From 9488c8660ca0332d228a7cfaa1afef5c406006e5 Mon Sep 17 00:00:00 2001 From: 15036302109 Date: Wed, 31 Jul 2024 13:48:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E6=80=A5=E6=95=91=E6=8F=B4=E7=89=A9?= =?UTF-8?q?=E8=B5=84--=E5=BD=95=E5=85=A5=E7=89=A9=E8=B5=84=E6=97=B6,?= =?UTF-8?q?=E8=8B=A5=E6=9C=AC=E9=83=A8=E9=97=A8=E5=B7=B2=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E7=89=A9=E8=B5=84=E5=88=99=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E7=89=A9=E8=B5=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ehs/EhsMaterialController.java | 26 ++++++++++++ .../com/ruoyi/common/constant/HttpStatus.java | 5 +++ .../ehsMaterial/mapper/EhsMaterialMapper.java | 5 +++ .../service/IEhsMaterialService.java | 12 ++++++ .../service/impl/EhsMaterialServiceImpl.java | 41 +++++++++++++++++++ .../mapper/ehs/EhsMaterialMapper.xml | 11 ++++- 6 files changed, 99 insertions(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java index 8bca699..fb26e99 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java @@ -7,6 +7,8 @@ import java.util.Set; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.ehsRisk.domain.EhsRisk; import com.ruoyi.materialClass.domain.MaterialClassMaster; @@ -126,6 +128,30 @@ public class EhsMaterialController extends BaseController return toAjax(ehsMaterialService.save(ehsMaterial)); } + /** + * 检查物资新增时, 物资是否重复 + */ + @PostMapping("/checkRepeat") + public AjaxResult checkRepeat(@RequestBody EhsMaterial ehsMaterial) + { + ehsMaterial.setDeptId(SecurityUtils.getDeptId()); + List list = ehsMaterialService.checkMaterialRepeat(ehsMaterial); + if (list != null && list.size() > 0) { + // 说明有重复的,返回响应码209 + return new AjaxResult(HttpStatus.DATA_REPEAT, "有重复数据"); + } + // 不重复则插入 + return toAjax(ehsMaterialService.save(ehsMaterial)); + } + + /** + * 合并物资数量 + */ + @PostMapping("/merge") + public AjaxResult mergeMaterial(@RequestBody EhsMaterial ehsMaterial) { + return toAjax(ehsMaterialService.mergeMaterial(ehsMaterial)); + } + /** * 修改物资信息包含 通用应急救援装备”“防汛抗旱应急救援装备”“森林防灭火应急救援装备”“救灾物资” */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java index a983c77..bb85049 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java @@ -27,6 +27,11 @@ public class HttpStatus */ public static final int NO_CONTENT = 204; + /** + * 有重复数据 + */ + public static final int DATA_REPEAT = 209; + /** * 资源已被移除 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/mapper/EhsMaterialMapper.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/mapper/EhsMaterialMapper.java index e9ff92a..4e577d8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/mapper/EhsMaterialMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/mapper/EhsMaterialMapper.java @@ -28,4 +28,9 @@ public interface EhsMaterialMapper extends BaseMapper { */ public List selectEhsMaterialList(EhsMaterial ehsMaterial); public List selectEhsMateriallExportList(EhsMaterial ehsMaterial); + + /** + * 检查物资新增时, 物资是否重复 + */ + List checkMaterialRepeat(EhsMaterial ehsMaterial); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java index ddc557d..a432ba2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java @@ -30,4 +30,16 @@ public interface IEhsMaterialService extends IService { public List selectEhsMaterialList(EhsMaterial ehsMaterial); public String importMaterial(List list,String classType, Boolean isUpdateSupport); public List selectEhsMateriallExportList(EhsMaterial ehsMaterial); + + /** + * 检查物资新增时, 物资是否重复 + */ + List checkMaterialRepeat(EhsMaterial ehsMaterial); + + /** + * 合并物资数量 + * @param ehsMaterial + * @return + */ + boolean mergeMaterial(EhsMaterial ehsMaterial); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java index ac97bea..1d3e68d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.ehsMaterialDetail.domain.EhsMaterialDetail; +import com.ruoyi.ehsMaterialDetail.service.IEhsMaterialDetailService; import com.ruoyi.ehsRisk.domain.EhsRisk; import com.ruoyi.materialClass.domain.MaterialClassMaster; import com.ruoyi.materialClass.domain.MaterialClassSub; @@ -14,6 +16,9 @@ import com.ruoyi.materialClass.mapper.MaterialClassSubMapper; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.utils.StringUtils; + +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -21,6 +26,7 @@ import java.util.stream.Collectors; import com.ruoyi.ehsMaterial.mapper.EhsMaterialMapper; import com.ruoyi.ehsMaterial.domain.EhsMaterial; import com.ruoyi.ehsMaterial.service.IEhsMaterialService; +import org.springframework.transaction.annotation.Transactional; import javax.validation.Validator; @@ -38,6 +44,8 @@ public class EhsMaterialServiceImpl extends ServiceImpl checkMaterialRepeat(EhsMaterial ehsMaterial) { + return ehsMaterialMapper.checkMaterialRepeat(ehsMaterial); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean mergeMaterial(EhsMaterial ehsMaterial) { + ehsMaterial.setDeptId(SecurityUtils.getDeptId()); + // 1.先根据部门,物资的一级、二级、三级分类查询数据库,取出数量最多的那条重复物资,与前端传来的数量相加 + List ehsMaterials = ehsMaterialMapper.checkMaterialRepeat(ehsMaterial); + EhsMaterial databaseMaterial = ehsMaterials.get(0); + Integer materialQuantity = 0; + if (StringUtils.isNotBlank(databaseMaterial.getMaterialQuantity())) { + materialQuantity = Integer.valueOf(databaseMaterial.getMaterialQuantity()) + Integer.valueOf(ehsMaterial.getMaterialQuantity()); + } + // 2.数量相加后更新数据库中该物资的数量 + databaseMaterial.setMaterialQuantity(materialQuantity.toString()); + boolean b = this.updateById(databaseMaterial); + // 3.插入出入库明细,合并算入库 + EhsMaterialDetail ehsMaterialDetail = new EhsMaterialDetail(); + ehsMaterialDetail.setMaterialId(databaseMaterial.getMaterialId()); + ehsMaterialDetail.setOutboundQuantity(ehsMaterial.getMaterialQuantity()); + ehsMaterialDetail.setOutboundTime(new Date()); + ehsMaterialDetail.setOutboundUserId(SecurityUtils.getUserId()); + ehsMaterialDetail.setOperateType(1); + ehsMaterialDetail.setInventory(new BigDecimal(materialQuantity)); + return ehsMaterialDetailService.save(ehsMaterialDetail); + } + private LambdaQueryWrapper buildQueryWrapper(EhsMaterial query) { Map params = query.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); diff --git a/ruoyi-system/src/main/resources/mapper/ehs/EhsMaterialMapper.xml b/ruoyi-system/src/main/resources/mapper/ehs/EhsMaterialMapper.xml index 9526825..61e16c9 100644 --- a/ruoyi-system/src/main/resources/mapper/ehs/EhsMaterialMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/ehs/EhsMaterialMapper.xml @@ -88,6 +88,16 @@ FROM and m2.class_name_sub like concat('%', #{classNameKey}, '%') +