From 65ca50935315a89e219b7c974caf95dc28895ffc Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: Thu, 16 Oct 2025 08:37:56 +0800
Subject: [PATCH] 修改
---
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java | 76 ++++++++++++++++++++++++++++++-------
1 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
index 38d041e..7a7234b 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
@@ -15,14 +15,8 @@
import com.gkhy.hazmat.common.utils.PageUtils;
import com.gkhy.hazmat.common.utils.SecurityUtils;
import com.gkhy.hazmat.common.utils.StringUtils;
-import com.gkhy.hazmat.system.domain.HzProduct;
-import com.gkhy.hazmat.system.domain.HzProductBasic;
-import com.gkhy.hazmat.system.domain.HzProductEntryRecord;
-import com.gkhy.hazmat.system.domain.HzProductWarehouseRecord;
-import com.gkhy.hazmat.system.mapper.HzProductBasicMapper;
-import com.gkhy.hazmat.system.mapper.HzProductEntryRecordMapper;
-import com.gkhy.hazmat.system.mapper.HzProductMapper;
-import com.gkhy.hazmat.system.mapper.HzProductWarehouseRecordMapper;
+import com.gkhy.hazmat.system.domain.*;
+import com.gkhy.hazmat.system.mapper.*;
import com.gkhy.hazmat.system.service.HzProductEntryRecordService;
import com.gkhy.hazmat.system.service.HzProductService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,11 +50,13 @@
private HzProductWarehouseRecordMapper productWarehouseRecordMapper;
@Autowired
private CustomEventPublisher customEventPublisher;
+ @Autowired
+ private SysCompanyMapper companyMapper;
@Override
public CommonPage selectEntryRecordList(HzProductEntryRecord entryRecord) {
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
- if (!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
+ if (!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())&&!currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())) {
entryRecord.setCompanyId(currentUser.getCompanyId());
}
PageUtils.startPage();
@@ -87,6 +83,9 @@
if(productBasic==null){
throw new ApiException("成品基础数据不存在");
}
+ if(entryRecord.getNum()>productBasic.getMaxEntry()){
+ throw new ApiException("数量超过单次入库最大数量<"+productBasic.getMaxEntry()+">");
+ }
entryRecord.setCompanyId(currentUser.getCompanyId());
entryRecord.setCreateBy(currentUser.getUsername());
checkUserAllowed(null,currentUser);
@@ -103,11 +102,17 @@
}
public void generateCode(HzProductEntryRecord entryRecord){
+ SysCompany company=companyMapper.selectById(entryRecord.getCompanyId());
+ String code=company.getCode();
+ if(StringUtils.isBlank(code)){
+ throw new ApiException("公司两位编码为空");
+ }
String currentDate= DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
StringBuilder prefixBuilder=new StringBuilder().append(CodePrexEnum.GOOD.getCode())
+ .append(code)
.append(currentDate);
HzProductEntryRecord per=baseMapper.selectLastEntryRecord(prefixBuilder.toString(),entryRecord.getCompanyId());
- int startCode=0;
+ int startCode=1;
int endCode=startCode+entryRecord.getNum()-1;
if(per!=null){
startCode=per.getEndCode()+1;
@@ -155,6 +160,7 @@
//新增危化品变动记录
HzProductWarehouseRecord warehouseRecord = new HzProductWarehouseRecord()
.setWarehouseId(entryRecord.getWarehouseId())
+ .setCupboardId(entryRecord.getCupboardId())
.setBasicId(productBasic.getId())
.setNum(entryRecord.getNum())
.setCompanyId(currentUser.getCompanyId())
@@ -168,6 +174,7 @@
String lastCode= StringUtils.addZeroForNum(String.valueOf(i),4);
String code=String.format("%s%s",entryRecord.getCodePrex(),lastCode);
productList.add(new HzProduct().setWarehouseId(entryRecord.getWarehouseId())
+ .setCupboardId(entryRecord.getCupboardId())
.setBasicId(entryRecord.getBasicId())
.setEntryId(entryRecord.getId())
.setRemaining(productBasic.getMetering())
@@ -208,9 +215,19 @@
public int updateEntryRecord(HzProductEntryRecord entryRecord) {
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
checkUserAllowed(entryRecord,currentUser);
+ HzProductBasic productBasic=productBasicMapper.selectById(entryRecord.getBasicId());
+ if(productBasic==null){
+ throw new ApiException("成品基础数据不存在");
+ }
+ if(entryRecord.getNum()>productBasic.getMaxEntry()){
+ throw new ApiException("数量超过单次入库最大数量<"+productBasic.getMaxEntry()+">");
+ }
HzProductEntryRecord existEr=baseMapper.selectById(entryRecord.getId());
if(existEr.getState().equals(EntryStateEnum.ENTER.getCode())){
throw new ApiException("已经入库,不能再修改");
+ }
+ if (!Objects.equals(existEr.getNum(),entryRecord.getNum())){
+ generateCode2(entryRecord);
}
entryRecord.setUpdateBy(currentUser.getUsername());
int row=baseMapper.updateById(entryRecord);
@@ -220,16 +237,43 @@
return row;
}
+ private void generateCode2(HzProductEntryRecord entryRecord) {
+ SysCompany company=companyMapper.selectById(entryRecord.getCompanyId());
+ String code=company.getCode();
+ if(StringUtils.isBlank(code)){
+ throw new ApiException("公司两位编码为空");
+ }
+ String currentDate= DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
+ StringBuilder prefixBuilder=new StringBuilder().append(CodePrexEnum.GOOD.getCode())
+ .append(code)
+ .append(currentDate);
+ HzProductEntryRecord per=baseMapper.selectLastEndCodeEntryRecord(prefixBuilder.toString(),entryRecord.getCompanyId());
+ int startCode=1;
+ int endCode=startCode+entryRecord.getNum()-1;
+ if(per!=null){
+ startCode=per.getEndCode()+1;
+ endCode=startCode+entryRecord.getNum()-1;
+ }
+ entryRecord.setCodePrex(prefixBuilder.toString());
+ entryRecord.setStartCode(startCode);
+ entryRecord.setEndCode(endCode);
+ entryRecord.setState(EntryStateEnum.UNENTER.getCode());
+ }
+
@Override
- public CommonPage selectProductListByEntryId(Long entryId) {
+ public CommonPage selectProductListByEntryId(Long entryId,Long companyId) {
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
HzProductEntryRecord entryRecord=getById(entryId);
if(entryRecord==null){
throw new ApiException("入库信息不存在");
}
checkUserAllowed(entryRecord,currentUser);
- //设置分表id
- IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
+ if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
+ IdTableNameHandler.setCurrentId(companyId);
+ }else {
+ //设置分表id
+ IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
+ }
PageUtils.startPage();
List<HzProduct> productList = productMapper.selectProductList(new HzProduct().setEntryId(entryId));
IdTableNameHandler.removeCurrentId();
@@ -242,8 +286,10 @@
throw new ApiException("管理员不能操作");
}
if(entryRecord!=null){
- if(!Objects.equals(user.getCompanyId(), entryRecord.getCompanyId())){
- throw new ApiException("无权限操作其他企业数据");
+ if (!user.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
+ if(!Objects.equals(user.getCompanyId(), entryRecord.getCompanyId())){
+ throw new ApiException("无权限操作其他企业数据");
+ }
}
}
}
--
Gitblit v1.9.2