whyclxw
2024-07-23 4fe8ac8ae84108e64ac99d43cab153634cba6814
不良品推送修改
5个文件已修改
105 ■■■■ 已修改文件
src/main/java/com/whyc/controller/DefectiveProductsController.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/DefectiveProducts.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/DefectiveProductsHistory.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DefectiveProductsHistoryService.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DefectiveProductsService.java 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/DefectiveProductsController.java
@@ -35,8 +35,9 @@
    @ApiOperation("处理不良品")
    @PostMapping("updateDefective")
    public Response updateDefective(@RequestBody DefectiveProductsHistory defectiveHis) {
        return service.updateDefective(defectiveHis);
    public Response updateDefective(@RequestPart(required = false) List<MultipartFile> multipartFileList, @RequestParam String defectiveHisJson) {
        DefectiveProductsHistory defectiveHis= ActionUtil.getGson().fromJson(defectiveHisJson, DefectiveProductsHistory.class);
        return service.updateDefective(defectiveHis,multipartFileList);
    }
    @ApiOperation("归档不良品")
src/main/java/com/whyc/pojo/DefectiveProducts.java
@@ -55,6 +55,9 @@
    @ApiModelProperty(value = "提出者")
    private Integer senderId;
    @TableField(exist = false)
    private String senderName;
    @ApiModelProperty(value = "接受者")
    private String receiverIds;
src/main/java/com/whyc/pojo/DefectiveProductsHistory.java
@@ -1,6 +1,7 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
@@ -52,5 +53,12 @@
    @ApiModelProperty(value = "备注")
    private String note;
    @TableField(exist = false)
    private Integer senderId;
    @ApiModelProperty(value = "处理者")
    private Integer delId;
}
src/main/java/com/whyc/service/DefectiveProductsHistoryService.java
@@ -4,10 +4,16 @@
import com.whyc.mapper.DefectiveProductsHistoryMapper;
import com.whyc.pojo.DefectiveProducts;
import com.whyc.pojo.DefectiveProductsHistory;
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.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@Service
public class DefectiveProductsHistoryService {
@@ -28,7 +34,40 @@
        mapper.insert(his);
    }
    //记录处理记录
    public void updateDefective(DefectiveProductsHistory defectiveHis) {
    public void updateDefective( DefectiveProducts defective,DefectiveProductsHistory defectiveHis, List<MultipartFile> multipartFileList) {
        defectiveHis.setRecordTime(new Date());
        String delName = ActionUtil.getUser().getName();
        Integer delId =ActionUtil.getUser().getId().intValue();
        defectiveHis.setDelId(delId);
        String time = ActionUtil.sdfwithday.format(defective.getStartTime());
        String rootFile = CommonUtil.getRootFile();
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String defectiveDirSuffix = "defective" + File.separator + defective.getSenderName() + File.separator + time + File.separator+delName+File.separator;
            String feedbackDir = rootFile + defectiveDirSuffix;
            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);
                try {
                    multipartFile.transferTo(file);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            defective.setFileUrl("doc_file" + File.separator + defectiveDirSuffix);
        }
        mapper.insert(defectiveHis);
    }
    //归档不良品
    public void stopDefective(DefectiveProductsHistory defectiveHis) {
        defectiveHis.setRecordTime(new Date());
        mapper.insert(defectiveHis);
    }
src/main/java/com/whyc/service/DefectiveProductsService.java
@@ -50,12 +50,15 @@
    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 senderName = ActionUtil.getUser().getName();
        String senderId =ActionUtil.getUser().getId().toString();
        defective.setSenderId(Integer.parseInt(senderId));
        long time = date.getTime();
        Integer senderId =ActionUtil.getUser().getId().intValue();
        defective.setSenderId(senderId);
        if(defective.getStartTime()==null){
            //保存
            defective.setStartTime(new Date());
        }
        String time = ActionUtil.sdfwithday.format(defective.getStartTime());
        //String feedbackZipPath = "defective" + File.separator + username + "_" + time+".zip";
        String rootFile = CommonUtil.getRootFile();
        if(multipartFileList!=null && multipartFileList.size()!=0){
@@ -80,10 +83,7 @@
            defective.setFileUrl("doc_file" + File.separator + defectiveDirSuffix);
        }
        if(defective.getStartTime()==null){
            //保存
            defective.setStartTime(date);
        }
        mapper.insert(defective);
        //发送邮件
        String receiverIds = defective.getReceiverIds();
@@ -135,13 +135,24 @@
    //处理不良品
    @Transactional
    public Response updateDefective(DefectiveProductsHistory defectiveHis) {
    public Response updateDefective(DefectiveProductsHistory defectiveHis, List<MultipartFile> multipartFileList) {
        //获取上一次记录信息
        QueryWrapper qwrapper=new QueryWrapper();
        qwrapper.eq("id",defectiveHis.getDeftId());
        qwrapper.last("limit 1");
        DefectiveProducts defective=mapper.selectOne(qwrapper);
        //获取
        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;
            }
        }
        defective.setSenderName(senderName);
        //修改当前表记录
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.set("receiver_ids",defectiveHis.getReceiverIds());
@@ -158,24 +169,12 @@
        mapper.update(null,wrapper);
        //记录处理记录
        defectiveHisService.updateDefective(defectiveHis);
        defectiveHisService.updateDefective(defective,defectiveHis,multipartFileList);
        //发送邮件
        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){
@@ -189,7 +188,7 @@
            }
        }
        String subject = "【不良品记录】-"+senderName;
        String subject = "【不良品处理记录】-"+senderName;
        String content = defective.getContent();
        MailDTO mailDTO = new MailDTO();
@@ -216,9 +215,10 @@
        //记录处理记录
        DefectiveProductsHistory defectiveHis=new DefectiveProductsHistory();
        defectiveHis.setDeftId(deftId);
        defectiveHis.setDelId(ActionUtil.getUser().getId().intValue());
        defectiveHis.setConfirmStatus(3);
        defectiveHis.setBadProduct(0);
        defectiveHisService.updateDefective(defectiveHis);
        defectiveHisService.stopDefective(defectiveHis);
        return new Response().set(1,true);
    }
}