whyclxw
2024-07-23 4fe8ac8ae84108e64ac99d43cab153634cba6814
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);
    }