危化品全生命周期管理后端
kongzy
2024-09-14 ed36af4d4cc5feac72a384d85f9032fc6dc1223a
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.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.HzEntryRecord;
import com.gkhy.hazmat.system.domain.HzHazmat;
import com.gkhy.hazmat.system.domain.HzHazmatBasic;
import com.gkhy.hazmat.system.domain.HzWarehouseRecord;
import com.gkhy.hazmat.system.mapper.HzEntryRecordMapper;
import com.gkhy.hazmat.system.mapper.HzHazmatBasicMapper;
import com.gkhy.hazmat.system.mapper.HzHazmatMapper;
import com.gkhy.hazmat.system.mapper.HzWarehouseRecordMapper;
import com.gkhy.hazmat.system.domain.*;
import com.gkhy.hazmat.system.mapper.*;
import com.gkhy.hazmat.system.service.HzEntryRecordService;
import com.gkhy.hazmat.system.service.HzHazmatService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,6 +50,8 @@
    private HzWarehouseRecordMapper warehouseRecordMapper;
    @Autowired
    private CustomEventPublisher customEventPublisher;
    @Autowired
    private SysCompanyMapper companyMapper;
    @Override
    public CommonPage selectEntryRecordList(HzEntryRecord entryRecord) {
@@ -87,6 +83,9 @@
        if(hazmatBasic==null){
            throw new ApiException("危化品基础数据不存在");
        }
        if(entryRecord.getNum()>hazmatBasic.getMaxEntry()){
            throw new ApiException("数量超过单次入库最大数量<"+hazmatBasic.getMaxEntry()+">");
        }
        entryRecord.setCompanyId(currentUser.getCompanyId());
        entryRecord.setCreateBy(currentUser.getUsername());
        checkUserAllowed(null,currentUser);
@@ -103,11 +102,18 @@
    }
    public void generateCode(HzEntryRecord 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.MATERIAL.getCode())
                .append(code)
                .append(currentDate);
        HzEntryRecord er=baseMapper.selectLastEntryRecord(prefixBuilder.toString(),entryRecord.getCompanyId());
        int startCode=0;
        int startCode=1;
        int endCode=startCode+entryRecord.getNum()-1;
        if(er!=null){
            startCode=er.getEndCode()+1;
@@ -209,10 +215,17 @@
    public int updateEntryRecord(HzEntryRecord entryRecord) {
        SysUser currentUser = SecurityUtils.getLoginUser().getUser();
        checkUserAllowed(entryRecord,currentUser);
        HzHazmatBasic hazmatBasic=hazmatBasicMapper.selectById(entryRecord.getBasicId());
        if(hazmatBasic==null){
            throw new ApiException("危化品基础数据不存在");
        }
        HzEntryRecord existEr=baseMapper.selectById(entryRecord.getId());
        if(existEr.getState().equals(EntryStateEnum.ENTER.getCode())){
            throw new ApiException("已经入库,不能再修改");
        }
        if(entryRecord.getNum()>hazmatBasic.getMaxEntry()){
            throw new ApiException("数量超过单次入库最大数量<"+hazmatBasic.getMaxEntry()+">");
        }
        entryRecord.setUpdateBy(currentUser.getUsername());
        int row=baseMapper.updateById(entryRecord);
        if(row<1){