whyclxw
2025-03-21 319d732f12a54e91079b843f83824a0274b7b5f7
src/main/java/com/whyc/service/BOMFeedbakService.java
@@ -5,21 +5,22 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.constant.UserOperation;
import com.whyc.dto.FileDirPath;
import com.whyc.dto.MailDTO;
import com.whyc.dto.Response;
import com.whyc.dto.ZipUtils;
import com.whyc.mapper.BOMFeedbakMapper;
import com.whyc.mapper.DocUserMapper;
import com.whyc.mapper.ProductHistoryMapper;
import com.whyc.pojo.BOMFeedback;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.Product;
import com.whyc.pojo.ProductHistory;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.MailUtil;
import com.whyc.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@@ -35,12 +36,22 @@
    @Autowired(required = false)
    private BOMFeedbakMapper mapper;
    @Autowired
    private MailUtil mailUtil;
    private MailService mailService;
    @Resource
    private DocUserMapper userMapper;
    @Autowired
    private DocLogService logService;
    @Autowired
    private ProductHistoryService phisService;
    @Resource
    private ProductHistoryMapper phisMapper;
    @Autowired
    private ProductService productService;
    //统计
    public Map<String, Integer> getFkStatistic(DocUser user,Map<String, Integer> map) {
        int sendFk=0;
@@ -78,7 +89,27 @@
    //查询发送者反馈不同状态
    public Response getSenderStatus(int[] flags,int pageCurr,int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        List list=mapper.getSenderStatus(ActionUtil.getUser().getId(),flags);
        List<BOMFeedback> list=mapper.getSenderStatus(ActionUtil.getUser().getId(),flags);
        //获取路径
        String fileDirName = FileDirPath.getFileDirName();
        if(list!=null&&list.size()>0){
            for (int i=0;i<list.size();i++) {
                BOMFeedback feedback=list.get(i);
                String attachFilePath=fileDirName+File.separator+feedback.getFile();
                File start = new File(attachFilePath);
                String[] files =new String[]{};
                List attachList=new ArrayList();
                if(start.exists()) {
                    files= start.list();//获取该文件夹下的所有文件名字
                    if(files.length>=0){
                        for(int j=0;j<files.length;j++) {
                            attachList.add(feedback.getFile()+files[j]);
                        }
                    }
                }
                feedback.setAttachFiles(attachList);
            }
        }
        PageInfo pageInfo = new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"发送者反馈");
    }
@@ -87,12 +118,32 @@
        PageHelper.startPage(pageCurr,pageSize);
        String name=ActionUtil.getUser().getName();
        long id=ActionUtil.getUser().getId();
        List list=new ArrayList();
        List<BOMFeedback> list=new ArrayList();
        if(name.equals("杨红兰")){
            //当是杨红兰查看时,只有杨红兰的排在最前面
            list=mapper.getRecevierYHL(id,name,flags);
        }else{
            list=mapper.getRecevierStatus(id,flags);
        }
        //获取路径
        String fileDirName = FileDirPath.getFileDirName();
        if(list!=null&&list.size()>0){
            for (int i=0;i<list.size();i++) {
                BOMFeedback feedback=list.get(i);
                String attachFilePath=fileDirName+File.separator+feedback.getFile();
                File start = new File(attachFilePath);
                String[] files =new String[]{};
                List attachList=new ArrayList();
                if(start.exists()) {
                    files= start.list();//获取该文件夹下的所有文件名字
                    if(files.length>=0){
                        for(int j=0;j<files.length;j++) {
                            attachList.add(feedback.getFile()+files[j]);
                        }
                    }
                }
                feedback.setAttachFiles(attachList);
            }
        }
        PageInfo pageInfo = new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"接收者反馈");
@@ -104,6 +155,7 @@
     * @param feedback
     * @return
     */
    @Transactional
    public Response confirmFeedback(BOMFeedback feedback) {
        DocUser user = ActionUtil.getUser();
        int userId = user.getId().intValue();
@@ -174,6 +226,15 @@
            int count=mapper.update(null,wrapper);
            bl=count>0;
            msg="接收者确认反馈";
            if(confirmStatus == 2){
                //解锁产品
                Integer productId = mapper.selectById(id).getProductId();
                Product product = productService.getById(productId);
                if(product!=null){
                    phisService.setpHistoryEnable(product.getParentCode(),product.getCustomCode(),-1,1,"问题反馈后"+ username +"确认不需要修改bom,系统执行产品解锁",DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime()));
                }
            }
        }
        return new Response().set(1,bl,msg);
    }
@@ -192,10 +253,16 @@
        //压缩包的路径及格式为: doc_file/feedback_bom/username_time.zip
        String username = ActionUtil.getUser().getName();
        long time = date.getTime();
        String feedbackZipPath = "feedback_bom" + File.separator + username + "_" + time+".zip";
        List<File> fileList = new LinkedList<>();
        //String feedbackZipPath = "feedback_bom" + File.separator + username + "_" + time+".zip";
        //List<File> fileList = new LinkedList<>();
        String rootFile = CommonUtil.getRootFile();
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String feedbackDirSuffix = "feedback_bom" + File.separator + username + File.separator + time + File.separator;
            String feedbackDir = rootFile + feedbackDirSuffix;
            File fileDir = new File(feedbackDir);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }
            for (int i = 0; i < multipartFileList.size(); i++) {
                MultipartFile multipartFile = multipartFileList.get(i);
                //存储文件
@@ -203,21 +270,19 @@
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String feedbackPath = "feedback_bom" + File.separator + fileName + "_" + time + suffix;
                File file = new File(rootFile + feedbackPath);
                if (!file.exists()) {
                    file.mkdirs();
                }
                String feedbackPath = feedbackDir + fileName + suffix;
                File file = new File(feedbackPath);
                multipartFile.transferTo(file);
                fileList.add(file);
                //fileList.add(file);
            }
            ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath)));
            feedback.setFile("doc_file" + File.separator + feedbackZipPath);
            //ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath)));
            feedback.setFile("doc_file" + File.separator + feedbackDirSuffix);
        }
        //删除已经被压缩的文件
        for (File file : fileList) {
            file.delete();
        }
        //for (File file : fileList) {
        //    file.delete();
        //}
        //保存
        feedback.setCreateTime(date);
        feedback.setConfirmStatus(0);
@@ -250,9 +315,25 @@
            }
        }
        String subject = "Bom问题反馈-"+senderName;
        String content = feedback.getContent();
        mailUtil.sendMailBatch(senderName,receiverMailList,subject,content);
        String subject = "【Bom问题反馈】-"+senderName;
        //邮件内容,添加产品的相关信息
        Product product = productService.getById(feedback.getProductId());
        String content ="产品料号:"+product.getParentCode() + "\n产品名称:"+product.getParentName() + "\n产品型号:"+product.getParentModel() + "\n版本时间:"+ DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime()) + "\n定制单号:"+product.getCustomCode() + "\n产品反馈内容:"+ feedback.getContent();
        MailDTO mailDTO = new MailDTO();
        mailDTO.setTitle(subject);
        mailDTO.setContent(content);
        mailDTO.setMailList(receiverMailList);
        mailService.sendMail(mailDTO);
        //mailUtil.sendMailBatch(senderName,receiverMailList,subject,content);
        //反馈时直接根据productid直接锁定
        //查询产品的信息
        QueryWrapper hisWrapper=new QueryWrapper();
        hisWrapper.eq("id",feedback.getProductId());
        hisWrapper.last("limit 1");
        ProductHistory phis=phisMapper.selectOne(hisWrapper);
        phisService.setpHistoryEnable(phis.getParentCode(),phis.getCustomCode(),phis.getVersion(),0,feedback.getContent(),ActionUtil.sdfwithALL.format(phis.getVersionTime()));
        return new Response().set(1,true,"反馈完成");
    }
    //根据文件路径下载
@@ -317,10 +398,43 @@
        }
        if(receiverMailList.size()>0) {
            String subject = "Bom问题反馈-" + senderName + ",并由" + appendUsername + "转发给您";
            String subject = "【Bom问题反馈】-" + senderName + ",由" + appendUsername + "转发给您";
            String content = feedback.getContent();
            mailUtil.sendMailBatch(senderName, receiverMailList, subject, content);
            MailDTO mailDTO = new MailDTO();
            mailDTO.setTitle(subject);
            mailDTO.setContent(content);
            mailDTO.setMailList(receiverMailList);
            mailService.sendMail(mailDTO);
            //mailUtil.sendMailBatch(senderName, receiverMailList, subject, content);
        }
        return new Response().setII(1,"追加反馈用户完成");
    }
    public Response getListPage(BOMFeedback feedback, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<BOMFeedback> list = mapper.getListPage(feedback);
        //获取路径
        String fileDirName = FileDirPath.getFileDirName();
        if(list!=null&&list.size()>0){
            for (int i=0;i<list.size();i++) {
                BOMFeedback fb=list.get(i);
                String attachFilePath=fileDirName+File.separator+fb.getFile();
                File start = new File(attachFilePath);
                String[] files =new String[]{};
                List attachList=new ArrayList();
                if(start.exists()) {
                    files= start.list();//获取该文件夹下的所有文件名字
                    if(files.length>=0){
                        for(int j=0;j<files.length;j++) {
                            attachList.add(fb.getFile()+files[j]);
                        }
                    }
                }
                fb.setAttachFiles(attachList);
            }
        }
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
}