From da2c594ade5d69621dd11a13bb758477e2dc079e Mon Sep 17 00:00:00 2001 From: “djh” <“3298565835@qq.com”> Date: 星期三, 07 五月 2025 15:57:51 +0800 Subject: [PATCH] 危化品新版修改 --- hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java | 86 +++++++++++++++++++++++++++++++++--------- 1 files changed, 67 insertions(+), 19 deletions(-) diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java index acad8a2..8bec69e 100644 --- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java +++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java @@ -1,7 +1,10 @@ package com.gkhy.hazmat.system.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.pagehelper.PageHelper; import com.gkhy.hazmat.common.api.CommonPage; import com.gkhy.hazmat.common.config.IdTableNameHandler; import com.gkhy.hazmat.common.domain.entity.SysUser; @@ -21,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -46,6 +50,7 @@ @Autowired private HzWarehouseMapper warehouseMapper; + @Override public CommonPage selectHazmatList(HzHazmat hzHazmat) { if(hzHazmat.getWarehouseId()==null||hzHazmat.getBasicId()==null){ @@ -53,9 +58,13 @@ } SysUser currentUser = SecurityUtils.getLoginUser().getUser(); checkUserAllowed(null,currentUser); - //设置分表id - IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); - hzHazmat.setCompanyId(currentUser.getCompanyId()); + if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ + IdTableNameHandler.setCurrentId(hzHazmat.getCompanyId()); + }else { + //设置分表id + IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); + hzHazmat.setCompanyId(currentUser.getCompanyId()); + } PageUtils.startPage(); List<HzHazmat> hazmatList = baseMapper.selectHazmatList(hzHazmat); IdTableNameHandler.removeCurrentId(); @@ -66,27 +75,41 @@ public CommonPage selectHazmatGroupWarehouse(HzHazmat hzHazmat) { SysUser currentUser = SecurityUtils.getLoginUser().getUser(); checkUserAllowed(null,currentUser); - hzHazmat.setCompanyId(currentUser.getCompanyId()); - //设置分表id - IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); + if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ + IdTableNameHandler.setCurrentId(hzHazmat.getCompanyId()); + }else { + hzHazmat.setCompanyId(currentUser.getCompanyId()); + //设置分表id + //todo + IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); + } PageUtils.startPage(); List<HzHazmatWarehouseVO> hazmatList = baseMapper.selectHazmatGroupWareHouse(hzHazmat); if(!hazmatList.isEmpty()) { List<Long> warehouseIds = hazmatList.stream().map(HzHazmatWarehouseVO::getWarehouseId).collect(Collectors.toList()); List<Long> basicIds = hazmatList.stream().map(HzHazmatWarehouseVO::getBasicId).collect(Collectors.toList()); + List<Integer> cupboardIds = hazmatList.stream().map(HzHazmatWarehouseVO::getCupboardId).collect(Collectors.toList()); List<HzHazmatBasic> hazmatBasicList = hazmatBasicMapper.selectHazmatBasicListByIds(basicIds); List<HzWarehouse> warehouseList = warehouseMapper.selectWarehouseListByIds(warehouseIds); + List<HzWarehouseCupboard> hzWarehouseCupboards = warehouseMapper.selectByCupboardIds(cupboardIds); + Map<Long,HzHazmatBasic> hazmatBasicMap=hazmatBasicList.stream().collect(Collectors.toMap(HzHazmatBasic::getId, item->item)); Map<Long,HzWarehouse> warehouseMap=warehouseList.stream().collect(Collectors.toMap(HzWarehouse::getId, item->item)); + Map<Integer, HzWarehouseCupboard> cupboardMap = hzWarehouseCupboards.stream().collect(Collectors.toMap(HzWarehouseCupboard::getId, item -> item)); for(HzHazmatWarehouseVO hazmatWarehouseVO:hazmatList){ HzHazmatBasic hazmatBasic=hazmatBasicMap.get(hazmatWarehouseVO.getBasicId()); HzWarehouse warehouse=warehouseMap.get(hazmatWarehouseVO.getWarehouseId()); + HzWarehouseCupboard hzWarehouseCupboard = cupboardMap.get(hazmatWarehouseVO.getCupboardId()); if(hazmatBasic!=null){ hazmatWarehouseVO.setHazmatBasic(hazmatBasic); } if(warehouse!=null){ hazmatWarehouseVO.setWarehouseName(warehouse.getName()); } + if (hzWarehouseCupboard != null){ + hazmatWarehouseVO.setCupboardName(hzWarehouseCupboard.getCupboardName()); + } + } } IdTableNameHandler.removeCurrentId(); @@ -142,7 +165,7 @@ @Override @Transactional(rollbackFor = RuntimeException.class) - public void hazmatUse(Long hazmatId) { + public void hazmatUse(Long hazmatId, Integer used) { SysUser currentUser=SecurityUtils.getLoginUser().getUser(); checkUserAllowed(null,currentUser); //设置分表id @@ -153,24 +176,39 @@ } checkUserAllowed(hazmat,currentUser); //获取变动前仓库库存 - int count = baseMapper.selectHazmatCountOfWarehouse(hazmat.getWarehouseId(), hazmat.getBasicId(), currentUser.getCompanyId()); - hazmat.setState(HazmatStatusEnum.USING.getCode()); - hazmat.setUpdateBy(currentUser.getUsername()); - updateById(hazmat); + int count = baseMapper.selectHazmatCountOfWarehouse(hazmat.getWarehouseId(), hazmat.getBasicId(), currentUser.getCompanyId(),hazmat.getCupboardId()); + //生成流向 + BigDecimal remaining=hazmat.getRemaining(); HzHazmatFlow hazmatFlow=new HzHazmatFlow(); hazmatFlow.setHazmatId(hazmatId); hazmatFlow.setBasicId(hazmat.getBasicId()); hazmatFlow.setState(OperateStatusEnum.USING.getCode()); hazmatFlow.setCompanyId(currentUser.getCompanyId()); - hazmatFlow.setNum(hazmat.getRemaining().multiply(BigDecimal.valueOf(-1))); + hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); hazmatFlow.setCreateId(currentUser.getId()); hazmatFlowMapper.insert(hazmatFlow); + hazmat.setState(HazmatStatusEnum.USING.getCode()); + if(used==1){//用尽流向 + hazmatFlow=new HzHazmatFlow(); + hazmatFlow.setHazmatId(hazmatId); + hazmatFlow.setBasicId(hazmat.getBasicId()); + hazmatFlow.setState(OperateStatusEnum.USE_UP.getCode()); + hazmatFlow.setCompanyId(currentUser.getCompanyId()); + hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); + hazmatFlow.setCreateId(currentUser.getId()); + hazmatFlowMapper.insert(hazmatFlow); + hazmat.setState(HazmatStatusEnum.USED.getCode()); + hazmat.setRemaining(BigDecimal.valueOf(0)); + } + hazmat.setUpdateBy(currentUser.getUsername()); + updateById(hazmat);//更新试剂状态 //生成库存变动记录 //新增危化品变动记录 HzWarehouseRecord warehouseRecord = new HzWarehouseRecord() .setWarehouseId(hazmat.getWarehouseId()) .setBasicId(hazmat.getBasicId()) + .setCupboardId(hazmat.getCupboardId()) .setCreateId(currentUser.getId()) .setNum(-1) .setState(OperateStatusEnum.USING.getCode()) @@ -191,15 +229,22 @@ //设置分表id IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); HzHazmat dbhazmat=getById(hazmat.getId()); - if(!dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())){ - throw new ApiException("危化品非使用中状态,不能进行归还操作"); + BigDecimal remaining=dbhazmat.getRemaining(); + if(!dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())&&!dbhazmat.getState().equals(HazmatStatusEnum.USED.getCode())){ + throw new ApiException("危化品非使用中或者用尽状态,不能进行归还操作"); } - if(dbhazmat.getRemaining().compareTo(hazmat.getRemaining())<0){ + if(dbhazmat.getState().equals(HazmatStatusEnum.USING.getCode())&&remaining.compareTo(hazmat.getRemaining())<0){ throw new ApiException("退还的容量不能高于库存容量"); + } + if(dbhazmat.getState().equals(HazmatStatusEnum.USED.getCode())){ + HzHazmatBasic hazmatBasic=hazmatBasicMapper.selectById(dbhazmat.getBasicId()); + if(hazmatBasic.getMetering().compareTo(hazmat.getRemaining())<0) { + throw new ApiException("退还的容量不能高于最小包装数量"); + } } checkUserAllowed(dbhazmat,currentUser); //获取变动前仓库库存 - int count = baseMapper.selectHazmatCountOfWarehouse(dbhazmat.getWarehouseId(), dbhazmat.getBasicId(), currentUser.getCompanyId()); + int count = baseMapper.selectHazmatCountOfWarehouse(dbhazmat.getWarehouseId(), dbhazmat.getBasicId(), currentUser.getCompanyId(),dbhazmat.getCupboardId()); hazmat.setState(HazmatStatusEnum.USEWAREHOUSEIN.getCode()); hazmat.setUpdateBy(currentUser.getUsername()); updateById(hazmat); @@ -218,6 +263,7 @@ HzWarehouseRecord warehouseRecord = new HzWarehouseRecord() .setWarehouseId(dbhazmat.getWarehouseId()) .setBasicId(dbhazmat.getBasicId()) + .setCupboardId(hazmat.getCupboardId()) .setCreateId(currentUser.getId()) .setNum(1) .setState(OperateStatusEnum.RETURN.getCode()) @@ -238,8 +284,9 @@ if(!hazmat.getState().equals(HazmatStatusEnum.USING.getCode())){ throw new ApiException("危化品非使用中状态,不能进行用完登记操作"); } - + BigDecimal remaining=hazmat.getRemaining(); hazmat.setState(HazmatStatusEnum.USED.getCode()); + hazmat.setRemaining(BigDecimal.valueOf(0)); hazmat.setUpdateBy(currentUser.getUsername()); updateById(hazmat); //生成流向 @@ -248,7 +295,7 @@ hazmatFlow.setBasicId(hazmat.getBasicId()); hazmatFlow.setState(OperateStatusEnum.USE_UP.getCode()); hazmatFlow.setCompanyId(currentUser.getCompanyId()); - hazmatFlow.setNum(hazmat.getRemaining().multiply(BigDecimal.valueOf(-1))); + hazmatFlow.setNum(remaining.multiply(BigDecimal.valueOf(-1))); hazmatFlow.setCreateId(currentUser.getId()); hazmatFlowMapper.insert(hazmatFlow); IdTableNameHandler.removeCurrentId(); @@ -267,7 +314,7 @@ } checkUserAllowed(hazmat,currentUser); //获取变动前仓库库存 - int count = baseMapper.selectHazmatCountOfWarehouse(hazmat.getWarehouseId(), hazmat.getBasicId(), currentUser.getCompanyId()); + int count = baseMapper.selectHazmatCountOfWarehouse(hazmat.getWarehouseId(), hazmat.getBasicId(), currentUser.getCompanyId(),hazmat.getCupboardId()); hazmat.setState(HazmatStatusEnum.DISCARD.getCode()); hazmat.setUpdateBy(currentUser.getUsername()); updateById(hazmat); @@ -286,6 +333,7 @@ HzWarehouseRecord warehouseRecord = new HzWarehouseRecord() .setWarehouseId(hazmat.getWarehouseId()) .setBasicId(hazmat.getBasicId()) + .setCupboardId(hazmat.getCupboardId()) .setCreateId(currentUser.getId()) .setNum(-1) .setState(OperateStatusEnum.DISCARD.getCode()) -- Gitblit v1.9.2