| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.MailDTO; |
| | | import com.whyc.dto.MaterialCheckDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.MaterialMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.Material; |
| | | import com.whyc.pojo.MaterialHistory; |
| | | import com.whyc.pojo.ProductBom; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.*; |
| | | import org.apache.commons.codec.binary.Base64; |
| | |
| | | |
| | | @Autowired |
| | | private MaterialHistoryService mhService; |
| | | |
| | | @Autowired |
| | | private AttachLockService attachLockService; |
| | | |
| | | @Autowired |
| | | private MailService mailService; |
| | | |
| | | @Autowired |
| | | private MailUserService mailUserService; |
| | | |
| | | //查询所有的散装件信息加设置了替换关系的子件信息 |
| | | /*public Response getAllMaterial(String category,String subCode,String subName,String subModel,int pageCurr,int pageSize) { |
| | |
| | | public Response getMaterialLimit(String subCode, String subName, String subModel, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<Material> list=mapper.getMaterialLimit(subCode,subName,subModel); |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | int flag=0; |
| | | // 返回是否存在附件 |
| | | if(list!=null&&list.size()>0){ |
| | | for (Material m:list) { |
| | | if(m.getFileUrl()!=null&&!m.getFileUrl().isEmpty()){ |
| | | File file = new File(fileDirName+File.separator+m.getFileUrl()); |
| | | if(!file.exists()) { |
| | | flag=0; |
| | | }else{ |
| | | String[] fileNames = file.list();//获取该文件夹下的所有文件以及目录的名字 |
| | | List attachFileList=new ArrayList(); |
| | | if(fileNames.length>0){ |
| | | flag=1; |
| | | for (int i=0;i<fileNames.length;i++){ |
| | | if(!fileNames[i].contains("-dwg.pdf")&&!fileNames[i].contains("-doc.pdf")) |
| | | attachFileList.add(fileNames[i]); |
| | | } |
| | | }else{ |
| | | flag=0; |
| | | } |
| | | m.setAttachFileList(attachFileList); |
| | | } |
| | | } |
| | | m.setHasAttachFlag(flag); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"查询所有物料(分页,模糊查询)"); |
| | | } |
| | |
| | | material.setFileUrl(null); |
| | | }); |
| | | mapper.insertBatchSomeColumn(materialList); |
| | | /*0120开头的物料上传后,系统自动发邮件对应人员:吴浚、陈卓、熊家杰、钱镜元、於奇 |
| | | 0108、0109开头的物料上传后,系统自动发邮件对应人员:喻艳、袁成、熊志平、叶胜蓝 */ |
| | | List<String> materialCodeList = materialList.stream().map(Material::getSubCode).collect(Collectors.toList()); |
| | | //从materialList中查找 subCode以0120开头的所有物料集合 |
| | | List<Material> materialCodeList0120 = materialList.stream().filter(material -> material.getSubCode().startsWith("0120")).collect(Collectors.toList()); |
| | | //从materialList中查找 subCode以0108或0109开头的所有物料集合 |
| | | List<Material> materialCodeList0809 = materialList.stream().filter(material -> material.getSubCode().startsWith("0108") || material.getSubCode().startsWith("0109")).collect(Collectors.toList()); |
| | | |
| | | //如果存在,则创建邮件对象 |
| | | if(materialCodeList0120.size()>0 || materialCodeList0809.size()>0) { |
| | | DocUser user = ActionUtil.getUser(); |
| | | MailDTO mailDTO = new MailDTO(); |
| | | String now = DateUtil.YYYY_MM_DD_HH_MM_SS.format(new Date()); |
| | | mailDTO.setTitle("【物料上传提醒】"); |
| | | if(materialCodeList0120.size()>0){ |
| | | String subCodeJoin = materialCodeList0120.stream().map(Material::getSubCode).collect(Collectors.joining(",")); |
| | | String subNameJoin = materialCodeList0120.stream().map(Material::getSubName).collect(Collectors.joining(",")); |
| | | String subModelJoin = materialCodeList0120.stream().map(Material::getSubModel).collect(Collectors.joining(",")); |
| | | |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(5); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName() + "在文档管理平台"+now+"上传了0120开头的物料,详细信息如下:\n物料编码:"+subCodeJoin+"\n物料名称:"+subNameJoin+"\n规格型号:"+subModelJoin); |
| | | mailService.sendMail(mailDTO); |
| | | } |
| | | if (materialCodeList0809.size()>0) { |
| | | String subCodeJoin = materialCodeList0809.stream().map(Material::getSubCode).collect(Collectors.joining(",")); |
| | | String subNameJoin = materialCodeList0809.stream().map(Material::getSubName).collect(Collectors.joining(",")); |
| | | String subModelJoin = materialCodeList0809.stream().map(Material::getSubModel).collect(Collectors.joining(",")); |
| | | |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(6); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName() + "在文档管理平台"+now+"上传了0108或0109开头的物料,详细信息如下:\n物料编码:"+subCodeJoin+"\n物料名称:"+subNameJoin+"\n规格型号:"+subModelJoin); |
| | | mailService.sendMail(mailDTO); |
| | | } |
| | | } |
| | | return new Response().set(1,true,"新增完成"); |
| | | } |
| | | |
| | |
| | | return mapper.getListByCodeAndModelList2(bomList); |
| | | } |
| | | |
| | | public Material getByCodeAndModel(String subCode, String subModel) { |
| | | public List<Material> getListByCodeAndModelList3(List<ProductBom> bomList) { |
| | | return mapper.getListByCodeAndModelList3(bomList); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param subCode 物料编码 |
| | | * @param subModel 物料型号 |
| | | * @param equalSubModel 是否等于物料型号,用于等于物料型号 或者 排除物料型号并且存在附件 |
| | | * @return |
| | | */ |
| | | public Material getByCodeAndModel(String subCode, String subModel, boolean equalSubModel) { |
| | | QueryWrapper<Material> query = Wrappers.query(); |
| | | query.eq("sub_code",subCode).eq("sub_model",subModel).last(" limit 1"); |
| | | query.eq("sub_code",subCode); |
| | | if(equalSubModel) { |
| | | query.eq("sub_model", subModel); |
| | | }else{ |
| | | query.ne("sub_model", subModel); |
| | | query.isNotNull("file_url"); |
| | | } |
| | | query.orderByDesc("id"); |
| | | query.last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | |
| | |
| | | File parentFile = new File(filePath); |
| | | String originalFilename = file.getOriginalFilename(); |
| | | File zipFile = new File(filePath+File.separator+ originalFilename); |
| | | if(!zipFile.exists()){ |
| | | /*if(!zipFile.exists()){ |
| | | zipFile.mkdirs(); |
| | | }*/ |
| | | if (!parentFile.exists()) { |
| | | parentFile.mkdirs(); |
| | | } |
| | | file.transferTo(zipFile); |
| | | //解压文件夹 |
| | |
| | | public Response addAttachment(List<MultipartFile> multipartFileList, Material material) throws IOException { |
| | | List<String> currentFileList = new LinkedList<>(); |
| | | List<String> uploadingFileList = new LinkedList<>(); |
| | | |
| | | String dirPathDB = "doc_file" + File.separator + "material" + File.separator + material.getId() + "-"+ material.getSubCode() + "-" + material.getSubModel(); |
| | | String dirPath = CommonUtil.getRootFile() + "material" + File.separator + material.getId() + "-"+ material.getSubCode() + "-" + material.getSubModel(); |
| | | String subCode = material.getSubCode(); |
| | | String subModel = material.getSubModel(); |
| | | subModel = MaterialSpecialCharUtil.transfer(subModel); |
| | | String dirPathDB = "doc_file" + File.separator + "material" + File.separator + material.getId() + "-"+ subCode + "-" + subModel; |
| | | String dirPath = CommonUtil.getRootFile() + "material" + File.separator + material.getId() + "-"+ subCode + "-" + subModel; |
| | | File dirFile = new File(dirPath); |
| | | |
| | | Date now = new Date(); |
| | | //long timestamp = now.getTime(); |
| | | String formattedTimestamp = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(now); |
| | | String formattedNow = DateUtil.YYYY_MM_DD_HH_MM_SS.format(now); |
| | | |
| | | boolean dirFileExist = true; |
| | | if(!dirFile.exists()){ |
| | | dirFile.mkdirs(); |
| | | dirFileExist = false; |
| | | } |
| | | StringBuilder fileNameJoin = new StringBuilder(); |
| | | for (int i = 0; i < multipartFileList.size(); i++) { |
| | | MultipartFile multipartFile = multipartFileList.get(i); |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | fileNameJoin.append(originalFilename).append(","); |
| | | File zipFile = new File(dirPath + File.separator + originalFilename.substring(0,originalFilename.lastIndexOf(".")) + "_" + formattedTimestamp + originalFilename.substring(originalFilename.lastIndexOf("."))); |
| | | multipartFile.transferTo(zipFile); |
| | | } |
| | | //fileNameJoin去除最后一个元素 |
| | | fileNameJoin.deleteCharAt(fileNameJoin.length()-1); |
| | | /*//解压文件夹,删除原zip文件 |
| | | String unPackageDir = dirPath + File.separator + timestamp; |
| | | Zip4jUtil.unPackZip(zipFile, null, unPackageDir); |
| | |
| | | //上传的文件夹转移到正式路径 |
| | | org.aspectj.util.FileUtil.copyDir(unPackageFile,dirFile); |
| | | FileUtil.deleteFile(unPackageFile);*/ |
| | | /*0120开头的物料上传后,系统自动发邮件对应人员:吴浚、陈卓、熊家杰、钱镜元、於奇 |
| | | 0108、0109开头的物料上传后,系统自动发邮件对应人员:喻艳、袁成、熊志平、叶胜蓝 */ |
| | | MailDTO mailDTO = new MailDTO(); |
| | | DocUser user = ActionUtil.getUser(); |
| | | Material materialById = mapper.getMaterialById(material.getId()); |
| | | mailDTO.setTitle("【附件更新提醒】"); |
| | | if(subCode.startsWith("0120")){ |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(5); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台"+formattedNow+"上传了附件,详细信息如下:\n物料编码:"+subCode+"\n物料名称:"+materialById.getSubName()+"\n物料型号:"+subModel+"\n附件名称:"+fileNameJoin.toString()); |
| | | mailService.sendMail(mailDTO); |
| | | }else if (subCode.startsWith("0108")|| subCode.startsWith("0109")){ |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(6); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台"+formattedNow+"上传了附件,详细信息如下:\n物料编码:"+subCode+"\n物料名称:"+materialById.getSubName()+"\n物料型号:"+subModel+"\n附件名称:"+fileNameJoin.toString()); |
| | | mailService.sendMail(mailDTO); |
| | | } |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | | |
| | | /** |
| | | * 转移 被复制的附件,到新的物料 |
| | | * @param materialDB .fileUrl 被复制的附件路径,例如:doc_file\material\8468-0109000512-SHIDA-2455-OLD-ZX_A01 |
| | | * @param material 新的物料 |
| | | * @return 返回被追加文件的文件夹路径 |
| | | */ |
| | | @Transactional |
| | | public Response transferCopiedAttachment(Material materialDB, Material material) throws IOException { |
| | | String fileUrlDir = materialDB.getFileUrl(); |
| | | String subModel = material.getSubModel(); |
| | | subModel = MaterialSpecialCharUtil.transfer(subModel); |
| | | String dirPathDB = "doc_file" + File.separator + "material" + File.separator + material.getId() + "-"+ material.getSubCode() + "-" + subModel; |
| | | String dirPath = CommonUtil.getRootFile() + "material" + File.separator + material.getId() + "-"+ material.getSubCode() + "-" + subModel; |
| | | File dirFile = new File(dirPath); |
| | | |
| | | if(!dirFile.exists()){ |
| | | |
| | | dirFile.mkdirs(); |
| | | } |
| | | FileUtil.copyDirectory(new File(CommonUtil.getProjectDir() + File.separator + fileUrlDir),dirFile); |
| | | |
| | | //设置物料对应的fileUrl及物料状态 |
| | | Material temp = new Material(); |
| | | temp.setId(material.getId()); |
| | | temp.setFileUrl(dirPathDB); |
| | | mapper.updateById(temp); |
| | | |
| | | attachLockService.getAndInsert(materialDB.getId(),material.getId()); |
| | | |
| | | |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | |
| | | public Response updatePicOrDwg(MultipartFile multipartFile, Material material) throws IOException { |
| | | List<String> currentFileList = new LinkedList<>(); |
| | | List<String> uploadingFileList = new LinkedList<>(); |
| | | |
| | | String dirPathDB = "doc_file" + File.separator + "material" + File.separator + material.getSubCode() + "-" + material.getSubModel(); |
| | | String dirPath = CommonUtil.getRootFile() + "material" + File.separator + material.getSubCode() + "-" + material.getSubModel(); |
| | | String subCode = material.getSubCode(); |
| | | String subModel = material.getSubModel(); |
| | | subModel = MaterialSpecialCharUtil.transfer(subModel); |
| | | String dirPathDB = "doc_file" + File.separator + "material" + File.separator + subCode + "-" + subModel; |
| | | String dirPath = CommonUtil.getRootFile() + "material" + File.separator + subCode + "-" + subModel; |
| | | File dirFile = new File(dirPath); |
| | | |
| | | Date now = new Date(); |
| | | //long timestamp = now.getTime(); |
| | | String formattedTimestamp = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(now); |
| | | String formattedNow = DateUtil.YYYY_MM_DD_HH_MM_SS.format(now); |
| | | |
| | | if (!dirFile.exists()) { |
| | | dirFile.mkdirs(); |
| | |
| | | mapper.updateById(temp); |
| | | mhService.insert(mh); |
| | | |
| | | /*0120开头的物料上传后,系统自动发邮件对应人员:吴浚、陈卓、熊家杰、钱镜元、於奇 |
| | | 0108、0109开头的物料上传后,系统自动发邮件对应人员:喻艳、袁成、熊志平、叶胜蓝 */ |
| | | Material materialById = mapper.getMaterialById(material.getId()); |
| | | MailDTO mailDTO = new MailDTO(); |
| | | DocUser user = ActionUtil.getUser(); |
| | | mailDTO.setTitle("【图纸图片更新提醒】"); |
| | | if(subCode.startsWith("0120")){ |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(5); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台"+formattedNow+"上传了图纸或图片,详细信息如下:\n物料编码:"+subCode+"\n物料名称:"+materialById.getSubName()+"\n物料型号:"+subModel+"\n图纸图片名称:"+originalFilename); |
| | | mailService.sendMail(mailDTO); |
| | | }else if (subCode.startsWith("0108")|| subCode.startsWith("0109")){ |
| | | List<MailUser> mailUserList = mailUserService.getMailUserList(6); |
| | | mailDTO.setMailList(mailUserList.stream().map(MailUser::getMail).collect(Collectors.toList())); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台"+formattedNow+"上传了图纸或图片,详细信息如下:\n物料编码:"+subCode+"\n物料名称:"+materialById.getSubName()+"\n物料型号:"+subModel+"\n图纸图片名称:"+originalFilename); |
| | | mailService.sendMail(mailDTO); |
| | | } |
| | | return new Response().set(1, true, "上传完成"); |
| | | } |
| | | public Response dwgCompare(int materialId, int materialId2) throws IOException { |
| | |
| | | query.eq("sub_code",code).orderByDesc("id").last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | //物料推送弹窗使用 |
| | | public Response getMaterialDialog(String subCode, String subName, String subModel) { |
| | | List<Material> list=mapper.getMaterialLimit(subCode,subName,subModel); |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | int flag=0; |
| | | Material m=new Material(); |
| | | // 返回是否存在附件 |
| | | if(list!=null&&list.size()>0){ |
| | | m=list.get(list.size()-1); |
| | | if(m.getFileUrl()!=null&&!m.getFileUrl().isEmpty()){ |
| | | File file = new File(fileDirName+File.separator+m.getFileUrl()); |
| | | if(!file.exists()) { |
| | | flag=0; |
| | | }else{ |
| | | String[] fileNames = file.list();//获取该文件夹下的所有文件以及目录的名字 |
| | | List attachFileList=new ArrayList(); |
| | | if(fileNames.length>0){ |
| | | flag=1; |
| | | for (int i=0;i<fileNames.length;i++){ |
| | | if(!fileNames[i].contains("-dwg.pdf")&&!fileNames[i].contains("-doc.pdf")) |
| | | attachFileList.add(fileNames[i]); |
| | | } |
| | | }else{ |
| | | flag=0; |
| | | } |
| | | m.setAttachFileList(attachFileList); |
| | | } |
| | | } |
| | | m.setHasAttachFlag(flag); |
| | | } |
| | | return new Response().setII(1,m!=null,m,"物料推送弹窗使用"); |
| | | } |
| | | } |