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); } /** * 新增 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); } 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; } } 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; } } 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; } } 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); } 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); 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); } 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); 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); } 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); 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); } } 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); 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); } } 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,6 +137,10 @@ } } //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_SAVE"); try { lock.lock(10, TimeUnit.SECONDS); //批量入库 safeMaterialDetailInfoService.saveBatch(list); @@ -143,6 +153,20 @@ 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,6 +211,10 @@ materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i)); list.add(materialDetailInfo); } //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_SAVEBATCH"); try { lock.lock(10, TimeUnit.SECONDS); //批量入库 safeMaterialDetailInfoService.saveBatch(list); //发送消息 @@ -197,6 +225,17 @@ 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,6 +271,10 @@ safeMaterialDetailInfo.setSmId(req.getSmId()); safeMaterialDetailInfo.setValidType(req.getValidType()); safeMaterialDetailInfo.setValidTime(req.getValidTime()); //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_UPDATE"); try { lock.lock(10, TimeUnit.SECONDS); //修改 safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo); //如果是非常期 @@ -242,6 +285,17 @@ 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); } List<Long> idList = new ArrayList<>(); Collections.addAll(idList,ids); public ResultVO receiptBatch(ParamForm paramForm) { //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_RECEIPTBATCH"); try { lock.lock(10, TimeUnit.SECONDS); //验证 List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(idList); 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() != ids.length){ if(selectList.size() != paramForm.getIds().size()){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库或耗材物资不可重复入库!"); } //修改为入库状态 safeMaterialDetailInfoService.updateReceiptStatusByIds(idList,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); 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(); } } 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,6 +376,10 @@ public ResultVO deliveryBatchRandom(MterialRandomDeliveryReq req) { UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); List<Long> idList = new ArrayList<>(); //加分布式锁,防止重复创建规则 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()); @@ -335,6 +400,17 @@ 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(); } } return new ResultVO(ResultCodes.OK); } @@ -501,6 +577,10 @@ */ @Override public ResultVO singleDelivery(SafeMaterialDetailReq req) { //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_SINGLEDELIVERY"); try { lock.lock(10, TimeUnit.SECONDS); //获取该条数据 SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId()); if(null == vo){ @@ -522,6 +602,17 @@ 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(); } } return new ResultVO<>(ResultCodes.OK); } @@ -536,6 +627,10 @@ if(null == id){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SMD_SINGLERECEIPT"); try { lock.lock(10, TimeUnit.SECONDS); //获取该条数据 SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id); if(null == vo){ @@ -550,6 +645,17 @@ } //修改出入库状态为入库 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(); } } return new ResultVO<>(ResultCodes.OK); } 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,10 +48,15 @@ private SafeMaterialClassifyInfoService safeMaterialClassifyInfoService; @Autowired private SafeMaterialDetailInfoService safeMaterialDetailInfoService; @Autowired private RedissonClient redissonClient; @Override public ResultVO save(SafeMaterialAddReq req) { ResultVO resultVO = null; //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SM_INSERT"); try { lock.lock(10, TimeUnit.SECONDS); //获取部门信息 DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); if(null == ConsumableEnum.getByCode(req.getConsumable())){ @@ -79,12 +86,28 @@ //插入 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; //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SM_UPDATE"); try { lock.lock(10, TimeUnit.SECONDS); //获取部门信息 DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); @@ -109,7 +132,19 @@ 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(); } } return new ResultVO(ResultCodes.OK); } @@ -136,6 +171,10 @@ public ResultVO delete(Long id) { ResultVO resultVO = null; //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SM_DELETE"); try { lock.lock(10, TimeUnit.SECONDS); //删除之前检查详表中是否还有该物物资数据 int count = safeMaterialDetailInfoService.getCountBySmId(id); if(count > 0){ @@ -150,6 +189,19 @@ }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,6 +210,10 @@ if(ids.length == 0){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } //加分布式锁,防止重复创建规则 RLock lock = redissonClient.getLock("LOCK_SM_DELETEBATCH"); try { lock.lock(10, TimeUnit.SECONDS); List<Long> idList = Arrays.asList(ids); int count = safeMaterialDetailInfoService.getCountBySmIds(idList); //判断是否绑定具体安全物资数据 @@ -165,6 +221,19 @@ 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(); } } return new ResultVO(ResultCodes.OK); } 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> 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>