| | |
| | | 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 io.swagger.models.auth.In; |
| | | 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; |
| | |
| | | private DocUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private ProductBomApprovingService approvingService; |
| | | |
| | | @Autowired |
| | | private ProductBomService bomService; |
| | | private ComponentProductApprovingService cpApprovingService; |
| | | |
| | | @Autowired |
| | | private ComponentApprovingService cApprovingService; |
| | | |
| | | @Autowired |
| | | private ComponentService cService; |
| | | |
| | | @Autowired |
| | | private ProductBomService pbService; |
| | | |
| | | @Autowired |
| | | private ComponentProductHistoryService cphService; |
| | | |
| | | @Transactional |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | }else{ |
| | | return false; |
| | | } |
| | | //产品bom/图纸图片提交 |
| | | |
| | | //查询部件最新的版本号 |
| | | Integer version = bomService.getProduct(bomList.get(0).getParentModel()).getVersion(); |
| | | if(version==null){ |
| | | version = 0; |
| | | //散装件-产品审批提交 |
| | | if(addedList!=null && addedList.size()!=0){ |
| | | addedList.forEach(item->{ |
| | | item.setMainId(main.getId()); |
| | | item.setLinkType(1); |
| | | }); |
| | | approvingList.addAll(addedList); |
| | | } |
| | | Integer finalVersion = version; |
| | | bomList.forEach(bom->{ |
| | | bom.setMainId(main.getId()); |
| | | bom.setVersion(finalVersion+1); |
| | | }); |
| | | approvingService.insert(bomList); |
| | | 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, "重复提交:现有散装件及正在进行审批的散装件中,存在当前提交上传的散装件"); |
| | | } else { |
| | | response.set(22, existCAList, "重复提交:正在进行审批的散装件中,存在当前提交上传的散装件"); |
| | | } |
| | | return response; |
| | | } else { |
| | | if (existComponentSize != 0) { |
| | | return response.setII(23, null, existComponentList, "重复提交:现有散装件中,存在当前提交上传的散装件"); |
| | | } |
| | | } |
| | | }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,"拒绝本次删除申请,当前散装件正在进行删除审批"); |
| | | } |
| | | if(cphLatestExistList!=null && cphLatestExistList.size()!=0){ |
| | | if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){ |
| | | return response.setII(32,cpaLatestExistList,cphLatestExistList,"拒绝本次删除申请,当前散装已经关联产品及在产品关联审批"); |
| | | }else{ |
| | | return response.setII(33,null,cphLatestExistList,"拒绝本次删除申请,当前散装件在产品关联审批"); |
| | | } |
| | | }else{ |
| | | if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){ |
| | | return response.set(34,cpaLatestExistList,"拒绝本次删除申请,当前散装件已经关联产品"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | 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); |
| | | } |
| | | //散装件-审批提交 |
| | | 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) { |
| | |
| | | main.setId(id); |
| | | main.setStatus(status); |
| | | main.setEndReason(endReason); |
| | | main.setEndTime(new Date()); |
| | | mainMapper.updateById(main); |
| | | } |
| | | |
| | |
| | | } |
| | | 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{ //散装件-产品 |
| | | 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); |
| | | 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); |
| | | 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); |
| | |
| | | //自己的工单 |
| | | if(!user.getRoleId().equals("1003")){ |
| | | QueryWrapper<WorksheetMain> query = Wrappers.query(); |
| | | query.eq("create_user_id",user.getId()).in("status",5); |
| | | query.eq("create_user_id",user.getId()).in("status",5).orderByDesc("id"); |
| | | worksheetMainList = mainMapper.selectList(query); |
| | | |
| | | }else{ |
| | |
| | | |
| | | public Response<PageInfo<WorksheetMain>> getHandlingListPage(DocUser user, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<WorksheetMain> worksheetMainList = linkService.getInfoList2(user.getId(),0); |
| | | 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.getInfoList2(user.getId(),1); |
| | | 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); |
| | | |
| | | } |
| | | |
| | | } |