whyclxw
2024-07-25 9a48f0e7c87a371b50e5b92a2533dc14ea262374
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 javax.xml.crypto.Data;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
 
@Service
public class DefectiveProductsHistoryService {
 
    @Autowired(required = false)
    private DefectiveProductsHistoryMapper mapper;
 
    //记录处理过程
    public void addHis(DefectiveProducts defective) {
        DefectiveProductsHistory his=new DefectiveProductsHistory();
        his.setDeftId(defective.getId());
        his.setRecordTime(defective.getRecordTime());
        his.setConfirmStatus(defective.getConfirmStatus());
        his.setNote(defective.getNote());
        his.setReceiverIds(defective.getReceiverIds());
        his.setReceiverNames(defective.getReceiverNames());
        his.setDelProduct(0);
        his.setDelId(defective.getSenderId());
        his.setDelName(defective.getSenderName());
        his.setRestProduct(defective.getRestProduct());
        mapper.insert(his);
    }
    //记录处理记录
    public void updateDefective( DefectiveProducts defective,DefectiveProductsHistory defectiveHis, List<MultipartFile> multipartFileList) {
        Date date=new Date();
        defectiveHis.setRecordTime(date);
        String recordTime=ActionUtil.sdfwithFTP.format(date);
        String delName = ActionUtil.getUser().getName();
        Integer delId =ActionUtil.getUser().getId().intValue();
        defectiveHis.setDelId(delId);
        defectiveHis.setDelName(delName);
        String record = ActionUtil.sdfwithFTP.format(defective.getRecordTime());
        String rootFile = CommonUtil.getRootFile();
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String defectiveDirSuffix = "defective" + File.separator + defective.getSenderName() + File.separator+ record + File.separator
                    +delName+File.separator+recordTime+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();
                }
            }
            defectiveHis.setDelUrl(defectiveDirSuffix);
        }
        mapper.insert(defectiveHis);
    }
    //归档不良品
    public void stopDefective(DefectiveProductsHistory defectiveHis) {
        defectiveHis.setRecordTime(new Date());
        mapper.insert(defectiveHis);
    }
}