whyclxw
2024-07-23 a2cb0eed5a0bb7cf9d5eb8afe74f4ba6836205b4
不良品录入
8个文件已添加
319 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/DefectiveProductsController.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/DefectiveProductsHistoryMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/DefectiveProductsMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/DefectiveProducts.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/DefectiveProductsHistory.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DefectiveProductsHistoryService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DefectiveProductsService.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DefectiveProductsMapper.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/DefectiveProductsController.java
New file
@@ -0,0 +1,33 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.pojo.BOMFeedback;
import com.whyc.pojo.DefectiveProducts;
import com.whyc.service.BOMFeedbakService;
import com.whyc.service.DefectiveProductsService;
import com.whyc.util.ActionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.mail.MessagingException;
import java.io.IOException;
import java.util.List;
@RestController
@Api(tags = "不良品管理")
@RequestMapping("defective")
public class DefectiveProductsController {
    @Autowired
    private DefectiveProductsService service;
    @ApiOperation("录入不良品信息")
    @PostMapping("addDefective")
    public Response addDefective(@RequestPart(required = false) List<MultipartFile> multipartFileList, @RequestParam String defectiveJson) throws IOException, MessagingException {
        DefectiveProducts defective= ActionUtil.getGson().fromJson(defectiveJson, DefectiveProducts.class);
        return service.addDefective(defective,multipartFileList);
    }
}
src/main/java/com/whyc/mapper/DefectiveProductsHistoryMapper.java
New file
@@ -0,0 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.DefectiveProductsHistory;
public interface DefectiveProductsHistoryMapper extends CustomMapper<DefectiveProductsHistory>{
}
src/main/java/com/whyc/mapper/DefectiveProductsMapper.java
New file
@@ -0,0 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.DefectiveProducts;
public interface DefectiveProductsMapper extends CustomMapper<DefectiveProducts>{
}
src/main/java/com/whyc/pojo/DefectiveProducts.java
New file
@@ -0,0 +1,71 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
 * 不良品表
 * </p>
 *
 * @author lxw
 * @since 2024-07-23
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_defective_products")
@ApiModel(value="DefectiveProducts对象", description="不良品表")
public class DefectiveProducts implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    @ApiModelProperty(value = "入库时间")
    private Date startTime;
    @ApiModelProperty(value = "厂商名称")
    private String provideName;
    @ApiModelProperty(value = "不良现象描述")
    private String content;
    @ApiModelProperty(value = "附件url")
    private String fileUrl;
    @ApiModelProperty(value = "型号")
    private String type;
    @ApiModelProperty(value = "提出者")
    private Integer senderId;
    @ApiModelProperty(value = "接受者")
    private String receiverIds;
    private String receiverNames;
    @ApiModelProperty(value = "状态0,1,2,3")
    private Integer confirmStatus;
    @ApiModelProperty(value = "总数")
    private Integer sumProduct;
    @ApiModelProperty(value = "不良产品数")
    private Integer badProduct;
    @ApiModelProperty(value = "备注")
    private String note;
}
src/main/java/com/whyc/pojo/DefectiveProductsHistory.java
New file
@@ -0,0 +1,56 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
 * 不良品过程表
 * </p>
 *
 * @author lxw
 * @since 2024-07-23
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_defective_products_history")
@ApiModel(value="DefectiveProductsHistory对象", description="不良品过程表")
public class DefectiveProductsHistory implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "num", type = IdType.AUTO)
    private Integer num;
    @ApiModelProperty(value = "不良品记录id")
    private Integer deftId;
    @ApiModelProperty(value = "记录时间")
    private Date recordTime;
    @ApiModelProperty(value = "接受者")
    private String receiverIds;
    private String receiverNames;
    @ApiModelProperty(value = "状态0,1,2,3")
    private Integer confirmStatus;
    @ApiModelProperty(value = "不良产品数")
    private Integer badProduct;
    @ApiModelProperty(value = "备注")
    private String note;
}
src/main/java/com/whyc/service/DefectiveProductsHistoryService.java
New file
@@ -0,0 +1,28 @@
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@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);
    }
}
src/main/java/com/whyc/service/DefectiveProductsService.java
New file
@@ -0,0 +1,114 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.MailDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.DefectiveProductsMapper;
import com.whyc.mapper.DocUserMapper;
import com.whyc.pojo.DefectiveProducts;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.ProductHistory;
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.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@Service
public class DefectiveProductsService {
    @Autowired(required = false)
    private DefectiveProductsMapper mapper;
    @Autowired
    private MailService mailService;
    @Resource
    private DocUserMapper userMapper;
    @Autowired
    private DocLogService logService;
    @Autowired
    private DefectiveProductsHistoryService defectiveHisService;
    //录入不良品信息
    public Response addDefective(DefectiveProducts defective, List<MultipartFile> multipartFileList) throws IOException {
        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 rootFile = CommonUtil.getRootFile();
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String defectiveDirSuffix = "defective" + File.separator + username + File.separator + time + 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);
                multipartFile.transferTo(file);
            }
            //ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath)));
            defective.setFileUrl("doc_file" + File.separator + defectiveDirSuffix);
        }
        //保存
        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){
            if(docUser.getId().intValue() == senderId){
                senderName = docUser.getName();
                break;
            }
        }
        for (String receiverId:receiverIdsSplit){
            for (DocUser docUser:docUsers){
                if(docUser.getId().intValue() == Integer.parseInt(receiverId)){
                    String mail = docUser.getMail();
                    if(mail!=null && !mail.isEmpty()) {
                        receiverMailList.add(mail);
                    }
                    break;
                }
            }
        }
        String subject = "【不良品记录】-"+senderName;
        String content = defective.getContent();
        MailDTO mailDTO = new MailDTO();
        mailDTO.setTitle(subject);
        mailDTO.setContent(content);
        mailDTO.setMailList(receiverMailList);
        mailService.sendMail(mailDTO);
        //记录处理过程
        defectiveHisService.addHis(defective);
       return new Response().set(1,true,"不良品操作完成");
    }
}
src/main/resources/mapper/DefectiveProductsMapper.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.whyc.mapper.DefectiveProductsMapper">
</mapper>