diff --git a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/SltAgreementInfo.java b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/SltAgreementInfo.java index 30c851f9..5ffd4cda 100644 --- a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/SltAgreementInfo.java +++ b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/SltAgreementInfo.java @@ -186,6 +186,7 @@ public class SltAgreementInfo { private Integer codeNum; private Integer unitId; private Integer lotId; + private Integer leaseType; private List node; } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java index 93e72be7..ee70e65b 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/BackReceiveServiceImpl.java @@ -55,7 +55,7 @@ public class BackReceiveServiceImpl implements BackReceiveService { MachinePart machinePart = tmTaskMapper.getMachineParts(typeId); machinePart.setParentId(record.getId().intValue()); int countMachineByPidAndTid = tmTaskMapper.getCountMachineByPidAndTid(machinePart); - Double machinePartNum = typeId.getPartNum() * Double.parseDouble(backApplyInfo.getPreNum()); + Double machinePartNum = typeId.getPartNum() * Double.parseDouble(backApplyInfo.getAuditNum()); count1 += machinePartNum; count2 += countMachineByPidAndTid; machinePart.setPartNum(machinePartNum - countMachineByPidAndTid); @@ -65,7 +65,7 @@ public class BackReceiveServiceImpl implements BackReceiveService { if (count1 == count2) { backApplyInfo.setPartNum(0); } else { - backApplyInfo.setPartNum((int) Double.parseDouble(backApplyInfo.getPreNum())); + backApplyInfo.setPartNum((int) Double.parseDouble(backApplyInfo.getAuditNum())); } } } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java index 45ecd384..48d11db9 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java @@ -1,6 +1,7 @@ package com.bonus.sgzb.base.controller; import com.bonus.sgzb.base.domain.MaPartType; +import com.bonus.sgzb.base.domain.MapType; import com.bonus.sgzb.base.service.ExcelService; import com.bonus.sgzb.base.service.IPartTypeService; import com.bonus.sgzb.common.core.utils.poi.ExcelUtil; @@ -103,7 +104,7 @@ public class MaPartTypeController extends BaseController { // 保存文件 file.transferTo(filePath.toFile()); - Map>> stringMapMap = excelService.readExcelFile(filePath.toString()); + Map>> stringMapMap = excelService.readExcelFile(filePath.toString()); return AjaxResult.success(); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MapType.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MapType.java new file mode 100644 index 00000000..c26b5b39 --- /dev/null +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MapType.java @@ -0,0 +1,47 @@ +package com.bonus.sgzb.base.domain; + +import com.bonus.sgzb.common.core.annotation.Excel; +import com.bonus.sgzb.common.core.web.domain.BaseEntity; +import lombok.Data; + +import java.util.Objects; + +/** + * 配件类型管理ma_part_type(MaPartType)表实体类 + * + * @author makejava + * @since 2023-11-27 16:44:09 + */ +@SuppressWarnings("serial") +@Data +public class MapType extends BaseEntity { + + //类型名称 + @Excel(name = "类型名称") + private String paName; + + //计量单位ID + @Excel(name = "计量单位ID") + private String unitId; + + //原值 + @Excel(name = "原值") + private String buyPrice; + + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MapType mapType = (MapType) o; + return Objects.equals(paName, mapType.paName) && + Objects.equals(unitId, mapType.unitId) && + Objects.equals(buyPrice, mapType.buyPrice); + } + + @Override + public int hashCode() { + return Objects.hash(paName, unitId, buyPrice); + } + +} + diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/ExcelMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/ExcelMapper.java index 1d127f02..8dc3ff53 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/ExcelMapper.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/ExcelMapper.java @@ -4,16 +4,41 @@ import com.bonus.sgzb.base.domain.MaPartType; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + @Mapper public interface ExcelMapper { + MaPartType selectMa(@Param("name") String name,@Param("id") long id); + void insertPaName(MaPartType maPartType); - String selectPaName(@Param("firstLevel") String firstLevel); - - - int insertPaName(MaPartType firstLevel); - - void insertPaTwoName(MaPartType maPartType); - - void insertPaThreeName(MaPartType maPartType); +// +// String selectPaName(@Param("firstLevel") String firstLevel); +// +// +// int insertPaName(MaPartType firstLevel); +// +// void insertPaTwoName(MaPartType maPartType); +// +// void insertPaThreeName(MaPartType maPartType); +// +// int selectThreeName(String secondLevel); +// +// int selectTwoName(String entry2); +// +// String selectPaNameAndpaId(String value, String o); +// +// +// List selectListParentid(String firstLevel); +// +// String selectName(String parentId2); +// +// +// void updateLevelStatus(String parentId); +// +// String selectStatus(String pId); +// +// MaPartType selectTwoPaName(@Param("secondLevel") String secondLevel,@Param("id") Long id); +// +// String selectThreePaName(@Param("value") String value,@Param("paId") Long paId); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/ExcelService.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/ExcelService.java index 5a5d2313..c89fab99 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/ExcelService.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/ExcelService.java @@ -1,11 +1,11 @@ package com.bonus.sgzb.base.service; -import org.springframework.stereotype.Service; +import com.bonus.sgzb.base.domain.MapType; import java.util.List; import java.util.Map; public interface ExcelService { - Map>> readExcelFile(String filePath); + Map>> readExcelFile(String filePath); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/ExcelServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/ExcelServiceImpl.java index 764cad59..88d55824 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/ExcelServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/ExcelServiceImpl.java @@ -1,11 +1,11 @@ package com.bonus.sgzb.base.service.impl;// ExcelServiceImpl.java import com.bonus.sgzb.base.domain.MaPartType; +import com.bonus.sgzb.base.domain.MapType; import com.bonus.sgzb.base.mapper.ExcelMapper; import com.bonus.sgzb.base.service.ExcelService; import com.bonus.sgzb.common.security.utils.SecurityUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.xmlbeans.impl.xb.xsdschema.Public; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,10 +22,10 @@ public class ExcelServiceImpl implements ExcelService { /* - * 将读取的excel文件转为 - * */ + * 将读取的excel文件转为 + * */ @Override - public Map>> readExcelFile(String filePath) { + public Map>> readExcelFile(String filePath) { FileInputStream excelFile = null; Workbook workbook = null; @@ -34,10 +34,8 @@ public class ExcelServiceImpl implements ExcelService { workbook = new XSSFWorkbook(excelFile); Sheet datatypeSheet = workbook.getSheetAt(0); Iterator iterator = datatypeSheet.iterator(); - String fourthLevel = ""; - String fifthLevel =""; - Long id = null; - Map>> level3Relation = new HashMap<>(); + + Map>> level3Relation = new HashMap<>(); while (iterator.hasNext()) { Row currentRow = iterator.next(); @@ -51,72 +49,46 @@ public class ExcelServiceImpl implements ExcelService { Cell thirdLevelCell = currentRow.getCell(3); Cell fourthLevelCell = currentRow.getCell(4); Cell fifthLevelCell = currentRow.getCell(5); - + Cell sixthLevelCell = currentRow.getCell(6); + if (sixthLevelCell != null){ + throw new RuntimeException("导入模板不正确"); + } String firstLevel = getCellValueAsString(firstLevelCell); String secondLevel = getCellValueAsString(secondLevelCell); - String thirdLevel = getCellValueAsString(thirdLevelCell); - fourthLevel = getCellValueAsString(fourthLevelCell); - fifthLevel = getCellValueAsString(fifthLevelCell); - level3Relation.computeIfAbsent(firstLevel, k -> new HashMap<>()) - .computeIfAbsent(secondLevel, k -> new ArrayList<>()) - .add(thirdLevel); - } - - // 遍历外层Map - for (Map.Entry>> entry1 : level3Relation.entrySet()) { - String firstLevel = entry1.getKey(); // 获取第一层级的键 - String parentId = excelMapper.selectPaName(firstLevel); - - //产生返回值并且进行判断是否是pa_name列已经有的,并且返回对应的pa_id - if(parentId == null || parentId == ""){ - MaPartType maPartType = new MaPartType(); - maPartType.setPaName(firstLevel); - maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); - excelMapper.insertPaName(maPartType);//如果第一层在数据库中查询不到则插入数据,并且读取到parent_id - id = maPartType.getPaId(); + MapType thirdLevel = new MapType(); + thirdLevel.setPaName(getCellValueAsString(thirdLevelCell)); + thirdLevel.setUnitId(getCellValueAsString(fourthLevelCell)); + thirdLevel.setBuyPrice(getCellValueAsString(fifthLevelCell)); + // 检查是否所有三个级别都是空白 + if (firstLevel.isEmpty() || secondLevel.isEmpty() || thirdLevel == null) { + continue; // 跳过这一行 } -// - - - Map> secondLevelMap = entry1.getValue(); // 获取对应于第一层级键的内层Map - - // 遍历内层Map - for (Map.Entry> entry2 : secondLevelMap.entrySet()) { - String secondLevel = entry2.getKey(); // 获取第二层级的键 - String parentIdTwo = excelMapper.selectPaName(secondLevel); - - //产生返回值并且进行判断是否是pa_name列已经有的,并且返回对应的pa_id - if(parentIdTwo == null || parentIdTwo == ""){ - MaPartType maPartType = new MaPartType(); - maPartType.setPaName(secondLevel); - maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); - maPartType.setParentId(id); - excelMapper.insertPaTwoName(maPartType);//第二层在数据库中查询不到则插入数据,则插入时候设置关联关系 - id = maPartType.getPaId(); + // 检查是否已经存在相同的组合 + boolean isDuplicate = false; + for (String key : level3Relation.keySet()) { + Map> secondLevelMap = level3Relation.get(key); + for (String key2 : secondLevelMap.keySet()) { + List thirdLevelList = secondLevelMap.get(key2); + if (key.equals(firstLevel) && key2.equals(secondLevel) && thirdLevelList.contains(thirdLevel)) { + isDuplicate = true; + break; + } } + if (isDuplicate) break; + } - - - //从数据库中查询 - String thirdLevel = entry2.getValue().get(0); // 获取对应于第二层级键的值,即第三层级的列表 - - - String parentThreeId = excelMapper.selectPaName(thirdLevel); - if(parentThreeId == null || parentThreeId == ""){ - MaPartType maPartType = new MaPartType(); - maPartType.setPaName(thirdLevel); - maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); - maPartType.setUnitId(fourthLevel); - maPartType.setBuyPrice(fifthLevel); - maPartType.setParentId(id); - excelMapper.insertPaThreeName(maPartType);//第二层在数据库中查询不到则插入数据,则插入时候设置关联关系 - } + if (!isDuplicate) { + // 如果不是重复项,则添加到映射中 + Map> secondLevelMap = level3Relation.computeIfAbsent(firstLevel, k -> new HashMap<>()); + List thirdLevelList = secondLevelMap.computeIfAbsent(secondLevel, k -> new ArrayList<>()); + thirdLevelList.add(thirdLevel); } } + printLevel3Relation(level3Relation); return level3Relation; } catch (IOException e) { @@ -160,5 +132,83 @@ public class ExcelServiceImpl implements ExcelService { } + private void printLevel3Relation(Map>> level3Relation) { + for (Map.Entry>> firstLevel : level3Relation.entrySet()) { + boolean outExist = true; + System.out.println("level_1: " + firstLevel.getKey()); + //TODO, sql查询:是否有此名字 + parentId=0, select * from ma_part_type where name=? and parent_id=0; + MaPartType maPartType_level1 = excelMapper.selectMa(firstLevel.getKey(),0); + //TODO, 以上返回 maPartType_level1 + if (Objects.nonNull(maPartType_level1)) { + loopInner(firstLevel, outExist,maPartType_level1.getPaId()); + } else { + //TODO, insert firstLevel, get id + MaPartType maPartType = new MaPartType(); + maPartType.setPaName(firstLevel.getKey()); + maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + maPartType.setParentId(0L); + maPartType.setLevel("1"); + excelMapper.insertPaName(maPartType);//如果第一层在数据库中查询不到则插入数据,并且读取到parent_id + outExist = outExist && false; + loopInner(firstLevel, outExist, maPartType.getPaId()); + } + } + } + + private void loopInner(Map.Entry>> firstLevel, boolean outExist, long firstLevelId) { + for (Map.Entry> secondLevel : firstLevel.getValue().entrySet()) { + System.out.println("\tlevel_2: " + secondLevel.getKey()); + //TODO, sql查询:是否有此名字 + parentId=firstLevelId, select * from ma_part_type where name=? and parent_id = firstLevelId; + MaPartType maPartType_level2 = excelMapper.selectMa(firstLevel.getKey(),firstLevelId); + //TODO, 以上返回 maPartType_level2 + if (Objects.nonNull(maPartType_level2)) { + looplevel3(secondLevel, outExist, maPartType_level2.getPaId()); + } else { + //TODO, insert firstLevel, get id + if (!outExist) { + MaPartType maPartType = new MaPartType(); + maPartType.setPaName(secondLevel.getKey()); + maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + maPartType.setParentId(firstLevelId); + maPartType.setLevel("2"); + excelMapper.insertPaName(maPartType);//如果第一层在数据库中查询不到则插入数据,并且读取到parent_id + outExist = outExist && false; + looplevel3(secondLevel, outExist, maPartType.getPaId()); + } + } + } + } + + private void looplevel3(Map.Entry> secondLevel, boolean outExist, long secondLevelId) { + for (MapType thirdLevel : secondLevel.getValue()) { + System.out.println("\t\tlevel_3: " + thirdLevel); + //TODO, sql查询:是否有此名字 + parentId=secondLevelId, select * from ma_part_type where name=? and parent_id = secondLevelId; + MaPartType maPartType_level3 = excelMapper.selectMa(thirdLevel.getPaName(),secondLevelId); + //TODO, 以上返回 maPartType_level3 + if (Objects.nonNull(maPartType_level3)) { + if (!outExist) { + //TODO insert + MaPartType maPartType = new MaPartType(); + maPartType.setPaName(thirdLevel.getPaName()); + maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + maPartType.setUnitId(thirdLevel.getUnitId()); + maPartType.setBuyPrice(thirdLevel.getBuyPrice()); + maPartType.setParentId(secondLevelId); + maPartType.setLevel("3"); + excelMapper.insertPaName(maPartType);//如果第一层在数据库中查询不到则插入数据,并且读取到parent_id + } + } else { + //TODO insert + MaPartType maPartType = new MaPartType(); + maPartType.setPaName(thirdLevel.getPaName()); + maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + maPartType.setUnitId(thirdLevel.getUnitId()); + maPartType.setBuyPrice(thirdLevel.getBuyPrice()); + maPartType.setParentId(secondLevelId); + maPartType.setLevel("3"); + excelMapper.insertPaName(maPartType);//如果第一层在数据库中查询不到则插入数据,并且读取到parent_id + } + } + } } diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml index fea753c1..8928f754 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackReceiveMapper.xml @@ -542,8 +542,8 @@ ) - insert into slt_agreement_info (agreement_id,type_id,ma_id,num,start_time,status,lease_id,lease_price,buy_price,is_slt,company_id) - values (#{info.agreementId},#{info.typeId},#{info.maId},#{many},#{info.startTime},#{info.status},#{info.leaseId},#{info.leasePrice},#{info.buyPrice},'0',#{info.companyId}); + insert into slt_agreement_info (agreement_id,type_id,ma_id,num,start_time,status,lease_id,lease_price,buy_price,is_slt,company_id,lease_type) + values (#{info.agreementId},#{info.typeId},#{info.maId},#{many},#{info.startTime},#{info.status},#{info.leaseId},#{info.leasePrice},#{info.buyPrice},'0',#{info.companyId},#{info.leaseType}); @@ -664,7 +664,8 @@ mt.type_name as typeCode, mt.unit_name as unitName, mt2.type_name AS typeName, - bad.audit_num as preNum, + bad.pre_num as preNum, + bad.audit_num as auditNum, bad.status as status, IFNULL(bad.audit_num,0)-IFNULL(aa.back_num,0) as num, mt.manage_type as manageType, @@ -860,6 +861,7 @@ end_time AS endTime, status AS status, lease_id AS leaseId, + lease_type AS leaseType, back_id AS backId, lease_price AS leasePrice, buy_price AS buyPrice, diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/ExcelMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/ExcelMapper.xml index 645b3d3b..767a2560 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/ExcelMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/ExcelMapper.xml @@ -3,27 +3,64 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + insert into ma_part_type - (pa_name, status,level,del_flag,create_by,create_time,year) + (pa_name, parent_id, status,level,del_flag,unit_id,buy_price,create_by,create_time,year) VALUES - (#{paName}, 0 , 1, 0, #{createBy}, now(),year(now())) - - - insert into ma_part_type - (pa_name, parent_id, status,level,del_flag,create_by,create_time,year) - VALUES - (#{paName}, #{parentId},0 , 2, 0, #{createBy}, now(),year(now())) - - - insert into ma_part_type - (pa_name, parent_id, status,level,del_flag,unit_id,buy_price,create_by,create_time,year) - VALUES - (#{paName}, #{parentId},0 , 3, 0, #{unitId}, #{buyPrice}, #{createBy}, now(),year(now())) + (#{paName}, #{parentId},0 , #{level}, 0, #{unitId}, #{buyPrice}, #{createBy}, now(),year(now())) - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml index 300a6bbb..a8e39728 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml @@ -74,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update ma_part_type set del_flag = '2' where pa_id = #{paId} + delete from ma_part_type where pa_id = #{paId}