From f600f38c6c23a282b61ed4db1b2da094d695276f Mon Sep 17 00:00:00 2001 From: zhangfeng <1603559716@qq.com> Date: 星期五, 25 十一月 2022 16:43:52 +0800 Subject: [PATCH] 安全物资和设备管理调整 --- equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialClassifyInfoRepository.java | 6 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialClassifyInfoService.java | 5 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialClassifyInfoServiceImpl.java | 15 + equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialDetailController.java | 8 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialDetailInfoServiceImpl.java | 4 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialDetailInfoService.java | 2 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialDetailServiceImpl.java | 304 +++++++++++++++++-------- equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/SafeMatetrialDetailQuery.java | 10 equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialDetailInfoMapper.xml | 5 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialServiceImpl.java | 215 +++++++++++------ equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialClassifyService.java | 4 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/SafeMaterialDetailService.java | 4 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialDetailInfoRepository.java | 2 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/MaterialClassifyController.java | 15 + equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/MaterialClassifyQuery.java | 13 + equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/ParamForm.java | 23 + equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialClassifyInfoMapper.xml | 28 ++ equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java | 38 +++ 18 files changed, 518 insertions(+), 183 deletions(-) diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/MaterialClassifyController.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/MaterialClassifyController.java index 8b13294..56a8311 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/MaterialClassifyController.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/MaterialClassifyController.java @@ -3,7 +3,11 @@ 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.model.dto.req.MaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery; @@ -34,6 +38,17 @@ return new ResultVO<>(ResultCodes.OK,materialClassifyService.list()); } + /** + * 列表 + * @return + */ + @PostMapping(value = "page/list") + public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(Authentication authentication,@RequestBody PageQuery<MaterialClassifyQuery> pageQuery){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + PageUtils.checkCheck(pageQuery); + return materialClassifyService.listByPage(pageQuery); + + } /** * 新增 diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialDetailController.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialDetailController.java index 2f399c1..619a9e5 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialDetailController.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/controller/SafeMaterialDetailController.java @@ -100,8 +100,8 @@ * 批量重新入库 */ @PostMapping(value = "/batch/receipt") - public ResultVO receiptBatch(Authentication authentication, @RequestBody Long[] ids){ - return safeMaterialDetailService.receiptBatch(ids); + public ResultVO receiptBatch(Authentication authentication ,@Validated @RequestBody ParamForm paramForm){ + return safeMaterialDetailService.receiptBatch(paramForm); } /** * 删除-单条 @@ -120,8 +120,8 @@ * @return */ @PostMapping(value = "/deleteBatch") - public ResultVO deleteBatch(Authentication authentication,@RequestBody Long[] ids){ - return safeMaterialDetailService.deleteBatch(ids); + public ResultVO deleteBatch(Authentication authentication,@Validated @RequestBody ParamForm paramForm){ + return safeMaterialDetailService.deleteBatch(paramForm); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/MaterialClassifyQuery.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/MaterialClassifyQuery.java new file mode 100644 index 0000000..c97c65b --- /dev/null +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/MaterialClassifyQuery.java @@ -0,0 +1,13 @@ +package com.gkhy.safePlatform.equipment.model.dto.req; + +public class MaterialClassifyQuery { + private String classifyName; + + public String getClassifyName() { + return classifyName; + } + + public void setClassifyName(String classifyName) { + this.classifyName = classifyName; + } +} diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/ParamForm.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/ParamForm.java new file mode 100644 index 0000000..c820e07 --- /dev/null +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/ParamForm.java @@ -0,0 +1,23 @@ +package com.gkhy.safePlatform.equipment.model.dto.req; + +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2022/11/25 + * @time: 13:48 + */ +public class ParamForm { + @NotNull(message = "参数不可为空!") + List<Long> ids; + + public List<Long> getIds() { + return ids; + } + + public void setIds(List<Long> ids) { + this.ids = ids; + } +} diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/SafeMatetrialDetailQuery.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/SafeMatetrialDetailQuery.java index b12d628..374daf7 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/SafeMatetrialDetailQuery.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/model/dto/req/SafeMatetrialDetailQuery.java @@ -4,6 +4,8 @@ private Byte irStatus; private String rfid; + private Long smId; + public Byte getIrStatus() { return irStatus; } @@ -19,4 +21,12 @@ public void setRfid(String rfid) { this.rfid = rfid; } + + public Long getSmId() { + return smId; + } + + public void setSmId(Long smId) { + this.smId = smId; + } } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialClassifyInfoRepository.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialClassifyInfoRepository.java index b04f699..0738587 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialClassifyInfoRepository.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialClassifyInfoRepository.java @@ -1,8 +1,10 @@ package com.gkhy.safePlatform.equipment.repository; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo; +import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -22,4 +24,8 @@ SafeMaterialClassifyDO getBigAndSmallClassify(Long smallClassifyId); List<SafeMaterialClassifyDO> getTraceabilityClassifyList(List<Long> smallClassifyIds); + + List<SafeMaterialClassifyInfo> listByConditions(Page<SafeMaterialClassifyInfo> page, @Param("query") MaterialClassifyQuery query); + + List<SafeMaterialClassifyInfo> getListByParentIds(List<Long> parentIdList); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialDetailInfoRepository.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialDetailInfoRepository.java index 709805c..984dab5 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialDetailInfoRepository.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/repository/SafeMaterialDetailInfoRepository.java @@ -25,7 +25,7 @@ List<SafeMaterialDetailCountDO> getStatisticsValidStock(@Param("smIds") List<Long> smIds,@Param("validStatus") Byte validStatus,@Param("irStatus") Byte irStatus); - void deleteBatch(Long[] ids); + void deleteBatch(List<Long> ids); void updateDeliveryStatusByIds(@Param("detailBO")SafeMaterialDetailBO detailBO); diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialClassifyService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialClassifyService.java index 538ff9b..98f10b7 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialClassifyService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/MaterialClassifyService.java @@ -1,8 +1,11 @@ package com.gkhy.safePlatform.equipment.service; import com.gkhy.safePlatform.commons.co.ContextCacheUser; +import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.vo.ResultVO; +import com.gkhy.safePlatform.commons.vo.SearchResultVO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO; +import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery; @@ -27,4 +30,5 @@ List<SafeMaterialClassifyDO> getTraceabilityClassifyList(List<Long> smallClassifyIds); + SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(PageQuery<MaterialClassifyQuery> pageQuery); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/SafeMaterialDetailService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/SafeMaterialDetailService.java index 1d7ce83..7d4248b 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/SafeMaterialDetailService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/SafeMaterialDetailService.java @@ -25,9 +25,9 @@ ResultVO update(SafeMaterialDetailReq req); - ResultVO receiptBatch(Long[] ids); + ResultVO receiptBatch(ParamForm paramForm); - ResultVO deleteBatch(Long[] ids); + ResultVO deleteBatch(ParamForm paramForm); ResultVO deliveryBatchByIds(MterialDeliveryReq req); diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialClassifyInfoService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialClassifyInfoService.java index 9c0c3d4..cc5df5d 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialClassifyInfoService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialClassifyInfoService.java @@ -1,9 +1,11 @@ package com.gkhy.safePlatform.equipment.service.baseService; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyStockDO; +import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto; @@ -29,4 +31,7 @@ List<SafeMaterialClassifyDO> getTraceabilityClassifyList(List<Long> smallClassifyIds); + List<SafeMaterialClassifyInfo> listByPage(Page<SafeMaterialClassifyInfo> page, MaterialClassifyQuery searchParams); + + List<SafeMaterialClassifyInfo> getListByParentIds(List<Long> parentIdList); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialDetailInfoService.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialDetailInfoService.java index 9981f0e..c295f3b 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialDetailInfoService.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/SafeMaterialDetailInfoService.java @@ -23,7 +23,7 @@ List<SafeMaterialDetailCountDO> getStatisticsValidStock(List<Long> smIds); - void deleteBatch(Long[] ids); + void deleteBatch(List<Long> ids); void updateDeliveryStatusByIds(SafeMaterialDetailBO detailBO); diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialClassifyInfoServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialClassifyInfoServiceImpl.java index 64d1a22..e9945ea 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialClassifyInfoServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialClassifyInfoServiceImpl.java @@ -1,6 +1,7 @@ package com.gkhy.safePlatform.equipment.service.baseService.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.utils.StringUtils; @@ -8,6 +9,7 @@ import com.gkhy.safePlatform.equipment.enums.IssueReceiptEnum; import com.gkhy.safePlatform.equipment.enums.ValidStatusEnum; import com.gkhy.safePlatform.equipment.excepiton.EquipmentException; +import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery; import com.gkhy.safePlatform.equipment.repository.SafeMaterialClassifyInfoRepository; import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService; @@ -100,5 +102,18 @@ return repository.getTraceabilityClassifyList(smallClassifyIds); } + @Override + public List<SafeMaterialClassifyInfo> listByPage(Page<SafeMaterialClassifyInfo> page, MaterialClassifyQuery query) { + return repository.listByConditions(page,query); + } + + @Override + public List<SafeMaterialClassifyInfo> getListByParentIds(List<Long> parentIdList) { + if (CollectionUtils.isEmpty(parentIdList)){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); + } + return repository.getListByParentIds(parentIdList); + } + } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialDetailInfoServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialDetailInfoServiceImpl.java index 65de141..6a8537b 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialDetailInfoServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/baseService/impl/SafeMaterialDetailInfoServiceImpl.java @@ -77,8 +77,8 @@ } @Override - public void deleteBatch(Long[] ids) { - if(ids.length == 0){ + public void deleteBatch(List<Long> ids) { + if(CollectionUtils.isEmpty(ids)){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } repository.deleteBatch(ids); diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java index c4a001d..735b542 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java @@ -1,12 +1,17 @@ package com.gkhy.safePlatform.equipment.service.impl; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.BeanCopyUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; +import com.gkhy.safePlatform.commons.vo.SearchResultVO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo; import com.gkhy.safePlatform.equipment.enums.EquipmentResultCodes; import com.gkhy.safePlatform.equipment.excepiton.EquipmentException; +import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq; import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto; @@ -200,5 +205,38 @@ return safeMaterialClassifyInfoService.getTraceabilityClassifyList(smallClassifyIds); } + @Override + public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(PageQuery<MaterialClassifyQuery> pageQuery) { + Page<SafeMaterialClassifyInfo> page = new Page<>(pageQuery.getPageIndex(),pageQuery.getPageSize()); + List<SafeMaterialClassifyInfo> classifyInfoList = safeMaterialClassifyInfoService.listByPage(page, pageQuery.getSearchParams()); + List<SafeMaterialClassifyInfo> childList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(classifyInfoList)) { + List<Long> parentIdList = classifyInfoList.stream().map(SafeMaterialClassifyInfo::getId).collect(Collectors.toList()); + childList = safeMaterialClassifyInfoService.getListByParentIds(parentIdList); + } + List<SafeMaterialClassifyDto> respList = new ArrayList<>(); + for(SafeMaterialClassifyInfo classifyInfo:classifyInfoList){ + SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto(); + classifyDto.setId(classifyInfo.getId()); + classifyDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); + classifyDto.setParentId(classifyInfo.getParentId()); + //获取子级 + List<SafeMaterialClassifyInfo> selectList = childList.stream().filter(cl -> cl.getParentId().equals(classifyInfo.getId())).collect(Collectors.toList()); + List<SafeMaterialClassifyDto> childRespList = new ArrayList<>(); + if(selectList.size()>0){ + childRespList = BeanCopyUtils.copyBeanList(selectList,SafeMaterialClassifyDto.class); + } + classifyDto.setChildList(childRespList); + respList.add(classifyDto); + } + return new SearchResultVO<>(true, + page.getCurrent(), + page.getSize(), + page.getPages(), + page.getTotal(), + respList, + ResultCodes.OK); + } + } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialDetailServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialDetailServiceImpl.java index ff396c5..09a01fe 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialDetailServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialDetailServiceImpl.java @@ -5,6 +5,7 @@ import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO; import com.gkhy.safePlatform.commons.enums.ResultCodes; +import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.utils.StringUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; @@ -24,6 +25,8 @@ import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -35,6 +38,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service("SafeMaterialDetailService") @@ -56,6 +60,8 @@ @Autowired private RocketMQTemplateHelper rocketMQTemplateHelper; + @Autowired + private RedissonClient redissonClient; @Override public ResultVO save(SafeMaterialDetailAddReq req) { //判断物资是否存在 @@ -131,18 +137,36 @@ } } - //批量入库 - safeMaterialDetailInfoService.saveBatch(list); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_SAVE"); + try { + lock.lock(10, TimeUnit.SECONDS); + //批量入库 + safeMaterialDetailInfoService.saveBatch(list); - //发送消息 - if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ - for(SafeMaterialDetailInfo materialDetailInfo:list){ - SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); - safeMaterialMsg.setId(materialDetailInfo.getId()); - safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); - rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + //发送消息 + if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ + for(SafeMaterialDetailInfo materialDetailInfo:list){ + SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); + safeMaterialMsg.setId(materialDetailInfo.getId()); + safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); + rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + } + } + //创建成功,释放锁 + lock.unlock(); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); } } + return new ResultVO<>(ResultCodes.OK); } @@ -187,16 +211,31 @@ materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i)); list.add(materialDetailInfo); } - //批量入库 - safeMaterialDetailInfoService.saveBatch(list); - //发送消息 - if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ - for(SafeMaterialDetailInfo materialDetailInfo:list){ - //发送消息 - SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); - safeMaterialMsg.setId(materialInfo.getId()); - safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); - rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_SAVEBATCH"); + try { + lock.lock(10, TimeUnit.SECONDS); + //批量入库 + safeMaterialDetailInfoService.saveBatch(list); + //发送消息 + if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ + for(SafeMaterialDetailInfo materialDetailInfo:list){ + //发送消息 + SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); + safeMaterialMsg.setId(materialInfo.getId()); + safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); + rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + } + } + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); } } return new ResultVO<>(ResultCodes.OK); @@ -232,15 +271,30 @@ safeMaterialDetailInfo.setSmId(req.getSmId()); safeMaterialDetailInfo.setValidType(req.getValidType()); safeMaterialDetailInfo.setValidTime(req.getValidTime()); - //修改 - safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo); - //如果是非常期 - if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ - //发送消息 - SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); - safeMaterialMsg.setId(req.getId()); - safeMaterialMsg.setValidTime(conversionTimeType(req.getValidTime())); - rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_UPDATE"); + try { + lock.lock(10, TimeUnit.SECONDS); + //修改 + safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo); + //如果是非常期 + if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ + //发送消息 + SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); + safeMaterialMsg.setId(req.getId()); + safeMaterialMsg.setValidTime(conversionTimeType(req.getValidTime())); + rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); + } + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } return new ResultVO(ResultCodes.OK); } @@ -251,23 +305,33 @@ * @return */ @Override - public ResultVO receiptBatch(Long[] ids) { - if (ids.length == 0) { - throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); + public ResultVO receiptBatch(ParamForm paramForm) { + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_RECEIPTBATCH"); + try { + lock.lock(10, TimeUnit.SECONDS); + //验证 + List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(paramForm.getIds()); + List<SafeMaterialDetailInfo> selectList = list + .stream() + .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()) && item.getConsumable().equals(ConsumableEnum.YES.getCode())) + .collect(Collectors.toList()); + if(selectList.size() != paramForm.getIds().size()){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库或耗材物资不可重复入库!"); + } + //修改为入库状态 + safeMaterialDetailInfoService.updateReceiptStatusByIds(paramForm.getIds(),IssueReceiptEnum.IN_THE_LIBRARY.getCode()); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - List<Long> idList = new ArrayList<>(); - Collections.addAll(idList,ids); - //验证 - List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(idList); - List<SafeMaterialDetailInfo> selectList = list - .stream() - .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()) && item.getConsumable().equals(ConsumableEnum.YES.getCode())) - .collect(Collectors.toList()); - if(selectList.size() != ids.length){ - throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库或耗材物资不可重复入库!"); - } - //修改为入库状态 - safeMaterialDetailInfoService.updateReceiptStatusByIds(idList,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); return new ResultVO(ResultCodes.OK); } @@ -277,11 +341,8 @@ * @return */ @Override - public ResultVO deleteBatch(Long[] ids) { - if (ids.length == 0) { - throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); - } - safeMaterialDetailInfoService.deleteBatch(ids); + public ResultVO deleteBatch(ParamForm paramForm) { + safeMaterialDetailInfoService.deleteBatch(paramForm.getIds()); return new ResultVO(ResultCodes.OK); } @@ -315,26 +376,41 @@ public ResultVO deliveryBatchRandom(MterialRandomDeliveryReq req) { UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); List<Long> idList = new ArrayList<>(); - if(StringUtils.isNotBlank(req.getRfid())){ - idList = safeMaterialDetailInfoService.getIdListByRfid(req.getCount(),req.getSmId(),req.getRfid()); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_DELIVERYBATCHRANDOM"); + try { + lock.lock(10, TimeUnit.SECONDS); + if(StringUtils.isNotBlank(req.getRfid())){ + idList = safeMaterialDetailInfoService.getIdListByRfid(req.getCount(),req.getSmId(),req.getRfid()); - }else{ - idList = safeMaterialDetailInfoService.getRfidNullList(req.getCount(), req.getSmId()); + }else{ + idList = safeMaterialDetailInfoService.getRfidNullList(req.getCount(), req.getSmId()); + } + if(idList.size()< req.getCount()){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效库存数量不足!"); + } + //获取有效数量 + Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(req.getSmId()); + if(req.getCount() > validStockCount){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可大于有效库存数量!"); + } + SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO(); + detailBO.setClaimantName(userInfo.getUsername()); + detailBO.setClaimantId(req.getClaimantId()); + detailBO.setIds(idList); + safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - if(idList.size()< req.getCount()){ - throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效库存数量不足!"); - } - //获取有效数量 - Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(req.getSmId()); - if(req.getCount() > validStockCount){ - throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可大于有效库存数量!"); - } - SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO(); - detailBO.setClaimantName(userInfo.getUsername()); - detailBO.setClaimantId(req.getClaimantId()); - detailBO.setIds(idList); - safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); return new ResultVO(ResultCodes.OK); } @@ -501,27 +577,42 @@ */ @Override public ResultVO singleDelivery(SafeMaterialDetailReq req) { - //获取该条数据 - SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId()); - if(null == vo){ - throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_SINGLEDELIVERY"); + try { + lock.lock(10, TimeUnit.SECONDS); + //获取该条数据 + SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId()); + if(null == vo){ + throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); + } + if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){ + throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库"); + } + if(vo.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())){ + throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY); + } + //检查认领人 + UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); + SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); + materialDetailInfo.setId(req.getId()); + materialDetailInfo.setIrStatus(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()); + materialDetailInfo.setClaimantId(req.getClaimantId()); + materialDetailInfo.setClaimantName(userInfo.getUsername()); + materialDetailInfo.setDeliveryTime(LocalDateTime.now()); + //修改出入库状态为出库 + safeMaterialDetailInfoService.updateById(materialDetailInfo); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){ - throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库"); - } - if(vo.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())){ - throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY); - } - //检查认领人 - UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); - SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); - materialDetailInfo.setId(req.getId()); - materialDetailInfo.setIrStatus(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()); - materialDetailInfo.setClaimantId(req.getClaimantId()); - materialDetailInfo.setClaimantName(userInfo.getUsername()); - materialDetailInfo.setDeliveryTime(LocalDateTime.now()); - //修改出入库状态为出库 - safeMaterialDetailInfoService.updateById(materialDetailInfo); return new ResultVO<>(ResultCodes.OK); } @@ -536,20 +627,35 @@ if(null == id){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } - //获取该条数据 - SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id); - if(null == vo){ - throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SMD_SINGLERECEIPT"); + try { + lock.lock(10, TimeUnit.SECONDS); + //获取该条数据 + SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id); + if(null == vo){ + throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); + } + //如果是耗材不可重新入库 + if(vo.getConsumable().equals(ConsumableEnum.YES.getCode())){ + throw new EquipmentException(EquipmentResultCodes.MATERIAL_CONSUMABLE); + } + if(vo.getIrStatus().equals(IssueReceiptEnum.IN_THE_LIBRARY.getCode())){ + throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY); + } + //修改出入库状态为入库 + safeMaterialDetailInfoService.updateReceiptStatus(id,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - //如果是耗材不可重新入库 - if(vo.getConsumable().equals(ConsumableEnum.YES.getCode())){ - throw new EquipmentException(EquipmentResultCodes.MATERIAL_CONSUMABLE); - } - if(vo.getIrStatus().equals(IssueReceiptEnum.IN_THE_LIBRARY.getCode())){ - throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY); - } - //修改出入库状态为入库 - safeMaterialDetailInfoService.updateReceiptStatus(id,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); return new ResultVO<>(ResultCodes.OK); } diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialServiceImpl.java index c3eeab9..4b9107e 100644 --- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialServiceImpl.java +++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/SafeMaterialServiceImpl.java @@ -5,6 +5,7 @@ import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepRPCRespDTO; import com.gkhy.safePlatform.commons.enums.ResultCodes; +import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.commons.vo.SearchResultVO; @@ -19,21 +20,22 @@ import com.gkhy.safePlatform.equipment.model.dto.resp.MaterialClassificationDto; import com.gkhy.safePlatform.equipment.model.dto.resp.MaterialDepartmentDto; import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialDto; -import com.gkhy.safePlatform.equipment.repository.SafeMaterialDetailInfoRepository; import com.gkhy.safePlatform.equipment.service.SafeMaterialService; import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService; import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialDetailInfoService; import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService; import org.apache.dubbo.config.annotation.DubboReference; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service("SafeMaterialService") @@ -46,70 +48,103 @@ private SafeMaterialClassifyInfoService safeMaterialClassifyInfoService; @Autowired private SafeMaterialDetailInfoService safeMaterialDetailInfoService; + @Autowired + private RedissonClient redissonClient; @Override public ResultVO save(SafeMaterialAddReq req) { - ResultVO resultVO = null; - //获取部门信息 - DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); - if(null == ConsumableEnum.getByCode(req.getConsumable())){ - throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); - } - //获取物资类型 - SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); - if(null == classifyInfo){ - throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); - } - //判断该部门是否已经创建物资 - boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), null); - if(flag){ - throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); - } + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SM_INSERT"); + try { + lock.lock(10, TimeUnit.SECONDS); + //获取部门信息 + DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); + if(null == ConsumableEnum.getByCode(req.getConsumable())){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); + } + //获取物资类型 + SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); + if(null == classifyInfo){ + throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); + } + //判断该部门是否已经创建物资 + boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), null); + if(flag){ + throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); + } - //获取数量 - int safeMaterialTotalCount = safeMaterialInfoService.getTotalCount(); - SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); - safeMaterialInfo.setConsumable(req.getConsumable()); - safeMaterialInfo.setDepId(req.getDepId()); - safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); - safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); - safeMaterialInfo.setDepName(depInfo.getDepName()); - safeMaterialInfo.setSerialNum(this.generateSerialNum(safeMaterialTotalCount)); - safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); - //插入 - safeMaterialInfoService.save(safeMaterialInfo); + //获取数量 + int safeMaterialTotalCount = safeMaterialInfoService.getTotalCount(); + SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); + safeMaterialInfo.setConsumable(req.getConsumable()); + safeMaterialInfo.setDepId(req.getDepId()); + safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); + safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); + safeMaterialInfo.setDepName(depInfo.getDepName()); + safeMaterialInfo.setSerialNum(this.generateSerialNum(safeMaterialTotalCount)); + safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); + //插入 + safeMaterialInfoService.save(safeMaterialInfo); + //创建成功,释放锁 + lock.unlock(); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } + } return new ResultVO(ResultCodes.OK); } @Override public ResultVO update(SafeMaterialModReq req) { - ResultVO resultVO = null; - //获取部门信息 - DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SM_UPDATE"); + try { + lock.lock(10, TimeUnit.SECONDS); + //获取部门信息 + DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); - if(null == ConsumableEnum.getByCode(req.getConsumable())){ - throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); + if(null == ConsumableEnum.getByCode(req.getConsumable())){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); + } + //获取物资类型 + SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); + if(null == classifyInfo){ + throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); + } + boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), req.getDepId()); + if(flag){ + throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); + } + SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); + safeMaterialInfo.setConsumable(req.getConsumable()); + safeMaterialInfo.setDepId(req.getDepId()); + safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); + safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); + safeMaterialInfo.setDepName(depInfo.getDepName()); + safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); + //跟新 + safeMaterialInfoService.updateById(safeMaterialInfo); + //创建成功,释放锁 + lock.unlock(); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - //获取物资类型 - SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); - if(null == classifyInfo){ - throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); - } - boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), req.getDepId()); - if(flag){ - throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); - } - SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); - safeMaterialInfo.setConsumable(req.getConsumable()); - safeMaterialInfo.setDepId(req.getDepId()); - safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); - safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); - safeMaterialInfo.setDepName(depInfo.getDepName()); - safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); - //跟新 - safeMaterialInfoService.updateById(safeMaterialInfo); - return new ResultVO(ResultCodes.OK); } @@ -136,19 +171,36 @@ public ResultVO delete(Long id) { ResultVO resultVO = null; - //删除之前检查详表中是否还有该物物资数据 - int count = safeMaterialDetailInfoService.getCountBySmId(id); - if(count > 0){ - throw new EquipmentException(EquipmentResultCodes.DATA_HAS_BEEN_BOND,"该种物资已被绑定物资详情数据,不可删除!"); - } - SafeMaterialInfo materialInfo = new SafeMaterialInfo(); - materialInfo.setId(id); - materialInfo.setDelFlag(1); - boolean flag = safeMaterialInfoService.updateById(materialInfo); - if(flag){ - resultVO = new ResultVO(ResultCodes.OK); - }else{ - resultVO = new ResultVO(ResultCodes.SERVER_DEL_ERROR); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SM_DELETE"); + try { + lock.lock(10, TimeUnit.SECONDS); + //删除之前检查详表中是否还有该物物资数据 + int count = safeMaterialDetailInfoService.getCountBySmId(id); + if(count > 0){ + throw new EquipmentException(EquipmentResultCodes.DATA_HAS_BEEN_BOND,"该种物资已被绑定物资详情数据,不可删除!"); + } + SafeMaterialInfo materialInfo = new SafeMaterialInfo(); + materialInfo.setId(id); + materialInfo.setDelFlag(1); + boolean flag = safeMaterialInfoService.updateById(materialInfo); + if(flag){ + resultVO = new ResultVO(ResultCodes.OK); + }else{ + resultVO = new ResultVO(ResultCodes.SERVER_DEL_ERROR); + } + //创建成功,释放锁 + lock.unlock(); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } return resultVO; } @@ -158,13 +210,30 @@ if(ids.length == 0){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } - List<Long> idList = Arrays.asList(ids); - int count = safeMaterialDetailInfoService.getCountBySmIds(idList); - //判断是否绑定具体安全物资数据 - if(count > 0){ - throw new EquipmentException(EquipmentResultCodes.DATA_HAS_BEEN_BOND,"物资已被绑定物资详情数据,不可删除!"); + //加分布式锁,防止重复创建规则 + RLock lock = redissonClient.getLock("LOCK_SM_DELETEBATCH"); + try { + lock.lock(10, TimeUnit.SECONDS); + List<Long> idList = Arrays.asList(ids); + int count = safeMaterialDetailInfoService.getCountBySmIds(idList); + //判断是否绑定具体安全物资数据 + if(count > 0){ + throw new EquipmentException(EquipmentResultCodes.DATA_HAS_BEEN_BOND,"物资已被绑定物资详情数据,不可删除!"); + } + safeMaterialInfoService.deleteBatch(idList); + //创建成功,释放锁 + lock.unlock(); + }catch (EquipmentException e) { + e.printStackTrace(); + throw new EquipmentException(e.getCode(), e.getMessage()); + }catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(ResultCodes.SERVER_ERROR); + }finally { + if(lock.isLocked()){ + lock.unlock(); + } } - safeMaterialInfoService.deleteBatch(idList); return new ResultVO(ResultCodes.OK); } diff --git a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialClassifyInfoMapper.xml b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialClassifyInfoMapper.xml index 8b3c12e..616d946 100644 --- a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialClassifyInfoMapper.xml +++ b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialClassifyInfoMapper.xml @@ -67,5 +67,33 @@ #{id} </foreach> </select> + <select id="listByConditions" parameterType="com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo"> + SELECT + id, + parent_id, + material_classify_name + FROM + safe_material_classify + WHERE + parent_id = 0 + AND del_flag = 0 + <if test="query.classifyName != null and query.classifyName != ''"> + and instr(material_classify_name,#{query.classifyName}) > 0 + </if> + </select> + <select id="getListByParentIds" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo"> + SELECT + id, + parent_id, + material_classify_name + FROM + safe_material_classify + WHERE + del_flag = 0 + and parent_id in + <foreach collection="parentIdList" item="parentId" open="(" close=")" separator=","> + #{parentId} + </foreach> + </select> </mapper> 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 7574bbc..8394b25 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 @@ -170,9 +170,12 @@ <if test="query.rfid != null and query.rfid != '' "> and sd.rfid = #{query.rfid} </if> - <if test="query.irStatus != null and query.irStatus != '' or query.irStatus == 0"> + <if test="query.irStatus != null"> and sd.ir_status = #{query.irStatus} </if> + <if test="query.smId != null"> + and sd.sm_id = #{query.smId} + </if> ORDER BY sd.create_time desc </select> -- Gitblit v1.9.2