From 6eda8b2ff2b6748376670e84a14a8656cc1094c6 Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期一, 15 八月 2022 14:33:00 +0800 Subject: [PATCH] 物料编码字典新建及数据导入 --- src/main/java/com/whyc/service/WorksheetMainService.java | 430 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 396 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/whyc/service/WorksheetMainService.java b/src/main/java/com/whyc/service/WorksheetMainService.java index 989bd7b..08783df 100644 --- a/src/main/java/com/whyc/service/WorksheetMainService.java +++ b/src/main/java/com/whyc/service/WorksheetMainService.java @@ -2,19 +2,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.whyc.config.EnumWorksheetType; +import com.whyc.dto.Response; import com.whyc.dto.WorksheetMainDTO; import com.whyc.mapper.DocUserMapper; import com.whyc.mapper.WorksheetLinkMapper; import com.whyc.mapper.WorksheetMainMapper; -import com.whyc.pojo.DocUser; -import com.whyc.pojo.ProductBomApproving; -import com.whyc.pojo.WorksheetLink; -import com.whyc.pojo.WorksheetMain; +import com.whyc.pojo.*; +import io.swagger.annotations.ApiModelProperty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sun.print.PSPrinterJob; import javax.annotation.Resource; import java.util.*; @@ -37,19 +38,124 @@ private DocUserMapper userMapper; @Autowired + @Lazy private ProductBomApprovingService approvingService; + @Autowired + private ComponentProductApprovingService cpApprovingService; + + @Autowired + private ComponentApprovingService cApprovingService; + + @Autowired + private ComponentService cService; + + @Autowired + private ProductBomService pbService; + + @Autowired + private ComponentProductHistoryService cphService; + @Transactional - public boolean submit(WorksheetMainDTO mainDTO, DocUser user) { - WorksheetMain main = mainDTO.getMain(); - List<ProductBomApproving> bomList = mainDTO.getBomList(); + public boolean submit(WorksheetMain main, DocUser user) { + main.setType(1); + List<ProductBomApproving> bomList = main.getApprovingBomList(); + int rejectVersion=-1; //鎻愪氦涓昏〃 main.setCreateUserId(user.getId()); //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾� if(user.getRoleId().equals("1001")){ - main.setLevel(2); - main.setStatus(1); + if(main.getId()==null) { + main.setLevel(2); + main.setStatus(1); + mainMapper.insert(main); + }else { + rejectVersion = approvingService.getRejectVersion(main.getId()); + } + //鎻愪氦瀛愯〃 + WorksheetLink link =new WorksheetLink(); + link.setMainId(main.getId()); + link.setParentId(0); + link.setDealUserId(main.getNextUser()); + link.setDealType(1); + link.setDealDesc(main.getDealDesc()); + link.setLinkStatus(0); + link.setEnableArchive(0); + link.setRejectVersion(rejectVersion+1); + linkMapper.insert(link); + } + else if(user.getRoleId().equals("1002")){ + if(main.getId()==null) { + main.setLevel(1); + main.setStatus(2); + mainMapper.insert(main); + }else { + rejectVersion = approvingService.getRejectVersion(main.getId()); + } + //鎻愪氦瀛愯〃 + WorksheetLink link =new WorksheetLink(); + link.setMainId(main.getId()); + link.setParentId(0); + link.setDealUserId(main.getNextUser()); + link.setDealType(2); + link.setDealDesc(main.getDealDesc()); + link.setLinkStatus(0); + link.setEnableArchive(1); + link.setRejectVersion(rejectVersion+1); + linkMapper.insert(link); + } + else if(user.getRoleId().equals("1003")){ + main.setLevel(0); + main.setStatus(5); mainMapper.insert(main); + }else{ + return false; + } + //浜у搧bom/鍥剧焊鍥剧墖鎻愪氦 + //鏌ヨ褰撳墠椹冲洖鐗堟湰 + int nextRejectVersion = rejectVersion+1; + bomList.forEach(bom->{ + bom.setMainId(main.getId()); + bom.setUpUserId(user.getId()); + bom.setRejectVersion(nextRejectVersion); + bom.setCreateDate(new Date()); + if(bom.getDwgUrl()==null){ + bom.setDwgUrl(""); + }else { + bom.setDwgUrl(bom.getDwgUrl()); + } + if(bom.getFileUrl()==null){ + bom.setFileUrl(""); + }else { + bom.setFileUrl(bom.getFileUrl()); + } + if(bom.getPictureUrl()==null){ + bom.setPictureUrl(""); + }else{ + bom.setPictureUrl(bom.getPictureUrl()); + } + }); + approvingService.insert(bomList); + return true; + } + + public boolean componentProductSubmit(WorksheetMainDTO mainDTO, DocUser user) { + List<ComponentProductApproving> approvingList = new LinkedList<>(); + WorksheetMain main = mainDTO.getMain(); + List<ComponentProductApproving> addedList = mainDTO.getAddedList(); + List<ComponentProductApproving> replacedList = mainDTO.getReplacedList(); + List<ComponentProductApproving> removedList = mainDTO.getRemovedList(); + + main.setType(EnumWorksheetType.ComponentProduct.getType()); + //鎻愪氦涓昏〃 + main.setCreateUserId(user.getId()); + //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾� + if(user.getRoleId().equals("1001")){ + if(main.getId()==null) { + main.setLevel(2); + main.setStatus(1); + mainMapper.insert(main); + } //鎻愪氦瀛愯〃 WorksheetLink link =new WorksheetLink(); link.setMainId(main.getId()); @@ -62,9 +168,11 @@ linkMapper.insert(link); } else if(user.getRoleId().equals("1002")){ - main.setLevel(1); - main.setStatus(2); - mainMapper.insert(main); + if(main.getId()==null) { + main.setLevel(1); + main.setStatus(2); + mainMapper.insert(main); + } //鎻愪氦瀛愯〃 WorksheetLink link =new WorksheetLink(); link.setMainId(main.getId()); @@ -83,10 +191,161 @@ }else{ return false; } - //浜у搧bom/鍥剧焊鍥剧墖鎻愪氦 - bomList.forEach(bom->bom.setMainId(main.getId())); - approvingService.insert(bomList); + //鏁h浠�-浜у搧瀹℃壒鎻愪氦 + if(addedList!=null && addedList.size()!=0){ + addedList.forEach(item->{ + item.setMainId(main.getId()); + item.setLinkType(1); + }); + approvingList.addAll(addedList); + } + if(replacedList!=null && replacedList.size()!=0){ + replacedList.forEach(item->{ + item.setMainId(main.getId()); + item.setLinkType(2); + }); + approvingList.addAll(replacedList); + } + if(removedList!=null && removedList.size()!=0){ + removedList.forEach(item->{ + item.setMainId(main.getId()); + item.setLinkType(-1); + }); + approvingList.addAll(removedList); + } + cpApprovingService.insert(approvingList); return true; + } + + public Response componentSubmit(WorksheetMain main, DocUser user) { + Response<Object> response = new Response<>(); + List<ComponentApproving> cApprovingList = main.getCApprovingList(); + //鍒ゆ柇鏄柊澧炶繕鏄垹闄� + boolean isAdded = cApprovingList.get(0).getSubName()!=null; + if(isAdded) { //鏂板 + //鏌ヨ鏄惁鏈� 宸茬敓鏁堟垨鑰呭凡鎻愪氦瀹℃壒鐨� 鐩稿悓鐨勬暎瑁呬欢 + List<Component> existComponentList = new LinkedList<>(); + List<ComponentApproving> existCAList = new LinkedList<>(); + + List<Component> componentList = cService.getList(); + List<ComponentApproving> cAList = cApprovingService.getListByStatus(1); + for (int i = 0; i < cApprovingList.size(); i++) { + ComponentApproving componentApproving = cApprovingList.get(i); + for (int j = 0; j < componentList.size(); j++) { + if (componentApproving.getSubCode().equals(componentList.get(j).getSubCode()) + && componentApproving.getSubName().equals(componentList.get(j).getSubName()) + && componentApproving.getSubModel().equals(componentList.get(j).getSubModel()) + ) { + existComponentList.add(componentList.get(j)); + } + } + + for (int j = 0; j < cAList.size(); j++) { + if (componentApproving.getSubCode().equals(cAList.get(j).getSubCode()) + && componentApproving.getSubName().equals(cAList.get(j).getSubName()) + && componentApproving.getSubModel().equals(cAList.get(j).getSubModel()) + ) { + existCAList.add(cAList.get(j)); + } + } + } + + int existCASize = existCAList.size(); + int existComponentSize = existComponentList.size(); + if (existCASize != 0) { + if (existComponentSize != 0) { + response.setII(21, existCAList, existComponentList, "閲嶅鎻愪氦:鐜版湁鏁h浠跺強姝e湪杩涜瀹℃壒鐨勬暎瑁呬欢涓�,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勬暎瑁呬欢"); + } else { + response.set(22, existCAList, "閲嶅鎻愪氦:姝e湪杩涜瀹℃壒鐨勬暎瑁呬欢涓�,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勬暎瑁呬欢"); + } + return response; + } else { + if (existComponentSize != 0) { + return response.setII(23, null, existComponentList, "閲嶅鎻愪氦:鐜版湁鏁h浠朵腑,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勬暎瑁呬欢"); + } + } + }else{ //鍒犻櫎 + //鍒ゆ柇鏄惁鍦ㄦ暎瑁呬欢瀹℃壒鍒犻櫎涓�,鏄惁瀛樺湪浜у搧鍏宠仈鍙婂叧鑱斿鎵� + ComponentApproving deleteApproving = new ComponentApproving(); + List<ComponentProductHistory> existComponentProducts = new LinkedList<>(); + List<ComponentProductApproving> existComponentProductApprovingList = new LinkedList<>(); + deleteApproving = cApprovingService.getListByComponentId(cApprovingList.get(0).getComponentId()); + + //鏌ョ湅浜у搧鍏宠仈 + List<ComponentProductHistory> cphLatestExistList = cphService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId()); + //鏌ョ湅浜у搧鍏宠仈瀹℃壒 + List<ComponentProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId()); + + if(deleteApproving!=null){ + return response.set(31,deleteApproving,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鏁h浠舵鍦ㄨ繘琛屽垹闄ゅ鎵�"); + } + if(cphLatestExistList!=null && cphLatestExistList.size()!=0){ + if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){ + return response.setII(32,cpaLatestExistList,cphLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鏁h宸茬粡鍏宠仈浜у搧鍙婂湪浜у搧鍏宠仈瀹℃壒"); + }else{ + return response.setII(33,null,cphLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鏁h浠跺湪浜у搧鍏宠仈瀹℃壒"); + } + }else{ + if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){ + return response.set(34,cpaLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鏁h浠跺凡缁忓叧鑱斾骇鍝�"); + } + } + + } + main.setType(EnumWorksheetType.Component.getType()); + //鎻愪氦涓昏〃 + main.setCreateUserId(user.getId()); + //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾� + if(user.getRoleId().equals("1001")){ + if(main.getId()==null) { + main.setLevel(2); + main.setStatus(1); + mainMapper.insert(main); + } + //鎻愪氦瀛愯〃 + WorksheetLink link =new WorksheetLink(); + link.setMainId(main.getId()); + link.setParentId(0); + link.setDealUserId(main.getNextUser()); + link.setDealType(1); + link.setDealDesc(main.getDealDesc()); + link.setLinkStatus(0); + link.setEnableArchive(0); + linkMapper.insert(link); + } + else if(user.getRoleId().equals("1002")){ + if(main.getId()==null) { + main.setLevel(1); + main.setStatus(2); + mainMapper.insert(main); + } + //鎻愪氦瀛愯〃 + WorksheetLink link =new WorksheetLink(); + link.setMainId(main.getId()); + link.setParentId(0); + link.setDealUserId(main.getNextUser()); + link.setDealType(2); + link.setDealDesc(main.getDealDesc()); + link.setLinkStatus(0); + link.setEnableArchive(1); + linkMapper.insert(link); + } + else if(user.getRoleId().equals("1003")){ + main.setLevel(0); + main.setStatus(5); + mainMapper.insert(main); + }else{ + return response.set(3); + } + //鏁h浠�-瀹℃壒鎻愪氦 + cApprovingList.forEach(cApproving->{ + cApproving.setCreateDate(new Date()); + cApproving.setMainId(main.getId()); + cApproving.setStatus(1); + }); + + cApprovingService.insert(cApprovingList); + return response.set(1); } public WorksheetMain getInfoById(Integer id) { @@ -105,20 +364,24 @@ main.setId(id); main.setStatus(status); main.setEndReason(endReason); + main.setEndTime(new Date()); mainMapper.updateById(main); } /** * 鐢ㄦ埛瀵瑰簲鐨勫伐浣滃彴鏁版嵁鍒嗙被 * @param user - * */ - public Map<String, List<WorksheetMain>> getList(DocUser user) { - Map<String,List<WorksheetMain>> map = new HashMap<>(); + * @return*/ + public Map<String, Integer> getStatusStatistic(DocUser user) { + Map<String,Integer> map = new HashMap<>(); switch (user.getRoleId()){ //鏅�氬憳宸� case "1001": { //鏈鐞�(瀹℃壒涓�)/宸查┏鍥�/宸插鎵� + map.put("rejected",0); + map.put("approving",0); + map.put("approved",0); QueryWrapper<WorksheetMain> query = Wrappers.query(); query.eq("create_user_id",user.getId()); List<WorksheetMain> worksheetMainList = mainMapper.selectList(query); @@ -126,20 +389,19 @@ groupingList.forEach((status,mainList)->{ switch (status){ case 0:{ - map.put("rejected",mainList); + map.put("rejected",mainList.size()); }break; case 1: case 2:{ - List<WorksheetMain> addedMainList = map.get("approving"); - if(addedMainList ==null){ - map.put("approving",mainList); + Integer addedMainCount= map.get("approving"); + if(addedMainCount ==0){ + map.put("approving",mainList.size()); }else{ - addedMainList.addAll(mainList); - map.put("approving",addedMainList); + map.put("approving",addedMainCount+mainList.size()); } }break; case 5:{ - map.put("approved",mainList); + map.put("approved",mainList.size()); }break; } }); @@ -150,6 +412,12 @@ { //寰呭鐞�/宸插鐞�/灞炰簬鑷繁-瀹℃壒涓�/宸查┏鍥�/宸插鎵� //灞炰簬鑷繁-瀹℃壒涓�/宸查┏鍥�/宸插鎵� + map.put("rejected",0); + map.put("approving",0); + map.put("approved",0); + map.put("handling",0); + map.put("handled",0); + QueryWrapper<WorksheetMain> query = Wrappers.query(); query.eq("create_user_id",user.getId()); List<WorksheetMain> worksheetMainList = mainMapper.selectList(query); @@ -157,13 +425,13 @@ groupingList.forEach((status,mainList)->{ switch (status){ case 0:{ - map.put("rejected",mainList); + map.put("rejected",mainList.size()); }break; case 2:{ - map.put("approving",mainList); + map.put("approving",mainList.size()); }break; case 5:{ - map.put("approved",mainList); + map.put("approved",mainList.size()); }break; } }); @@ -175,11 +443,16 @@ linkList.forEach(link -> {mainList.add(link.getMain());}); switch (linkStatus){ case 0:{ - map.put("handling",mainList); + map.put("handling",mainList.size()); }break; case 1: case 2:{ - map.put("handled",mainList); + Integer addedMainCount= map.get("handled"); + if(addedMainCount ==0){ + map.put("handled",mainList.size()); + }else{ + map.put("handled",addedMainCount+mainList.size()); + } }break; } }); @@ -189,6 +462,8 @@ case "1003": { //寰呭鐞�/宸插鎵� + map.put("handling",0); + map.put("approved",0); List<WorksheetLink> WorksheetLinkList = linkService.getInfoList(user.getId()); Map<Integer, List<WorksheetLink>> groupingLinkList = WorksheetLinkList.stream().collect(Collectors.groupingBy(WorksheetLink::getLinkStatus)); groupingLinkList.forEach((linkStatus,linkList)->{ @@ -196,22 +471,109 @@ linkList.forEach(link -> {mainList.add(link.getMain());}); switch (linkStatus){ case 0:{ - map.put("handling",mainList); + map.put("handling",mainList.size()); }break; case 1: case 2:{ - map.put("handled",mainList); + Integer addedMainCount= map.get("approved"); + if(addedMainCount ==0){ + map.put("approved",mainList.size()); + }else{ + map.put("approved",addedMainCount+mainList.size()); + } }break; } }); } break; } + //鏌ヨ鎴戠殑宸ュ崟鏁伴噺 + QueryWrapper<WorksheetMain> query = Wrappers.query(); + query.eq("create_user_id",user.getId()); + Integer count = mainMapper.selectCount(query); + map.put("my",count); return map; } public WorksheetMain getLinkList(int id) { - return mainMapper.getLinkList(id); + //鍒ゆ柇鏄摢绉嶇被鍨嬬殑瀹℃壒,杩斿洖涓嶅悓鐨勭被鍨� 鍏蜂綋鏁版嵁 + Integer type = getInfoById(id).getType(); + if(type.intValue() == EnumWorksheetType.ProductBom.getType()) { + return mainMapper.getLinkList(id); + }else if(type.intValue() == EnumWorksheetType.Component.getType()){ + return mainMapper.getLinkListWithComponents(id); + }else{ //鏁h浠�-浜у搧 + return mainMapper.getLinkListWithComponentProducts(id); + } } + + public Response<PageInfo<WorksheetMain>> getApprovingListPage(DocUser user, int pageNum, int pageSize) { + PageHelper.startPage(pageNum,pageSize); + QueryWrapper<WorksheetMain> query = Wrappers.query(); + query.eq("create_user_id",user.getId()).in("status",1,2).orderByDesc("id"); + List<WorksheetMain> worksheetMainList = mainMapper.selectList(query); + //鏌ヨ涓昏〃鐘舵�佸搴旂殑瀛愯〃 + worksheetMainList.forEach(main -> { + main.setApprovingUser(linkService.getApprovingUser(main.getId())); + }); + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo); + } + + public Response<PageInfo<WorksheetMain>> getRejectedListPage(DocUser user, int pageNum, int pageSize) { + PageHelper.startPage(pageNum,pageSize); + QueryWrapper<WorksheetMain> query = Wrappers.query(); + query.eq("create_user_id",user.getId()).in("status",0).orderByDesc("id"); + List<WorksheetMain> worksheetMainList = mainMapper.selectList(query); + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo); + } + + public Response<PageInfo<WorksheetMain>> getApprovedListPage(DocUser user, int pageNum, int pageSize) { + Response<PageInfo<WorksheetMain>> response = new Response<>(); + PageHelper.startPage(pageNum,pageSize); + List<WorksheetMain> worksheetMainList = null; + //鑷繁鐨勫伐鍗� + if(!user.getRoleId().equals("1003")){ + QueryWrapper<WorksheetMain> query = Wrappers.query(); + query.eq("create_user_id",user.getId()).in("status",5).orderByDesc("id"); + worksheetMainList = mainMapper.selectList(query); + + }else{ + //鎬荤粡鐞�,鑺傜偣瀹℃壒浜轰负鑷繁 + worksheetMainList = linkService.getInfoList2(user.getId(),1); + } + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return response.set(1,pageInfo); + } + + public Response<PageInfo<WorksheetMain>> getHandlingListPage(DocUser user, int pageNum, int pageSize) { + PageHelper.startPage(pageNum,pageSize); + List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),0); + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo); + } + + public Response<PageInfo<WorksheetMain>> getHandledListPage(DocUser user, int pageNum, int pageSize) { + PageHelper.startPage(pageNum,pageSize); + List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),1); + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo); + } + + public WorksheetMain getInfo(int id) { + return mainMapper.selectById(id); + } + + public Response<PageInfo<WorksheetMain>> getMyList(int pageNum, int pageSize, DocUser user) { + PageHelper.startPage(pageNum,pageSize); + QueryWrapper<WorksheetMain> query = Wrappers.query(); + query.eq("create_user_id",user.getId()).orderByDesc("id"); + List<WorksheetMain> worksheetMainList = mainMapper.selectList(query); + PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList); + return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo); + + } + } -- Gitblit v1.9.1