消息模块

pull/451/head
starrysky 2020-02-27 23:54:08 +08:00
parent 06da2219a9
commit 686bd25ed7
18 changed files with 556 additions and 4 deletions

View File

@ -0,0 +1,35 @@
package me.zhengjie.modules.system.cons;
/**
* @author
* @date 2020-02-27
*/
public enum MessageModulePath {
CUSTOMER_ORDER_LIST("客户订单列表","order/customerOrder"),
;
private String name;
private String code;
MessageModulePath(String name, String code) {
this.name = name;
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -0,0 +1,36 @@
package me.zhengjie.modules.system.cons;
/**
* @author
* @date 2020-02-27
*/
public enum MessageModuleType {
CUSTOMER_ORDER("客户订单", "CUSTOMER_ORDER"),
INVOICE("销售发货单", "INVOICE")
;
private String name;
private String code;
MessageModuleType(String name, String code) {
this.name = name;
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -0,0 +1,36 @@
package me.zhengjie.modules.system.cons;
/**
* @author
* @date 2020-02-27
*/
public enum MessageReadStatus {
NO_READ("未读", 0),
READEDD("已读", 1),
;
private String name;
private Integer status;
MessageReadStatus(String name, Integer status) {
this.name = name;
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@ -0,0 +1,87 @@
package me.zhengjie.modules.system.domain;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author
* @date 2020-02-26
*/
@Entity
@Getter
@Setter
@Table(name = "message")
public class Message implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull(groups = {Menu.Update.class})
private Long id;
// 创建时间
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
// 更新时间
@Column(name = "update_time")
@CreationTimestamp
private Timestamp updateTime;
// 状态
@Column(name = "status")
private Boolean status;
@Column(name = "user_id_send")
private Long userIdSend;
@Column(name = "user_name_send")
private Long userNameSend;
@Column(name = "user_id_accept")
private Long userIdAccept;
/**
*
*/
@Column(name = "mess_content")
private String messContent;
/**
*
* 0
* 1
*/
@Column(name = "read_status")
private Integer readStatus;
/**
*
*/
@Column(name = "module_type_code")
private String moduleTypeCode;
@Column(name = "module_type_name")
private String moduleTypeName;
/**
*
*/
@Column(name = "module_path")
private String modulePath;
/**
*
*/
@Column(name = "init_code")
private String initCode;
}

View File

@ -0,0 +1,14 @@
package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author
* @date 2020-02-27
*/
public interface MessageRepository extends JpaRepository<Message, Long>, JpaSpecificationExecutor {
}

View File

@ -0,0 +1,41 @@
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Message;
import me.zhengjie.modules.system.service.MessageService;
import me.zhengjie.modules.system.service.dto.MessageCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author
* @date 2020-02-27
*/
@RestController
@RequestMapping("api")
public class MessageController {
@Autowired
private MessageService messageService;
@ApiOperation(value = "我的消息列表")
@GetMapping(value = "/queryInvoiceList")
@PreAuthorize("hasAnyRole('ADMIN','MESSAGE_ALL','MESSAGE_ALL')")
public ResponseEntity queryInvoiceList(MessageCriteria criteria){
return new ResponseEntity(messageService.queryAll(criteria), HttpStatus.OK);
}
@Log("修改消息")
@PutMapping(value = "/menus")
@PreAuthorize("hasAnyRole('ADMIN','MESSAGE_ALL','MESSAGE_EDIT')")
public ResponseEntity update(@Validated(Menu.Update.class) @RequestBody Message resources){
messageService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
}

View File

@ -0,0 +1,29 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Message;
import me.zhengjie.modules.system.service.dto.MessageCriteria;
import me.zhengjie.modules.system.service.dto.MessageDTO;
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateQueryCriteria;
/**
* @author
* @date 2020-02-27
*/
public interface MessageService {
/**
* get
* @param id
* @return
*/
MessageDTO findById(long id);
MessageDTO create(Message resources);
void delete(Long id);
Object queryAll(MessageCriteria criteria);
void update(Message resources);
}

View File

@ -80,4 +80,7 @@ public interface UserService {
@Cacheable(keyGenerator = "keyGenerator")
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
Object queryAll(UserQueryCriteria criteria);
}

View File

@ -0,0 +1,14 @@
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
/**
* @author jie
* @date 2019-10-01
*/
@Data
public class MessageCriteria {
// 所属用户
private String userIdAccept;
}

View File

@ -0,0 +1,55 @@
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import java.sql.Timestamp;
/**
* @author
* @date 2020-02-27
*/
@Data
public class MessageDTO {
private Long id;
// 创建时间
private Timestamp createTime;
// 更新时间
private Timestamp updateTime;
private Long userIdSend;
private Long userNameSend;
private Long userIdAccept;
/**
*
*/
private String messContent;
/**
*
* 0
* 1
*/
private Integer readStatus;
/**
*
*/
private String moduleType;
/**
*
*/
private String modulePath;
/**
*
*/
private String initCode;
}

View File

@ -0,0 +1,111 @@
package me.zhengjie.modules.system.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Message;
import me.zhengjie.modules.system.repository.MessageRepository;
import me.zhengjie.modules.system.service.MessageService;
import me.zhengjie.modules.system.service.dto.MessageCriteria;
import me.zhengjie.modules.system.service.dto.MessageDTO;
import me.zhengjie.modules.system.service.mapper.MessageMapper;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceDTO;
import me.zhengjie.modules.wms.outSourceProductSheet.service.dto.OutSourceInspectionCertificateQueryCriteria;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author
* @date 2020-02-27
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MessageServiceImpl implements MessageService {
@Autowired
private MessageRepository messageRepository;
@Autowired
private MessageMapper messageMapper;
@Override
public MessageDTO findById(long id) {
return null;
}
@Override
public MessageDTO create(Message resources) {
String initCode = resources.getInitCode();
if(StringUtils.isEmpty(initCode)){
throw new BadRequestException("单据编号不能为空");
}
String modulePath = resources.getModulePath();
if(StringUtils.isEmpty(modulePath)){
throw new BadRequestException("模块路径不能为空");
}
String moduleTypeName = resources.getModuleTypeName();
if(StringUtils.isEmpty(moduleTypeName)){
throw new BadRequestException("模块类型名称不能为空!");
}
String moduleTypeCode = resources.getModuleTypeCode();
if(StringUtils.isEmpty(moduleTypeCode)){
throw new BadRequestException("模块类型编码不能为空!");
}
Message message = messageRepository.save(resources);
return messageMapper.toDto(message);
}
@Override
public void delete(Long id) {
}
@Override
public Object queryAll(MessageCriteria criteria) {
Specification<Message> specification = new Specification<Message>() {
@Override
public Predicate toPredicate(Root<Message> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> targetPredicateList = new ArrayList<>();
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){
return null;
}else{
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
}
}
};
List<Message> messageList = messageRepository.findAll(specification);
List<MessageDTO> messageDtoList = messageMapper.toDto(messageList);
return messageDtoList;
}
@Override
public void update(Message resources) {
Optional<Message> messageOptional = messageRepository.findById(resources.getId());
Message message = messageOptional.get();
message.setStatus(false);
messageRepository.save(resources);
}
}

View File

@ -9,16 +9,26 @@ import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
import me.zhengjie.modules.system.service.mapper.UserMapper;
import me.zhengjie.modules.wms.outSourceProductSheet.domain.OutSourceInspectionCertificate;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
@ -44,6 +54,29 @@ public class UserServiceImpl implements UserService {
return PageUtil.toPage(page.map(userMapper::toDto));
}
@Override
public Object queryAll(UserQueryCriteria criteria) {
Specification<UserQueryCriteria> specification = new Specification<UserQueryCriteria>() {
@Override
public Predicate toPredicate(Root<UserQueryCriteria> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> targetPredicateList = new ArrayList<>();
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){
return null;
}else{
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
}
}
};
return userMapper.toDto(userRepository.findAll(specification));
}
@Override
public UserDTO findById(long id) {
Optional<User> user = userRepository.findById(id);

View File

@ -0,0 +1,15 @@
package me.zhengjie.modules.system.service.mapper;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.modules.system.domain.Message;
import me.zhengjie.modules.system.service.dto.MessageDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author
* @date 2020-02-27
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MessageMapper extends EntityMapper<MessageDTO, Message> {
}

View File

@ -31,7 +31,7 @@ public interface CustomerOrderService {
* @return
*/
//@Cacheable(keyGenerator = "keyGenerator")
public Object queryAll(CustomerOrderQueryCriteria criteria);
Object queryAll(CustomerOrderQueryCriteria criteria);
/**
* findById

View File

@ -1,6 +1,16 @@
package me.zhengjie.modules.wms.customerOrder.service.impl;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.cons.MessageModulePath;
import me.zhengjie.modules.system.cons.MessageModuleType;
import me.zhengjie.modules.system.cons.MessageReadStatus;
import me.zhengjie.modules.system.domain.Message;
import me.zhengjie.modules.system.repository.MessageRepository;
import me.zhengjie.modules.system.service.MessageService;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
@ -54,6 +64,7 @@ import javax.persistence.criteria.Root;
* @author jie
* @date 2019-08-03
*/
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class CustomerOrderServiceImpl implements CustomerOrderService {
@ -79,6 +90,14 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
@Autowired
private ProductInfoRepository productInfoRepository;
@Autowired
private MessageRepository messageRepository;
@Autowired
private UserService userService;
@Override
public Object queryAll(CustomerOrderQueryCriteria criteria, Pageable pageable){
@ -140,6 +159,7 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
@Override
@Transactional(rollbackFor = Exception.class)
public CustomerOrderDTO create(CreateCustomerOrderRequest createCustomerOrderRequest) {
String customerOrderCode = createCustomerOrderRequest.getCustomerOrderCode();
List<String> repeatProductCodeList =createCustomerOrderRequest.getCustomerOrderProductList().stream().
collect(Collectors.groupingBy(dog->dog.getProductCode() ,Collectors.counting()))
@ -213,6 +233,30 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
customerOrderDTO.setCustomerOrderProductList(customerOrderProductDTOList);
/**
*
*/
try {
// 查看所有用户
UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
List<UserDTO> userDTOList =(List<UserDTO>)userService.queryAll(userQueryCriteria);
if(!CollectionUtils.isEmpty(userDTOList)){
List<Message> messageList = new ArrayList<>();
for(UserDTO userDTO : userDTOList){
Message message = new Message();
message.setUserIdAccept(userDTO.getId());
String messageContent = MessageModuleType.CUSTOMER_ORDER.getName() + "(" + customerOrderCode + ")";
message.setMessContent(messageContent);
message.setModulePath(MessageModulePath.CUSTOMER_ORDER_LIST.getCode());
message.setModuleTypeName(MessageModuleType.CUSTOMER_ORDER.getCode());
message.setReadStatus(MessageReadStatus.NO_READ.getStatus());
messageList.add(message);
}
messageRepository.saveAll(messageList);
}
}catch (Exception e){
log.error("单据编号:插入消息失败!");
}
return customerOrderDTO;
}

View File

@ -42,8 +42,8 @@ public class OutSourceInspectionCertificateController {
@ApiOperation(value = "查询委外验收单列表")
@GetMapping(value = "/queryOutSourceInspectionCertificateList")
@PreAuthorize("hasAnyRole('ADMIN','SOUTSOURCEINSPECTIONCERTIFICATE_ALL','SOUTSOURCEINSPECTIONCERTIFICATE_SELECT')")
public ResponseEntity queryOutSourceInspectionCertificateList(OutSourceInspectionCertificateQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(outSourceInspectionCertificateService.queryAll(criteria,pageable),HttpStatus.OK);
public ResponseEntity queryOutSourceInspectionCertificateList(OutSourceInspectionCertificateQueryCriteria criteria){
return new ResponseEntity(outSourceInspectionCertificateService.queryAll(criteria),HttpStatus.OK);
}

View File

@ -1,6 +1,5 @@
package me.zhengjie.modules.wms.outSourceProductSheet.service.dto;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;