| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.MailDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BOMFeedbakMapper; |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.mapper.ProductHistoryMapper; |
| | | import com.whyc.pojo.BOMFeedback; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.Product; |
| | | import com.whyc.pojo.ProductHistory; |
| | | 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.multipart.MultipartFile; |
| | | |
| | | import java.util.Map; |
| | | import javax.annotation.Resource; |
| | | import javax.mail.MessagingException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class BOMFeedbakService { |
| | | @Autowired(required = false) |
| | | private BOMFeedbakMapper mapper; |
| | | @Autowired |
| | | private MailService mailService; |
| | | @Resource |
| | | private DocUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private DocLogService logService; |
| | | |
| | | @Autowired |
| | | private ProductHistoryService phisService; |
| | | |
| | | @Resource |
| | | private ProductHistoryMapper phisMapper; |
| | | |
| | | @Autowired |
| | | private ProductService productService; |
| | | |
| | | //统计 |
| | | public Map<String, Integer> getFkStatistic(DocUser user,Map<String, Integer> map) { |
| | | int sendFk=0; |
| | |
| | | case "1001": |
| | | map.put("sendFk",0); |
| | | sendFk=mapper.selectSender(user.getId()); |
| | | recevierFk=mapper.selectReceiver(user.getId()); |
| | | map.put("sendFk",sendFk); |
| | | map.put("recevierFk",recevierFk); |
| | | break; |
| | | //项目经理 |
| | | case "1002": |
| | |
| | | } |
| | | return map; |
| | | } |
| | | //查询发送者反馈不同状态 |
| | | public Response getSenderStatus(int[] flags,int pageCurr,int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<BOMFeedback> list=mapper.getSenderStatus(ActionUtil.getUser().getId(),flags); |
| | | //获取路径 |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | | BOMFeedback feedback=list.get(i); |
| | | String attachFilePath=fileDirName+File.separator+feedback.getFile(); |
| | | File start = new File(attachFilePath); |
| | | String[] files =new String[]{}; |
| | | List attachList=new ArrayList(); |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int j=0;j<files.length;j++) { |
| | | attachList.add(feedback.getFile()+files[j]); |
| | | } |
| | | } |
| | | } |
| | | feedback.setAttachFiles(attachList); |
| | | } |
| | | } |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"发送者反馈"); |
| | | } |
| | | //查询接收者反馈不同状态 |
| | | public Response getRecevierStatus(int[] flags, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | String name=ActionUtil.getUser().getName(); |
| | | long id=ActionUtil.getUser().getId(); |
| | | List<BOMFeedback> list=new ArrayList(); |
| | | if(name.equals("杨红兰")){ |
| | | //当是杨红兰查看时,只有杨红兰的排在最前面 |
| | | list=mapper.getRecevierYHL(id,name,flags); |
| | | }else{ |
| | | list=mapper.getRecevierStatus(id,flags); |
| | | } |
| | | //获取路径 |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | | BOMFeedback feedback=list.get(i); |
| | | String attachFilePath=fileDirName+File.separator+feedback.getFile(); |
| | | File start = new File(attachFilePath); |
| | | String[] files =new String[]{}; |
| | | List attachList=new ArrayList(); |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int j=0;j<files.length;j++) { |
| | | attachList.add(feedback.getFile()+files[j]); |
| | | } |
| | | } |
| | | } |
| | | feedback.setAttachFiles(attachList); |
| | | } |
| | | } |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"接收者反馈"); |
| | | } |
| | | |
| | | /** |
| | | * 接收者确认反馈 |
| | | * |
| | | * @param feedback |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public Response confirmFeedback(BOMFeedback feedback) { |
| | | DocUser user = ActionUtil.getUser(); |
| | | int userId = user.getId().intValue(); |
| | | String username = user.getName(); |
| | | String msg=""; |
| | | boolean bl=true; |
| | | int id = feedback.getId(); |
| | | Integer confirmStatus = feedback.getConfirmStatus(); |
| | | String replyContent = feedback.getReplyContent(); |
| | | Date now = new Date(); |
| | | if(confirmStatus == 1){ //与我无关 |
| | | if(replyContent == null || replyContent.isEmpty()) { |
| | | feedback.setReplyContent("系统默认生成回复:与我无关"); |
| | | } |
| | | } |
| | | //1.确认前先判断反馈是否被确认 |
| | | QueryWrapper<BOMFeedback> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.eq("id",id); |
| | | queryWrapper.ne("confirm_status",0).last(" limit 1"); |
| | | BOMFeedback feedbackDB = mapper.selectOne(queryWrapper); |
| | | if(feedbackDB!=null){ |
| | | msg="该反馈已被确认"; |
| | | bl=false; |
| | | }else{ |
| | | if(confirmStatus == 1){ //与我无关,完结原记录;生成新记录,剔除当前确认人 |
| | | QueryWrapper<BOMFeedback> query = Wrappers.query(); |
| | | query.eq("id",id).last(" limit 1"); |
| | | feedbackDB = mapper.selectOne(query); |
| | | feedbackDB.setId(null); |
| | | String receiverIdsNow = feedbackDB.getReceiverIds(); |
| | | String receiverNamesNow = feedbackDB.getReceiverNames(); |
| | | //接受者id剔除当前用户id |
| | | String[] receiverIdArr = receiverIdsNow.split(","); |
| | | StringBuilder idsNextBuilder = new StringBuilder(); |
| | | for (int i = 0; i < receiverIdArr.length; i++) { |
| | | if(!receiverIdArr[i].equals(String.valueOf(userId))){ |
| | | if(idsNextBuilder.length()==0){ |
| | | idsNextBuilder.append(receiverIdArr[i]); |
| | | }else{ |
| | | idsNextBuilder.append(",").append(receiverIdArr[i]); |
| | | } |
| | | } |
| | | } |
| | | feedbackDB.setReceiverIds(idsNextBuilder.toString()); |
| | | |
| | | //接受者名字剔除当前用户名 |
| | | String[] receiverNamesArr = receiverNamesNow.split(","); |
| | | StringBuilder namesNextBuilder = new StringBuilder(); |
| | | for (int i = 0; i < receiverNamesArr.length; i++) { |
| | | if(!receiverNamesArr[i].equals(String.valueOf(username))){ |
| | | if(namesNextBuilder.length()==0){ |
| | | namesNextBuilder.append(receiverNamesArr[i]); |
| | | }else{ |
| | | namesNextBuilder.append(",").append(receiverNamesArr[i]); |
| | | } |
| | | } |
| | | } |
| | | feedbackDB.setReceiverNames(namesNextBuilder.toString()); |
| | | mapper.insert(feedbackDB); |
| | | } |
| | | //2.确认反馈 |
| | | UpdateWrapper<BOMFeedback> wrapper=new UpdateWrapper<>(); |
| | | wrapper.set("confirm_status",confirmStatus); |
| | | wrapper.set("confirm_user_name",username); |
| | | wrapper.set("reply_content",replyContent); |
| | | wrapper.set("reply_time",now); |
| | | wrapper.eq("id",id); |
| | | int count=mapper.update(null,wrapper); |
| | | bl=count>0; |
| | | msg="接收者确认反馈"; |
| | | |
| | | if(confirmStatus == 2){ |
| | | //解锁产品 |
| | | Integer productId = mapper.selectById(id).getProductId(); |
| | | Product product = productService.getById(productId); |
| | | //解锁产品时解锁锁定时的版本号 |
| | | int nowVersion=feedbackDB.getNowVersion(); |
| | | if(product!=null){ |
| | | if(nowVersion!=-1){ |
| | | phisService.setpHistoryEnable(product.getParentCode(),product.getCustomCode(),nowVersion,1,"问题反馈后"+ username +"确认不需要修改bom,系统执行产品解锁",DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime())); |
| | | } |
| | | }else{ |
| | | ProductHistory phis = phisService.getById(productId); |
| | | phisService.setpHistoryEnable(phis.getParentCode(),phis.getCustomCode(),nowVersion,1,"问题反馈后"+ username +"确认不需要修改bom,系统执行产品解锁",DateUtil.YYYY_MM_DD_HH_MM_SS.format(phis.getVersionTime())); |
| | | } |
| | | } |
| | | } |
| | | return new Response().set(1,bl,msg); |
| | | } |
| | | |
| | | /** |
| | | * 提交反馈: |
| | | * 1.记录数据库保存 |
| | | * 2.附件存储 |
| | | * 3.邮件发送 |
| | | * @param feedback bom问题反馈 |
| | | * @param multipartFileList |
| | | * @return response |
| | | */ |
| | | public Response submitFeedback(BOMFeedback feedback, List<MultipartFile> multipartFileList) throws IOException, MessagingException { |
| | | Date date = new Date(); |
| | | //压缩包的路径及格式为: doc_file/feedback_bom/username_time.zip |
| | | String username = ActionUtil.getUser().getName(); |
| | | long time = date.getTime(); |
| | | //String feedbackZipPath = "feedback_bom" + File.separator + username + "_" + time+".zip"; |
| | | //List<File> fileList = new LinkedList<>(); |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | if(multipartFileList!=null && multipartFileList.size()!=0){ |
| | | String feedbackDirSuffix = "feedback_bom" + File.separator + username + File.separator + time + File.separator; |
| | | String feedbackDir = rootFile + feedbackDirSuffix; |
| | | File fileDir = new File(feedbackDir); |
| | | if (!fileDir.exists()) { |
| | | fileDir.mkdirs(); |
| | | } |
| | | for (int i = 0; i < multipartFileList.size(); i++) { |
| | | MultipartFile multipartFile = multipartFileList.get(i); |
| | | //存储文件 |
| | | |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | String fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")); |
| | | String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | String feedbackPath = feedbackDir + fileName + suffix; |
| | | File file = new File(feedbackPath); |
| | | |
| | | multipartFile.transferTo(file); |
| | | //fileList.add(file); |
| | | } |
| | | //ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath))); |
| | | feedback.setFile("doc_file" + File.separator + feedbackDirSuffix); |
| | | } |
| | | //删除已经被压缩的文件 |
| | | //for (File file : fileList) { |
| | | // file.delete(); |
| | | //} |
| | | |
| | | //查询产品的信息 |
| | | QueryWrapper hisWrapper=new QueryWrapper(); |
| | | hisWrapper.eq("id",feedback.getProductId()); |
| | | hisWrapper.last("limit 1"); |
| | | ProductHistory phis=phisMapper.selectOne(hisWrapper); |
| | | //保存 |
| | | feedback.setCreateTime(date); |
| | | feedback.setConfirmStatus(0); |
| | | feedback.setNowVersion(phis.getVersion()); |
| | | mapper.insert(feedback); |
| | | //发送邮件 |
| | | String receiverIds = feedback.getReceiverIds(); |
| | | String[] receiverIdsSplit = receiverIds.split(","); |
| | | List<String> receiverMailList = new LinkedList<>(); |
| | | |
| | | Integer senderId = feedback.getSenderId(); |
| | | String senderName = null; |
| | | |
| | | List<DocUser> docUsers = userMapper.selectList(null); |
| | | for (DocUser docUser:docUsers){ |
| | | if(docUser.getId().intValue() == senderId){ |
| | | senderName = docUser.getName(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (String receiverId:receiverIdsSplit){ |
| | | for (DocUser docUser:docUsers){ |
| | | if(docUser.getId().intValue() == Integer.parseInt(receiverId)){ |
| | | String mail = docUser.getMail(); |
| | | if(mail!=null && !mail.isEmpty()) { |
| | | receiverMailList.add(mail); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | String subject = "【Bom问题反馈】-"+senderName; |
| | | //邮件内容,添加产品的相关信息 |
| | | Product product = productService.getById(feedback.getProductId()); |
| | | |
| | | String content ="产品料号:"+product.getParentCode() + "\n产品名称:"+product.getParentName() + "\n产品型号:"+product.getParentModel() + "\n版本时间:"+ DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime()) + "\n定制单号:"+product.getCustomCode() + "\n产品反馈内容:"+ feedback.getContent(); |
| | | |
| | | MailDTO mailDTO = new MailDTO(); |
| | | mailDTO.setTitle(subject); |
| | | mailDTO.setContent(content); |
| | | mailDTO.setMailList(receiverMailList); |
| | | mailService.sendMail(mailDTO); |
| | | //mailUtil.sendMailBatch(senderName,receiverMailList,subject,content); |
| | | //反馈时直接根据productid直接锁定 |
| | | phisService.setpHistoryEnable(phis.getParentCode(),phis.getCustomCode(),phis.getVersion(),0,feedback.getContent(),ActionUtil.sdfwithALL.format(phis.getVersionTime())); |
| | | return new Response().set(1,true,"反馈完成"); |
| | | } |
| | | //根据文件路径下载 |
| | | public void downLoadFileByFilePath(HttpServletRequest req, HttpServletResponse resp, String filePath |
| | | ,String oprateReason,String oprateInfo,String oprateVersion,int type) { |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String fileName=filePath.substring(filePath.lastIndexOf("\\")+1); |
| | | try { |
| | | // 转码防止乱码 |
| | | //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1")); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (fileName, "utf-8")); |
| | | OutputStream out = resp.getOutputStream(); |
| | | FileInputStream in = new FileInputStream(fileDirName+File.separator+filePath); |
| | | int len=0; |
| | | byte[] buffer =new byte[1024]; |
| | | //7. 将缓冲区中的数据输出 |
| | | while ((len=in.read(buffer))>0){ |
| | | out.write(buffer,0,len); |
| | | } |
| | | in.close(); |
| | | out.close(); |
| | | } catch (FileNotFoundException | UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //记录新版下载日志 |
| | | logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), type,new Date(),req.getRemoteAddr() |
| | | ,fileName,fileDirName+File.separator+filePath,oprateReason,oprateInfo,oprateVersion); |
| | | } |
| | | |
| | | public Response updateEcrNumber(int id, String ecrNumber) { |
| | | UpdateWrapper<BOMFeedback> update = Wrappers.update(); |
| | | update.set("ecr_number",ecrNumber).set("confirm_status",4).eq("id",id); |
| | | mapper.update(null, update); |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response receiverUserAppend(String id, String userId, String username) throws MessagingException { |
| | | QueryWrapper<BOMFeedback> query = Wrappers.query(); |
| | | query.eq("id",id).last(" limit 1"); |
| | | BOMFeedback feedback = mapper.selectOne(query); |
| | | |
| | | feedback.setReceiverIds(feedback.getReceiverIds()+","+userId); |
| | | feedback.setReceiverNames(feedback.getReceiverNames()+","+username); |
| | | mapper.updateById(feedback); |
| | | //发送邮件 |
| | | List<String> receiverMailList = new LinkedList<>(); |
| | | |
| | | String appendUsername = ActionUtil.getUser().getName(); |
| | | //反馈发送者名称 |
| | | QueryWrapper<DocUser> userQuery1 = Wrappers.query(); |
| | | userQuery1.eq("id",feedback.getSenderId()).last(" limit 1"); |
| | | String senderName = userMapper.selectOne(userQuery1).getName(); |
| | | //反馈接收者邮箱 |
| | | QueryWrapper<DocUser> userQuery2 = Wrappers.query(); |
| | | userQuery2.eq("id",userId).last(" limit 1"); |
| | | String mail = userMapper.selectOne(userQuery2).getMail(); |
| | | if(mail!=null && !mail.isEmpty()) { |
| | | receiverMailList.add(mail); |
| | | } |
| | | |
| | | if(receiverMailList.size()>0) { |
| | | String subject = "【Bom问题反馈】-" + senderName + ",由" + appendUsername + "转发给您"; |
| | | String content = feedback.getContent(); |
| | | MailDTO mailDTO = new MailDTO(); |
| | | mailDTO.setTitle(subject); |
| | | mailDTO.setContent(content); |
| | | mailDTO.setMailList(receiverMailList); |
| | | mailService.sendMail(mailDTO); |
| | | //mailUtil.sendMailBatch(senderName, receiverMailList, subject, content); |
| | | } |
| | | return new Response().setII(1,"追加反馈用户完成"); |
| | | } |
| | | |
| | | public Response getListPage(BOMFeedback feedback, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<BOMFeedback> list = mapper.getListPage(feedback); |
| | | //获取路径 |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | | BOMFeedback fb=list.get(i); |
| | | String attachFilePath=fileDirName+File.separator+fb.getFile(); |
| | | File start = new File(attachFilePath); |
| | | String[] files =new String[]{}; |
| | | List attachList=new ArrayList(); |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int j=0;j<files.length;j++) { |
| | | attachList.add(fb.getFile()+files[j]); |
| | | } |
| | | } |
| | | } |
| | | fb.setAttachFiles(attachList); |
| | | } |
| | | } |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().set(1,pageInfo); |
| | | |
| | | } |
| | | } |