19 changed files with 560 additions and 26 deletions
-
6storeroom/src/main/java/com/storeroom/modules/device/controller/DeviceController.java
-
7storeroom/src/main/java/com/storeroom/modules/device/service/DeviceService.java
-
5storeroom/src/main/java/com/storeroom/modules/device/service/impl/DeviceImpl.java
-
54system/src/main/java/com/storeroom/modules/system/controller/NoticeController.java
-
47system/src/main/java/com/storeroom/modules/system/controller/UserController.java
-
73system/src/main/java/com/storeroom/modules/system/domain/Notice.java
-
47system/src/main/java/com/storeroom/modules/system/domain/NoticeDevices.java
-
39system/src/main/java/com/storeroom/modules/system/domain/NoticeUsers.java
-
2system/src/main/java/com/storeroom/modules/system/domain/User.java
-
8system/src/main/java/com/storeroom/modules/system/repository/NoticeDeviceRepository.java
-
15system/src/main/java/com/storeroom/modules/system/repository/NoticeRepository.java
-
10system/src/main/java/com/storeroom/modules/system/repository/NoticeUsersRepository.java
-
61system/src/main/java/com/storeroom/modules/system/service/NoticeService.java
-
6system/src/main/java/com/storeroom/modules/system/service/UserService.java
-
35system/src/main/java/com/storeroom/modules/system/service/dto/NoticeDto.java
-
28system/src/main/java/com/storeroom/modules/system/service/dto/NoticeQueryCriteria.java
-
129system/src/main/java/com/storeroom/modules/system/service/impl/NoticeServiceImpl.java
-
12system/src/main/java/com/storeroom/modules/system/service/impl/UserServiceImpl.java
-
2system/src/main/resources/application.yml
@ -0,0 +1,54 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.annotaion.rest.AnonymousGetMapping; |
||||
|
import com.storeroom.annotaion.rest.AnonymousPostMapping; |
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.modules.system.service.NoticeService; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeDto; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeQueryCriteria; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import com.storeroom.utils.StringUtils; |
||||
|
import com.storeroom.utils.enums.ResponseStatus; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.util.ObjectUtils; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:通知公告") |
||||
|
@RequestMapping("/api/notice/") |
||||
|
public class NoticeController { |
||||
|
|
||||
|
private final NoticeService noticeService; |
||||
|
|
||||
|
|
||||
|
@ApiOperation("添加通知信息") |
||||
|
@AnonymousPostMapping("create") |
||||
|
public ApiResponse<Object> create(@RequestBody NoticeDto noticeDto) { |
||||
|
if (!StringUtils.isEmpty(noticeDto.getId())) { |
||||
|
throw new BaseException("id不为空"); |
||||
|
} |
||||
|
if (!ObjectUtils.isEmpty(noticeDto.getDeviceInfoId())) { |
||||
|
noticeService.createDeviceNotice(noticeDto); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
if (!ObjectUtils.isEmpty(noticeDto.getUserId())) { |
||||
|
noticeService.createNotice(noticeDto); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
return ApiResponse.error(ResponseStatus.FAIL); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("通知列表") |
||||
|
@AnonymousGetMapping("list") |
||||
|
public ApiResponse<Object> list(NoticeQueryCriteria criteria, Pageable pageable) { |
||||
|
return ApiResponse.success(noticeService.queryAll(criteria, pageable)); |
||||
|
} |
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
package com.storeroom.modules.system.domain; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.List; |
||||
|
import java.util.Objects; |
||||
|
import java.util.Set; |
||||
|
|
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name = "sys_notice") |
||||
|
public class Notice extends BaseEntity implements Serializable { |
||||
|
|
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@NotNull(groups = BaseEntity.Update.class) |
||||
|
@ApiModelProperty(value = "id", hidden = true) |
||||
|
private String id; |
||||
|
|
||||
|
@Column(name = "notice_title") |
||||
|
@ApiModelProperty(value = "公告标题") |
||||
|
private String noticeTitle; |
||||
|
|
||||
|
@Column(name = "notice_type") |
||||
|
@ApiModelProperty(value = "公告类型(1通知 2公告)") |
||||
|
private Integer noticeType; |
||||
|
|
||||
|
@Column(name = "notice_content") |
||||
|
@ApiModelProperty(value = "公告内容") |
||||
|
private String noticeContent; |
||||
|
|
||||
|
@Column(name = "status") |
||||
|
@ApiModelProperty(value = "公告状态(true正常 false关闭)") |
||||
|
private Boolean status; |
||||
|
|
||||
|
@Column(name = "push_type") |
||||
|
@ApiModelProperty(value = "推送类型") |
||||
|
private Integer pushType; |
||||
|
|
||||
|
@OneToMany(mappedBy = "noticeId",cascade={CascadeType.PERSIST,CascadeType.REMOVE}) |
||||
|
private Set<NoticeUsers> noticeUsers; |
||||
|
|
||||
|
@OneToMany(mappedBy = "noticeId",cascade={CascadeType.PERSIST,CascadeType.REMOVE}) |
||||
|
private Set<NoticeDevices> noticeDevices; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean equals(Object o) { |
||||
|
if (this == o) return true; |
||||
|
if (o == null || getClass() != o.getClass()) return false; |
||||
|
Notice notice = (Notice) o; |
||||
|
return Objects.equals(id, notice.id) && Objects.equals(noticeTitle, notice.noticeTitle) && Objects.equals(noticeType, notice.noticeType) && Objects.equals(noticeContent, notice.noticeContent) && Objects.equals(status, notice.status); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int hashCode() { |
||||
|
return Objects.hash(id, noticeTitle, noticeType, noticeContent, status); |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
package com.storeroom.modules.system.domain; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name = "sys_notice_devices") |
||||
|
public class NoticeDevices implements Serializable { |
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@NotNull(groups = BaseEntity.Update.class) |
||||
|
@ApiModelProperty(value = "id", hidden = true) |
||||
|
private String id; |
||||
|
|
||||
|
|
||||
|
@Column(name = "notice_id") |
||||
|
@ApiModelProperty(value = "通知id") |
||||
|
private String noticeId; |
||||
|
|
||||
|
@Column(name = "device_info_id") |
||||
|
@ApiModelProperty(value = "设备id") |
||||
|
private String deviceInfoId; |
||||
|
|
||||
|
@Override |
||||
|
public boolean equals(Object o) { |
||||
|
if (this == o) return true; |
||||
|
if (o == null || getClass() != o.getClass()) return false; |
||||
|
NoticeDevices that = (NoticeDevices) o; |
||||
|
return Objects.equals(id, that.id) && Objects.equals(noticeId, that.noticeId) && Objects.equals(deviceInfoId, that.deviceInfoId); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int hashCode() { |
||||
|
return Objects.hash(id, noticeId, deviceInfoId); |
||||
|
} |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
package com.storeroom.modules.system.domain; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name = "sys_notice_users") |
||||
|
public class NoticeUsers implements Serializable { |
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@NotNull(groups = BaseEntity.Update.class) |
||||
|
@ApiModelProperty(value = "id", hidden = true) |
||||
|
private String id; |
||||
|
|
||||
|
|
||||
|
@Column(name = "notice_id") |
||||
|
@ApiModelProperty(value = "通知id") |
||||
|
private String noticeId; |
||||
|
|
||||
|
@Column(name = "user_id") |
||||
|
@ApiModelProperty(value = "设备id") |
||||
|
private Long userId; |
||||
|
|
||||
|
@Column(name = "is_read") |
||||
|
@ApiModelProperty(value = "阅读状态") |
||||
|
private Boolean isRead; |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
package com.storeroom.modules.system.repository; |
||||
|
|
||||
|
import com.storeroom.modules.system.domain.NoticeDevices; |
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
|
||||
|
public interface NoticeDeviceRepository extends JpaRepository<NoticeDevices, String>, JpaSpecificationExecutor<NoticeDevices> { |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package com.storeroom.modules.system.repository; |
||||
|
|
||||
|
import com.storeroom.modules.system.domain.Notice; |
||||
|
import org.springframework.data.domain.Page; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.data.jpa.domain.Specification; |
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
import org.springframework.data.jpa.repository.Query; |
||||
|
|
||||
|
public interface NoticeRepository extends JpaRepository<Notice, String>, JpaSpecificationExecutor<Notice> { |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
package com.storeroom.modules.system.repository; |
||||
|
|
||||
|
import com.storeroom.modules.system.domain.NoticeUsers; |
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
|
||||
|
public interface NoticeUsersRepository extends JpaRepository<NoticeUsers, String>, JpaSpecificationExecutor<NoticeUsers> { |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
package com.storeroom.modules.system.service; |
||||
|
|
||||
|
import com.storeroom.modules.system.domain.Notice; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeDto; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeQueryCriteria; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
|
||||
|
import java.util.Set; |
||||
|
|
||||
|
public interface NoticeService { |
||||
|
|
||||
|
/** |
||||
|
* 查询公告信息 |
||||
|
* |
||||
|
* @param noticeId 通知id |
||||
|
* @return / |
||||
|
*/ |
||||
|
Notice selectNoticeById(String noticeId); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 创建通知消息 |
||||
|
* @param notice |
||||
|
*/ |
||||
|
void createNotice(NoticeDto notice); |
||||
|
|
||||
|
/** |
||||
|
* 创建设备通知 |
||||
|
* @param notice |
||||
|
*/ |
||||
|
void createDeviceNotice(NoticeDto notice); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查询全部 |
||||
|
* |
||||
|
* @return / |
||||
|
*/ |
||||
|
Object queryAll(NoticeQueryCriteria criteria, Pageable pageable); |
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
*/ |
||||
|
void updateNotice(Notice notice); |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @param notice / |
||||
|
*/ |
||||
|
void deleteNotice(Notice notice); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 批量删除 |
||||
|
* |
||||
|
* @param ids id |
||||
|
*/ |
||||
|
void deleteByIds(Set<String> ids); |
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package com.storeroom.modules.system.service.dto; |
||||
|
|
||||
|
import com.storeroom.base.BaseDTO; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Set; |
||||
|
|
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class NoticeDto extends BaseDTO implements Serializable { |
||||
|
|
||||
|
private String id; |
||||
|
|
||||
|
private String noticeTitle; |
||||
|
|
||||
|
private Integer noticeType; |
||||
|
|
||||
|
private String noticeContent; |
||||
|
|
||||
|
private Boolean status; |
||||
|
|
||||
|
private Integer pushType; |
||||
|
|
||||
|
private Set<Long> userId; |
||||
|
|
||||
|
private Boolean isRead; |
||||
|
|
||||
|
private Set<String> deviceInfoId; |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package com.storeroom.modules.system.service.dto; |
||||
|
|
||||
|
import com.storeroom.annotaion.Query; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.sql.Timestamp; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
public class NoticeQueryCriteria implements Serializable { |
||||
|
|
||||
|
@Query |
||||
|
private Long id; |
||||
|
|
||||
|
@Query(blurry = "noticeTitle,noticeContent") |
||||
|
private String blurry; |
||||
|
|
||||
|
@Query |
||||
|
private Integer status; |
||||
|
|
||||
|
@Query |
||||
|
private Integer noticeType; |
||||
|
|
||||
|
|
||||
|
@Query(type = Query.Type.BETWEEN) |
||||
|
private List<Timestamp> createTime; |
||||
|
} |
@ -0,0 +1,129 @@ |
|||||
|
package com.storeroom.modules.system.service.impl; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.modules.device.domain.DeviceInfo; |
||||
|
import com.storeroom.modules.device.repository.DeviceInfoRepository; |
||||
|
import com.storeroom.modules.system.domain.Notice; |
||||
|
import com.storeroom.modules.system.domain.NoticeDevices; |
||||
|
import com.storeroom.modules.system.domain.NoticeUsers; |
||||
|
import com.storeroom.modules.system.repository.NoticeDeviceRepository; |
||||
|
import com.storeroom.modules.system.repository.NoticeRepository; |
||||
|
import com.storeroom.modules.system.repository.NoticeUsersRepository; |
||||
|
import com.storeroom.modules.system.service.NoticeService; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeDto; |
||||
|
import com.storeroom.modules.system.service.dto.NoticeQueryCriteria; |
||||
|
import com.storeroom.utils.NanoIdUtils; |
||||
|
import com.storeroom.utils.PageUtil; |
||||
|
import com.storeroom.utils.QueryHelp; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.SneakyThrows; |
||||
|
import org.hibernate.validator.constraints.UniqueElements; |
||||
|
import org.springframework.data.domain.Page; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.*; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class NoticeServiceImpl implements NoticeService { |
||||
|
|
||||
|
private final NoticeRepository noticeRepository; |
||||
|
private final DeviceInfoRepository deviceInfoRepository; |
||||
|
private final NoticeDeviceRepository noticeDeviceRepository; |
||||
|
private final NoticeUsersRepository noticeUsersRepository; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public Notice selectNoticeById(String noticeId) { |
||||
|
return noticeRepository.findById(noticeId).orElseGet(Notice::new); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void createNotice(NoticeDto noticeDto) { |
||||
|
noticeDto.setId(NanoIdUtils.randomNanoId()); |
||||
|
Notice noticeEntity = new Notice(); |
||||
|
noticeEntity.setId(noticeDto.getId()); |
||||
|
noticeEntity.setNoticeContent(noticeDto.getNoticeContent()); |
||||
|
noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
||||
|
noticeEntity.setStatus(false); |
||||
|
noticeEntity.setPushType(noticeDto.getPushType()); |
||||
|
|
||||
|
Set<Long> deviceInfos = noticeDto.getUserId(); |
||||
|
|
||||
|
|
||||
|
for (Long userid : deviceInfos) { |
||||
|
NoticeUsers noticeUsers = new NoticeUsers(); |
||||
|
Set<NoticeUsers> noticeUsersList = new LinkedHashSet<>(); |
||||
|
Notice notice = noticeRepository.findById(noticeDto.getId()).orElseGet(Notice::new); |
||||
|
noticeUsers.setId(NanoIdUtils.randomNanoId()); |
||||
|
noticeUsers.setIsRead(false); |
||||
|
noticeUsers.setUserId(userid); |
||||
|
noticeUsers.setNoticeId(noticeDto.getId()); |
||||
|
noticeEntity.setNoticeUsers(noticeUsersList); |
||||
|
noticeUsersList.add(noticeUsers); |
||||
|
noticeEntity.setNoticeUsers(noticeUsersList); |
||||
|
noticeUsersRepository.save(noticeUsers); |
||||
|
} |
||||
|
noticeRepository.save(noticeEntity); |
||||
|
} |
||||
|
|
||||
|
@SneakyThrows |
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void createDeviceNotice(NoticeDto noticeDto) { |
||||
|
noticeDto.setId(NanoIdUtils.randomNanoId()); |
||||
|
|
||||
|
Notice noticeEntity = new Notice(); |
||||
|
noticeEntity.setId(noticeDto.getId()); |
||||
|
noticeEntity.setNoticeContent(noticeDto.getNoticeContent()); |
||||
|
noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
||||
|
noticeEntity.setStatus(false); |
||||
|
noticeEntity.setPushType(noticeDto.getPushType()); |
||||
|
|
||||
|
Set<String> deviceInfos = noticeDto.getDeviceInfoId(); |
||||
|
|
||||
|
for (String d : deviceInfos) { |
||||
|
NoticeDevices noticeDevices = new NoticeDevices(); |
||||
|
DeviceInfo deviceInfo = deviceInfoRepository.findById(d).orElseGet(DeviceInfo::new); |
||||
|
String url = "http://" + deviceInfo.getDeviceIp() + ":" + deviceInfo.getDevicePort(); |
||||
|
HashMap<String, String> body = new HashMap<>(); |
||||
|
HashMap<String, String> map = new HashMap<>(); |
||||
|
map.put("Content-type", "application/json"); |
||||
|
body.put("notice", noticeDto.getNoticeContent()); |
||||
|
// HttpResponse response = HttpUtils.doPost(url, "/IntelligentCabinetAPIServer/getNotice", "POST", map, null, body); |
||||
|
// if (response.getStatusLine().getStatusCode() != 200) { |
||||
|
// throw new BaseException("接口调用失败"); |
||||
|
// } |
||||
|
noticeDevices.setId(NanoIdUtils.randomNanoId()); |
||||
|
noticeDevices.setNoticeId(noticeDto.getId()); |
||||
|
noticeDevices.setDeviceInfoId(d); |
||||
|
noticeDeviceRepository.save(noticeDevices); |
||||
|
} |
||||
|
noticeRepository.save(noticeEntity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Object queryAll(NoticeQueryCriteria criteria, Pageable pageable) { |
||||
|
Page<Notice> page = noticeRepository.findAll(((root, query, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)), pageable); |
||||
|
return PageUtil.toPage(page); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateNotice(Notice notice) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteNotice(Notice notice) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void deleteByIds(Set<String> ids) { |
||||
|
noticeRepository.deleteAllById(ids); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue