whyclxw
2024-07-24 1a8db70fe9c5d9a79ed50ca35a19a247dcddfc6a
src/main/java/com/whyc/service/DefectiveProductsService.java
@@ -15,6 +15,7 @@
import com.whyc.pojo.DocUser;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -46,17 +47,25 @@
    //录入不良品信息
    @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();
        long time = date.getTime();
        //String feedbackZipPath = "defective" + File.separator + username + "_" + time+".zip";
        String senderName = ActionUtil.getUser().getName();
        Integer senderId =ActionUtil.getUser().getId().intValue();
        defective.setSenderId(senderId);
        defective.setSenderName(senderName);
        Date date=new Date();
        defective.setRecordTime(date);
        if(defective.getStartTime()==null){
            //保存
            defective.setStartTime(date);
        }
        String recordtime = ActionUtil.sdfwithFTP.format(defective.getRecordTime());
        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+ recordtime + File.separator;
            String feedbackDir = rootFile + defectiveDirSuffix;
            File fileDir = new File(feedbackDir);
            if (!fileDir.exists()) {
@@ -74,29 +83,24 @@
                multipartFile.transferTo(file);
            }
            //ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath)));
            defective.setFileUrl("doc_file" + File.separator + defectiveDirSuffix);
            defective.setFileUrl( File.separator + defectiveDirSuffix);
        }
        if(defective.getStartTime()==null){
            //保存
            defective.setStartTime(date);
        }
        mapper.insert(defective);
        //发送邮件
        String receiverIds = defective.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){
      /*  for (DocUser docUser:docUsers){
            if(docUser.getId().intValue() == senderId){
                senderName = docUser.getName();
                break;
            }
        }
        }*/
        for (String receiverId:receiverIdsSplit){
            for (DocUser docUser:docUsers){
@@ -128,19 +132,49 @@
    public Response getDefectiveLimit(DefectiveDto defectiveDto) {
        PageHelper.startPage(defectiveDto.getPageCurr(),defectiveDto.getPageSize());
        List<DefectiveProducts> list=mapper.getDefectiveLimit(defectiveDto);
        String rootFile = CommonUtil.getRootFile();//主路径
        for (DefectiveProducts defective:list) {
            String filePath=defective.getFileUrl();
            defective.setFileUrl("doc_file"+File.separator+filePath);
            if(filePath!=null&&!filePath.isEmpty()){
                defective.setNameList(FileUtil.getFileNameWithOutDirectory(rootFile+filePath));
            }
            List<DefectiveProductsHistory> hisList=defective.getHisList();
            if(hisList!=null&&hisList.size()>0){
                for (DefectiveProductsHistory his:defective.getHisList()) {
                    String hisDelPath=his.getDelUrl();
                    his.setDelUrl("doc_file"+File.separator+hisDelPath);
                    if(hisDelPath!=null&&!hisDelPath.isEmpty()){
                        his.setHisNameList(FileUtil.getFileNameWithOutDirectory(rootFile+hisDelPath));
                    }
                }
            }
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"不良品首页推送");
    }
    //处理不良品
    @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());
@@ -157,24 +191,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){
@@ -188,7 +210,7 @@
            }
        }
        String subject = "【不良品记录】-"+senderName;
        String subject = "【不良品处理记录】-"+senderName;
        String content = defective.getContent();
        MailDTO mailDTO = new MailDTO();
@@ -201,6 +223,7 @@
    }
    //归档不良品
    @Transactional
    public Response stopDefective(int deftId) {
        //修改当前表记录
        UpdateWrapper wrapper=new UpdateWrapper();
@@ -214,9 +237,11 @@
        //记录处理记录
        DefectiveProductsHistory defectiveHis=new DefectiveProductsHistory();
        defectiveHis.setDeftId(deftId);
        defectiveHis.setDelId(ActionUtil.getUser().getId().intValue());
        defectiveHis.setConfirmStatus(3);
        defectiveHis.setBadProduct(0);
        defectiveHisService.updateDefective(defectiveHis);
        defectiveHis.setDelId(ActionUtil.getUser().getId().intValue());
        defectiveHisService.stopDefective(defectiveHis);
        return new Response().set(1,true);
    }
}