From c128ed33c2447e8daea89d70795098748bd5b2af Mon Sep 17 00:00:00 2001 From: zhangfeng <1603559716@qq.com> Date: 星期五, 06 一月 2023 10:53:27 +0800 Subject: [PATCH] 补充查询单条领取记录接口 --- equipment/equipment-rpc-provider/src/main/java/com/gkhy/safePlatform/equipment/rpc/provider/EquipmentRpcProvider.java | 16 +++-- equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml | 3 /dev/null | 46 --------------- equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialReceiveRecordsService.java | 2 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/MaterialReceiveRecordsInfoService.java | 2 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialReceiveRecordsServiceImpl.java | 26 ++++++++ equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialReceiveRecordsController.java | 12 +++ pom.xml | 25 ++++++++ equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/MaterialReceiveRecordsInfoServiceImpl.java | 11 +++ 9 files changed, 88 insertions(+), 55 deletions(-) diff --git a/equipment/equipment-rpc-provider/src/main/java/com/gkhy/safePlatform/equipment/rpc/provider/EquipmentRpcProvider.java b/equipment/equipment-rpc-provider/src/main/java/com/gkhy/safePlatform/equipment/rpc/provider/EquipmentRpcProvider.java index ca71dc0..e98d15e 100644 --- a/equipment/equipment-rpc-provider/src/main/java/com/gkhy/safePlatform/equipment/rpc/provider/EquipmentRpcProvider.java +++ b/equipment/equipment-rpc-provider/src/main/java/com/gkhy/safePlatform/equipment/rpc/provider/EquipmentRpcProvider.java @@ -88,7 +88,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; @@ -108,7 +108,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; @@ -131,7 +131,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; @@ -154,7 +154,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; @@ -183,7 +183,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; } @@ -202,7 +202,7 @@ resultVO.setMsg(e.getMessage()); }catch (Exception e){ resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; @@ -227,11 +227,13 @@ resultVO.setData(materialReceiveRecordsRPCRespDtos); } }catch (EquipmentException e){ + e.printStackTrace(); resultVO.setCode(e.getCode()); resultVO.setMsg(e.getMessage()); }catch (Exception e){ + e.printStackTrace(); resultVO.setCode(ResultCodes.SERVER_ERROR.getCode()); - resultVO.setCode(ResultCodes.SERVER_ERROR.getDesc()); + resultVO.setMsg(ResultCodes.SERVER_ERROR.getDesc()); } return resultVO; diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/common/RocketMQTemplateHelper.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/common/RocketMQTemplateHelper.java deleted file mode 100644 index 31aab69..0000000 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/common/RocketMQTemplateHelper.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.gkhy.safePlatform.equipment.common; - -import org.apache.rocketmq.client.producer.SendResult; -import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.spring.core.RocketMQTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.support.TransactionSynchronizationAdapter; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -import java.util.Date; - -@Component -public class RocketMQTemplateHelper { - - @Autowired - private RocketMQTemplate rocketMQTemplate; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); - - - /** - * 事务提交后发送MQ - * @param message - * @param <T> - */ - public <T> void syncSend(String destination, T message) { - // 是否开启事务判断 - if (TransactionSynchronizationManager.isSynchronizationActive()) { - TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { - @Override - public void afterCommit() { - SendResult sendResult = rocketMQTemplate.syncSend(destination, message); - if(sendResult.getSendStatus() != SendStatus.SEND_OK){ - logger.info("【安全物资和设备管理】事务提交后才发送MQ的消息发送失败!"+ new Date()); - }else{ - logger.info("【安全物资和设备管理】消息申请发送rocketMQ消息成功!"+ new Date()); - } - } - }); - } else { - SendResult sendResult = rocketMQTemplate.syncSend(destination, message); - if(sendResult.getSendStatus() != SendStatus.SEND_OK){ - logger.info("【安全物资和设备管理】事务提交后才发送MQ的消息发送失败!"+ new Date()); - }else{ - logger.info("【安全物资和设备管理】消息申请发送rocketMQ消息成功!"+ new Date()); - } - } - } -} diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialReceiveRecordsController.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialReceiveRecordsController.java index 43f4b22..bbb30a9 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialReceiveRecordsController.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialReceiveRecordsController.java @@ -1,13 +1,13 @@ package com.gkhy.safePlatform.equipment.controller; +import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.utils.PageUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.commons.vo.SearchResultVO; -import com.gkhy.safePlatform.equipment.entity.MaterialReceiveRecordsBaseDO; import com.gkhy.safePlatform.equipment.model.dto.req.MaterialReceiveRecordsBaseReq; import com.gkhy.safePlatform.equipment.model.dto.req.MaterialReceiveRecordsQuery; import com.gkhy.safePlatform.equipment.model.dto.resp.MaterialReceiveRecordsBaseDto; @@ -43,4 +43,14 @@ materialReceiveRecordsService.revertMaterial(currentUser,req); return new ResultVO(ResultCodes.OK); } + /** + * 获取单条记录 + */ + @RequestMapping("queryById") + public ResultVO queryById(Authentication authentication, @RequestBody JSONObject jsonObject){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + Long id = jsonObject.getLong("id"); + MaterialReceiveRecordsBaseDto materialReceiveRecordsBaseDto = materialReceiveRecordsService.queryById(currentUser,id); + return new ResultVO(ResultCodes.OK,materialReceiveRecordsBaseDto); + } } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/consumer/SafeMaterialConsumer.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/consumer/SafeMaterialConsumer.java deleted file mode 100644 index e70357a..0000000 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/consumer/SafeMaterialConsumer.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.gkhy.safePlatform.equipment.mq.consumer; - -import com.gkhy.safePlatform.commons.utils.CalcuteDelayLevelUtils; -import com.gkhy.safePlatform.commons.utils.JsonUtils; - -import com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfo; -import com.gkhy.safePlatform.equipment.enums.ValidStatusEnum; -import com.gkhy.safePlatform.equipment.mq.msg.SafeMaterialMsg; -import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialDetailInfoService; -import org.apache.rocketmq.client.producer.SendResult; -import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; -import org.apache.rocketmq.spring.core.RocketMQListener; -import org.apache.rocketmq.spring.core.RocketMQTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.messaging.Message; -import org.springframework.messaging.support.MessageBuilder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.nio.charset.StandardCharsets; -import java.util.Date; - -@Service -@RocketMQMessageListener(topic = "${rocketmq.topic.safeMaterialTopic}",consumerGroup = "${rocketmq.consumer.safeMaterialGroup}") -public class SafeMaterialConsumer implements RocketMQListener<MessageExt> { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Value("${rocketmq.topic.safeMaterialTopic}") - private String safeMaterialTopic; - - @Autowired - private RocketMQTemplate rocketMQTemplate; - - @Autowired - private SafeMaterialDetailInfoService safeMaterialDetailInfoService; - - - @Override - @Transactional - public void onMessage(MessageExt message) { - try{ - SafeMaterialMsg msg = JsonUtils.parse(new String(message.getBody(), StandardCharsets.UTF_8),SafeMaterialMsg.class); - if(null != msg && msg.getId()>0){ - //当前时间早于目标处理时间前0秒 - Long relaySeconds = (msg.getValidTime().getTime() - new Date().getTime())/1000; - if(relaySeconds>0){ - //重发消息,实现连续延时 - Message reMsg = MessageBuilder.withPayload(msg).build(); - SendResult sendResult = rocketMQTemplate.syncSend(safeMaterialTopic, reMsg, 10000, CalcuteDelayLevelUtils.calcuteDelayLevel(relaySeconds)); - if(sendResult.getSendStatus() != SendStatus.SEND_OK){ - throw new RuntimeException("【安全物资管理】重发消息失败" + msg.getId()+ "MSG_ID: "+ message.getMsgId()); - } - }else{//超时 - SafeMaterialDetailInfo materialDetailInfo = safeMaterialDetailInfoService.queryById(msg.getId()); - if(null != materialDetailInfo){ - safeMaterialDetailInfoService.updateValidStatus(msg.getId()); - logger.info("物资详细数据id:"+msg.getId()+" 物资过期!"); - - } - } - - } - }catch (Exception e){ - logger.error("【安全物资和设备管理】消息消费异常!"+ "MSG_ID: "+ message.getMsgId()+e); - } - } -} diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/msg/SafeMaterialMsg.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/msg/SafeMaterialMsg.java deleted file mode 100644 index 23b36bf..0000000 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/mq/msg/SafeMaterialMsg.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.gkhy.safePlatform.equipment.mq.msg; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.util.Date; - -public class SafeMaterialMsg { - /** - * 主键 - */ - private Long id ; - - /** - * 有效类型 - */ - private Byte validStatus; - /** - * 有效期 - */ - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - private Date validTime; - - public Byte getValidStatus() { - return validStatus; - } - - public void setValidStatus(Byte validStatus) { - this.validStatus = validStatus; - } - - public Date getValidTime() { - return validTime; - } - - public void setValidTime(Date validTime) { - this.validTime = validTime; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } -} diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialReceiveRecordsService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialReceiveRecordsService.java index 31679af..be7a1c8 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialReceiveRecordsService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialReceiveRecordsService.java @@ -16,4 +16,6 @@ void revertMaterial(ContextCacheUser currentUser, MaterialReceiveRecordsBaseReq req); List<MaterialReceiveRecordsDO> getReceiveRecordsByReceiveUids(MaterialReceiveRecordsBO bo); + + MaterialReceiveRecordsBaseDto queryById(ContextCacheUser currentUser, Long id); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/MaterialReceiveRecordsInfoService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/MaterialReceiveRecordsInfoService.java index e0caa07..6c6bb75 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/MaterialReceiveRecordsInfoService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/MaterialReceiveRecordsInfoService.java @@ -19,4 +19,6 @@ List<MaterialReceiveRecordsInfo> listByReceiveBaseIds(List<Long> idList); List<MaterialReceiveRecordsDO> getReceiveRecordsByReceiveUids(MaterialReceiveRecordsBO bo); + + List<MaterialReceiveRecordsInfo> listByReceiveBaseId(Long id); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/MaterialReceiveRecordsInfoServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/MaterialReceiveRecordsInfoServiceImpl.java index 4d28de4..1169547 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/MaterialReceiveRecordsInfoServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/MaterialReceiveRecordsInfoServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.util.List; @@ -66,4 +67,14 @@ } return repository.getReceiveRecordsByReceiveUids(bo); } + + @Override + public List<MaterialReceiveRecordsInfo> listByReceiveBaseId(Long id) { + if (ObjectUtils.isEmpty(id)) { + throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); + } + List<MaterialReceiveRecordsInfo> receiveRecordsInfoList = repository.selectList(new LambdaQueryWrapper<MaterialReceiveRecordsInfo>() + .eq(MaterialReceiveRecordsInfo::getReceiveBaseId, id)); + return receiveRecordsInfoList; + } } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialReceiveRecordsServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialReceiveRecordsServiceImpl.java index b7d8a20..a1d9930 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialReceiveRecordsServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialReceiveRecordsServiceImpl.java @@ -27,6 +27,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.time.LocalDateTime; import java.util.ArrayList; @@ -216,4 +217,29 @@ return list; } + @Override + public MaterialReceiveRecordsBaseDto queryById(ContextCacheUser currentUser, Long id) { + if(ObjectUtils.isEmpty(id)){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"领取总记录主键不可为空!"); + } + MaterialReceiveRecordsBaseInfo receiveRecordsBaseInfo = recordsBaseInfoService.queryById(id); + List<MaterialReceiveRecordsInfo> receiveRecordsInfoList = receiveRecordsInfoService.listByReceiveBaseId(id); + MaterialReceiveRecordsBaseDto materialReceiveRecordsBaseDto = new MaterialReceiveRecordsBaseDto(); + if(!ObjectUtils.isEmpty(receiveRecordsBaseInfo)){ + BeanUtils.copyProperties(receiveRecordsBaseInfo,materialReceiveRecordsBaseDto); + List<MaterialReceiveRecordsDto> receiveRecordsDtoList = new ArrayList<>(); + for(MaterialReceiveRecordsInfo receiveRecordsInfo:receiveRecordsInfoList){ + MaterialReceiveRecordsDto receiveRecordsDto = new MaterialReceiveRecordsDto(); + BeanUtils.copyProperties(receiveRecordsInfo,receiveRecordsDto); + receiveRecordsDto.setMaterialStatusName(MaterialStatusEnum.getByCode(receiveRecordsInfo.getMaterialStatus()).getValue()); + receiveRecordsDto.setRevertStatusName(MaterialRevertStatusEnum.getByCode(receiveRecordsInfo.getRevertStatus()).getValue()); + receiveRecordsDtoList.add(receiveRecordsDto); + } + materialReceiveRecordsBaseDto.setMaterialList(receiveRecordsDtoList); + return materialReceiveRecordsBaseDto; + } + + return null; + } + } diff --git a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml index 6ea5708..0c1ecba 100644 --- a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml +++ b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml @@ -320,7 +320,8 @@ delivery_time, sm_id, receive_uid, - receive_uname + receive_uname, + status from safe_material_detail where del_flag = 0 and valid_status = #{validStatus} diff --git a/pom.xml b/pom.xml index 25a525e..7bdf112 100644 --- a/pom.xml +++ b/pom.xml @@ -147,6 +147,18 @@ <version>${redission.version}</version> </dependency> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-spring-boot</artifactId> + <version>${rocketmq.starter.version}</version> + </dependency> + + <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-all</artifactId> + <version>5.8.5</version> + </dependency> + </dependencies> </dependencyManagement> @@ -265,6 +277,19 @@ <artifactId>account-rpc-api</artifactId> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-validation</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-spring-boot</artifactId> + </dependency> + <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-all</artifactId> + </dependency> </dependencies> <build> -- Gitblit v1.9.2