| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.DefectiveDto; |
| | |
| | | import com.whyc.pojo.DefectiveProducts; |
| | | import com.whyc.pojo.DefectiveProductsHistory; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.ProductHistory; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | 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 javax.annotation.Resource; |
| | |
| | | private DefectiveProductsHistoryService defectiveHisService; |
| | | |
| | | |
| | | |
| | | //录入不良品信息 |
| | | @Transactional |
| | | public Response addDefective(DefectiveProducts defective, List<MultipartFile> multipartFileList) throws IOException { |
| | | //初次录入状态为0 |
| | | defective.setConfirmStatus(0); |
| | | Date date = new Date(); |
| | | //压缩包的路径及格式为: doc_file/defective/username_time.zip |
| | | String username = ActionUtil.getUser().getName(); |
| | | String senderName = ActionUtil.getUser().getName(); |
| | | String senderId =ActionUtil.getUser().getId().toString(); |
| | | defective.setSenderId(Integer.parseInt(senderId)); |
| | | long time = date.getTime(); |
| | | //String feedbackZipPath = "defective" + File.separator + username + "_" + time+".zip"; |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | if(multipartFileList!=null && multipartFileList.size()!=0){ |
| | | String defectiveDirSuffix = "defective" + File.separator + username + File.separator + time + File.separator; |
| | | String defectiveDirSuffix = "defective" + File.separator + senderName + File.separator + time + File.separator; |
| | | String feedbackDir = rootFile + defectiveDirSuffix; |
| | | File fileDir = new File(feedbackDir); |
| | | if (!fileDir.exists()) { |
| | |
| | | String[] receiverIdsSplit = receiverIds.split(","); |
| | | List<String> receiverMailList = new LinkedList<>(); |
| | | |
| | | Integer senderId = defective.getSenderId(); |
| | | String senderName = null; |
| | | |
| | | List<DocUser> docUsers = userMapper.selectList(null); |
| | | for (DocUser docUser:docUsers){ |
| | | /* for (DocUser docUser:docUsers){ |
| | | if(docUser.getId().intValue() == senderId){ |
| | | senderName = docUser.getName(); |
| | | break; |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | for (String receiverId:receiverIdsSplit){ |
| | | for (DocUser docUser:docUsers){ |
| | |
| | | } |
| | | |
| | | //处理不良品 |
| | | @Transactional |
| | | public Response updateDefective(DefectiveProductsHistory defectiveHis) { |
| | | //获取上一次记录信息 |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("id",defectiveHis.getDeftId()); |
| | | qwrapper.last("limit 1"); |
| | | DefectiveProducts defective=mapper.selectOne(qwrapper); |
| | | |
| | | //修改当前表记录 |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("receiver_ids",defectiveHis.getReceiverIds()); |
| | | wrapper.set("receiver_names",defectiveHis.getReceiverNames()); |
| | | wrapper.set("bad_product",defectiveHis.getBadProduct()); |
| | | if(defectiveHis.getBadProduct()==0){ |
| | | defectiveHis.setConfirmStatus(2);//不良品数量为0结束 |
| | | }else { |
| | | defectiveHis.setConfirmStatus(1); |
| | | } |
| | | wrapper.set("confirm_status",defectiveHis.getConfirmStatus()); |
| | | wrapper.set("note",defectiveHis.getNote()); |
| | | wrapper.eq("id",defectiveHis.getDeftId()); |
| | | mapper.update(null,wrapper); |
| | | |
| | | //记录处理记录 |
| | | defectiveHisService.updateDefective(defectiveHis); |
| | | |
| | | //发送邮件 |
| | | String receiverIds = defectiveHis.getReceiverIds(); |
| | | String[] receiverIdsSplit = receiverIds.split(","); |
| | | List<String> receiverMailList = new LinkedList<>(); |
| | | |
| | | //获取 |
| | | Integer senderId = defective.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 = "【不良品记录】-"+senderName; |
| | | String content = defective.getContent(); |
| | | |
| | | MailDTO mailDTO = new MailDTO(); |
| | | mailDTO.setTitle(subject); |
| | | mailDTO.setContent(content); |
| | | mailDTO.setMailList(receiverMailList); |
| | | mailService.sendMail(mailDTO); |
| | | |
| | | return new Response().set(1,true); |
| | | } |
| | | |
| | | //归档不良品 |
| | | @Transactional |
| | | public Response stopDefective(int deftId) { |
| | | //修改当前表记录 |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("confirm_status",3);//归档 |
| | | wrapper.set("receiver_ids",""); |
| | | wrapper.set("receiver_names",""); |
| | | wrapper.set("bad_product",0); |
| | | wrapper.set("note",""); |
| | | wrapper.eq("id",deftId); |
| | | mapper.update(null,wrapper); |
| | | //记录处理记录 |
| | | DefectiveProductsHistory defectiveHis=new DefectiveProductsHistory(); |
| | | defectiveHis.setDeftId(deftId); |
| | | defectiveHis.setConfirmStatus(3); |
| | | defectiveHis.setBadProduct(0); |
| | | defectiveHisService.updateDefective(defectiveHis); |
| | | return new Response().set(1,true); |
| | | } |
| | | } |