| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.TechnicalSpecificationMapper; |
| | | import com.whyc.pojo.TechnicalSpecification; |
| | | import com.whyc.pojo.TechnicalSpecificationLockLog; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.DateUtil; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | private ProductHistoryService productHistoryService; |
| | | |
| | | @Autowired |
| | | private DocLogService logService; |
| | | private TechnicalSpecificationLockLogService lockLogService; |
| | | |
| | | public Response<Object> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException { |
| | | TechnicalSpecification specification = new TechnicalSpecification(); |
| | |
| | | return new Response().set(1,false,"文件名,文件类型,版本,负责人,归档日期,物料编码,规格型号 中至少有一项为空"); |
| | | } |
| | | |
| | | //校验规格书文件名称=说明书中的文件名称+版本号 |
| | | //校验规格书附件名称=说明书中的文件名称+版本号 |
| | | String fileNameUnion = specification.getFileName() + specification.getVersion(); |
| | | String excelName = file2Name.substring(0,file2Name.lastIndexOf(".")); |
| | | if(!(fileNameUnion).equals(excelName)){ |
| | | return new Response().set(1,false,"技术规格书excel的命名与excel内的文件名+版本号称不一致"); |
| | | String attachmentName = file1Name.substring(0,file1Name.lastIndexOf(".")); |
| | | if(!(fileNameUnion).equals(attachmentName)){ |
| | | return new Response().set(1,false,"附件的命名与技术规格书excel内的文件名+版本号称不一致"); |
| | | } |
| | | //校验负责人是否存在 |
| | | boolean checkExists = userService.checkExists(specification.getOwner()); |
| | |
| | | specification.setFileUrl(specificationHttpUrl+File.separator+file1Name); |
| | | specification.setExcelUrl(specificationHttpUrl+File.separator+file2Name); |
| | | specification.setCreateTime(date); |
| | | specification.setUploadUser(ActionUtil.getUser().getName()); |
| | | //锁定-负责人才能解锁 |
| | | specification.setLockFlag(1); |
| | | specification.setLockReason("系统默认锁定,新版本技术规则书上传"); |
| | | mapper.insert(specification); |
| | | //锁定适用机型的生效版本 |
| | | lockOtherByAppliedProduct(specification); |
| | | //锁定日志 |
| | | TechnicalSpecificationLockLog lockLog = new TechnicalSpecificationLockLog(); |
| | | lockLog.setUserName("系统"); |
| | | lockLog.setTechnicalSpecificationId(specification.getId()); |
| | | lockLog.setReason("系统默认锁定,新版本技术规则书上传"); |
| | | lockLog.setCreateTime(date); |
| | | lockLog.setStatus(0); |
| | | lockLogService.add(lockLog); |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | | |
| | | private void lockOtherByAppliedProduct(TechnicalSpecification specification) { |
| | | //先查询 |
| | | QueryWrapper<TechnicalSpecification> query = Wrappers.query(); |
| | | query.eq("apply_material_code",specification.getApplyMaterialCode()); |
| | | query.eq("apply_custom_code", specification.getApplyCustomCode()); |
| | | query.eq("lock_flag",0); |
| | | query.last(" limit 1"); |
| | | TechnicalSpecification specificationToBeLocked = mapper.selectOne(query); |
| | | if(specificationToBeLocked !=null){ //存在生效的,需要被锁定 |
| | | specificationToBeLocked.setLockFlag(1); |
| | | mapper.updateById(specificationToBeLocked); |
| | | //锁定日志 |
| | | TechnicalSpecificationLockLog lockLog = new TechnicalSpecificationLockLog(); |
| | | lockLog.setUserName("系统"); |
| | | lockLog.setTechnicalSpecificationId(specificationToBeLocked.getId()); |
| | | lockLog.setReason("系统默认锁定,新版本技术规则书上传,旧版本锁定"); |
| | | lockLog.setCreateTime(new Date()); |
| | | lockLog.setStatus(0); |
| | | lockLogService.add(lockLog); |
| | | } |
| | | |
| | | |
| | | UpdateWrapper<TechnicalSpecification> update = Wrappers.update(); |
| | | update.set("lock_flag",1); |
| | | update.set("lock_reason","系统默认锁定,新版本技术规则书上传,旧版本锁定"); |
| | | //update.set("lock_reason","系统默认锁定,新版本技术规则书上传,旧版本锁定"); |
| | | update.eq("apply_material_code",specification.getApplyMaterialCode()); |
| | | update.eq("apply_custom_code", specification.getApplyCustomCode()); |
| | | |
| | | update.eq("lock_flag",0); |
| | | update.last(" limit 1"); |
| | | |
| | | mapper.update(null,update); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response updateLock(int id, int lockFlag) { |
| | | public Response updateLock(int id, int lockFlag, String reason) { |
| | | Date date = new Date(); |
| | | String userName = ActionUtil.getUser().getName(); |
| | | TechnicalSpecification specificationInDB = get(id); |
| | | if(!userName.equals(specificationInDB.getOwner())){ |
| | |
| | | }else{ |
| | | //锁定目前生效版本 |
| | | availableVersion.setLockFlag(1); |
| | | availableVersion.setLockReason("新版本解锁,此旧版本锁定"); |
| | | mapper.updateById(availableVersion); |
| | | //锁定日志 |
| | | TechnicalSpecificationLockLog lockLog = new TechnicalSpecificationLockLog(); |
| | | lockLog.setUserName(userName); |
| | | lockLog.setTechnicalSpecificationId(id); |
| | | lockLog.setReason("新版本解锁,此旧版本锁定"); |
| | | lockLog.setCreateTime(date); |
| | | lockLog.setStatus(0); |
| | | lockLogService.add(lockLog); |
| | | } |
| | | } |
| | | } |
| | | specificationInDB.setLockFlag(lockFlag); |
| | | mapper.updateById(specificationInDB); |
| | | |
| | | //锁定/解锁日志 |
| | | TechnicalSpecificationLockLog lockLog = new TechnicalSpecificationLockLog(); |
| | | lockLog.setUserName(userName); |
| | | lockLog.setTechnicalSpecificationId(id); |
| | | lockLog.setReason(reason); |
| | | lockLog.setCreateTime(date); |
| | | lockLog.setStatus(lockFlag==1?0:1); |
| | | lockLogService.add(lockLog); |
| | | return new Response().set(1, true, "更新完成"); |
| | | } |
| | | |
| | |
| | | query.eq("lock_flag",lockFlag); |
| | | } |
| | | List<TechnicalSpecification> list=mapper.selectList(query); |
| | | //标识每条记录适用机型可用的版本的负责人是不是这条记录的负责人 |
| | | if(list!=null&&list.size()>0){ |
| | | for (TechnicalSpecification t:list) { |
| | | TechnicalSpecification enableTe=getEnableVersion(t); |
| | | if(enableTe!=null){ |
| | | if(enableTe.getOwner().equals(t.getOwner())){ |
| | | t.setFlag(1); |
| | | }else{ |
| | | t.setFlag(0); |
| | | } |
| | | }else { |
| | | t.setFlag(1); |
| | | } |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询技术规格书"); |
| | | } |
| | | //查询每条记录适用机型可用的版本 |
| | | public TechnicalSpecification getEnableVersion(TechnicalSpecification t){ |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("apply_material_code",t.getApplyMaterialCode()); |
| | | wrapper.eq("apply_model",t.getApplyModel()); |
| | | wrapper.eq("apply_custom_code",t.getApplyCustomCode()); |
| | | wrapper.last("limit 1"); |
| | | TechnicalSpecification enableTe=mapper.selectOne(wrapper); |
| | | return enableTe; |
| | | } |
| | | |
| | | //查询指定技术规格书的所有版本 |
| | | public Response getVersionByInfo(String applyMaterialCode, String applyModel, String applyCustomCode) { |
| | | QueryWrapper<TechnicalSpecification> query = Wrappers.query(); |
| | |
| | | query.eq("apply_custom_code",applyCustomCode); |
| | | } |
| | | List<TechnicalSpecification> list=mapper.selectList(query); |
| | | //标识每条记录适用机型可用的版本的负责人是不是这条记录的负责人 |
| | | if(list!=null&&list.size()>0){ |
| | | for (TechnicalSpecification t:list) { |
| | | TechnicalSpecification enableTe=getEnableVersion(t); |
| | | if(enableTe!=null){ |
| | | if(enableTe.getOwner().equals(t.getOwner())){ |
| | | t.setFlag(1); |
| | | }else{ |
| | | t.setFlag(0); |
| | | } |
| | | }else { |
| | | t.setFlag(1); |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,list!=null,list,"查询指定技术规格书的所有版本"); |
| | | } |
| | | } |