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.getStartTime());
|
his.setBadProduct(defective.getBadProduct());
|
his.setConfirmStatus(defective.getConfirmStatus());
|
his.setNote(defective.getNote());
|
his.setReceiverIds(defective.getReceiverIds());
|
his.setReceiverNames(defective.getReceiverNames());
|
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( File.separator + defectiveDirSuffix);
|
}
|
mapper.insert(defectiveHis);
|
}
|
//归档不良品
|
public void stopDefective(DefectiveProductsHistory defectiveHis) {
|
defectiveHis.setRecordTime(new Date());
|
mapper.insert(defectiveHis);
|
}
|
}
|