src/main/java/com/whyc/controller/DefectiveProductsController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/dto/DefectiveDto.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/mapper/DefectiveProductsMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/pojo/DefectiveProducts.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/DefectiveProductsService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/webSocket/DefectiveSocket.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/DefectiveProductsMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/whyc/controller/DefectiveProductsController.java
@@ -3,6 +3,7 @@ import com.whyc.dto.Response; import com.whyc.pojo.BOMFeedback; import com.whyc.pojo.DefectiveProducts; import com.whyc.pojo.DefectiveProductsHistory; import com.whyc.service.BOMFeedbakService; import com.whyc.service.DefectiveProductsService; import com.whyc.util.ActionUtil; @@ -30,4 +31,10 @@ DefectiveProducts defective= ActionUtil.getGson().fromJson(defectiveJson, DefectiveProducts.class); return service.addDefective(defective,multipartFileList); } @ApiOperation("处理不良品") @PostMapping("updateDefective") public Response updateDefective(@RequestBody DefectiveProductsHistory defectiveHis) throws IOException, MessagingException { return service.updateDefective(defectiveHis); } } src/main/java/com/whyc/dto/DefectiveDto.java
New file @@ -0,0 +1,61 @@ package com.whyc.dto; import java.util.Date; public class DefectiveDto { private Date startTime; private Date endTime; private Integer senderId; private Integer confirmStatus; private Integer pageCurr; private Integer pageSize; public Date getStartTime() { return startTime; } public void setStartTime(Date startTime) { this.startTime = startTime; } public Date getEndTime() { return endTime; } public void setEndTime(Date endTime) { this.endTime = endTime; } public Integer getSenderId() { return senderId; } public void setSenderId(Integer senderId) { this.senderId = senderId; } public Integer getConfirmStatus() { return confirmStatus; } public void setConfirmStatus(Integer confirmStatus) { this.confirmStatus = confirmStatus; } public Integer getPageCurr() { return pageCurr; } public void setPageCurr(Integer pageCurr) { this.pageCurr = pageCurr; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } } src/main/java/com/whyc/mapper/DefectiveProductsMapper.java
@@ -1,6 +1,15 @@ package com.whyc.mapper; import com.whyc.dto.DefectiveDto; import com.whyc.pojo.DefectiveProducts; import org.apache.ibatis.annotations.Param; import java.util.Date; import java.util.List; public interface DefectiveProductsMapper extends CustomMapper<DefectiveProducts>{ //不良品首页推送 List<DefectiveProducts> getDefectiveLimit(@Param("dto")DefectiveDto defectiveDto); } src/main/java/com/whyc/pojo/DefectiveProducts.java
@@ -1,6 +1,7 @@ package com.whyc.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; @@ -11,6 +12,7 @@ import java.io.Serializable; import java.util.Date; import java.util.List; /** * <p> @@ -37,6 +39,9 @@ @ApiModelProperty(value = "厂商名称") private String provideName; @ApiModelProperty(value = "产品名称") private String productName; @ApiModelProperty(value = "不良现象描述") private String content; @@ -67,5 +72,8 @@ @ApiModelProperty(value = "备注") private String note; @TableField(exist = false) private List<DefectiveProductsHistory> hisList; } src/main/java/com/whyc/service/DefectiveProductsService.java
@@ -1,11 +1,15 @@ package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.whyc.dto.DefectiveDto; 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.DefectiveProductsHistory; import com.whyc.pojo.DocUser; import com.whyc.pojo.ProductHistory; import com.whyc.util.ActionUtil; @@ -67,8 +71,11 @@ //ZipUtils.toZip(fileList,new FileOutputStream(new File(rootFile+feedbackZipPath))); defective.setFileUrl("doc_file" + File.separator + defectiveDirSuffix); } //保存 defective.setStartTime(date); if(defective.getStartTime()==null){ //保存 defective.setStartTime(date); } mapper.insert(defective); //发送邮件 String receiverIds = defective.getReceiverIds(); @@ -111,4 +118,17 @@ defectiveHisService.addHis(defective); return new Response().set(1,true,"不良品操作完成"); } //不良品首页推送 public Response getDefectiveLimit(DefectiveDto defectiveDto) { PageHelper.startPage(defectiveDto.getPageCurr(),defectiveDto.getPageSize()); List<DefectiveProducts> list=mapper.getDefectiveLimit(defectiveDto); PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list!=null,pageInfo,"不良品首页推送"); } //处理不良品 public Response updateDefective(DefectiveProductsHistory defectiveHis) { return new Response().set(1,true); } } src/main/java/com/whyc/webSocket/DefectiveSocket.java
New file @@ -0,0 +1,105 @@ package com.whyc.webSocket; import com.whyc.config.WebSocketConfig; import com.whyc.dto.DefectiveDto; import com.whyc.dto.MaterialSocketDto; import com.whyc.dto.Response; import com.whyc.pojo.DefectiveProducts; import com.whyc.service.DefectiveProductsService; import com.whyc.service.MaterialService; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.util.HashMap; import java.util.Map; @Component @ServerEndpoint(value = "/defective",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) public class DefectiveSocket { private Session session; private static final int executeTime = 2000; private Thread thread; private volatile boolean runFlag=true; private volatile Map<String,Thread> threadMap = new HashMap<>(); private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); private static DefectiveProductsService defectiveService; @Autowired private void setDefectiveService(DefectiveProductsService defectiveService){ DefectiveSocket.defectiveService=defectiveService; } @OnOpen public void onOpen(Session session){ this.session=session; } @OnMessage public void onMessage(Session session, String message){ this.session=session; DefectiveDto defectiveDto= ActionUtil.getGson().fromJson(message, DefectiveDto.class); thread = new Thread("Thread_Defective") { @Override public void run() { while (runFlag && !isInterrupted()) { Thread thread = currentThread(); threadFlagMap.put(thread.getId(), true); try { Response res = defectiveService.getDefectiveLimit(defectiveDto); if (session.isOpen()) { //推送信息 synchronized (session) { session.getBasicRemote().sendObject(res); } threadFlagMap.put(thread.getId(), false); } sleep(executeTime); //} catch (IOException | InterruptedException | EncodeException e) { } catch (Exception e) { interrupt(); } } } }; thread.start(); threadFlagMap.put(thread.getId(),true); //停止老的socket线程 Thread threadBefore = threadMap.get(session.getId()); if(threadBefore !=null && threadBefore.isAlive()){ while (threadFlagMap.get(threadBefore.getId())){ } threadBefore.interrupt(); } //将线程存储,便于调用定位 threadMap.put(session.getId(), this.thread); } @OnClose public void onClose(CloseReason closeReason){ System.err.println("closeReason = " + closeReason); runFlag = false; if (thread != null && thread.isAlive()) { thread.interrupt(); } threadMap.remove(session.getId()); } @OnError public void onError(Throwable error) { error.printStackTrace(); if (thread != null && thread.isAlive()) { thread.interrupt(); } threadMap.remove(session.getId()); } } src/main/resources/mapper/DefectiveProductsMapper.xml
@@ -1,5 +1,48 @@ <?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"> <resultMap id="defectiveList" type="defectiveProducts"> <id property="id" column="id"></id> <result property="startTime" column="start_time"></result> <result property="provideName" column="provide_name"></result> <result property="content" column="content"></result> <result property="fileUrl" column="file_url"></result> <result property="type" column="type"></result> <result property="senderId" column="sender_id"></result> <result property="receiverIds" column="receiver_ids"></result> <result property="receiverNames" column="receiver_names"></result> <result property="confirmStatus" column="confirm_status"></result> <result property="sumProduct" column="sum_product"></result> <result property="badProduct" column="bad_product"></result> <result property="note" column="note"></result> <collection property="hisList" javaType="java.util.ArrayList" ofType="com.whyc.pojo.DefectiveProductsHistory" column="{deftId=id}" select="selectDefectiveHis"> </collection> </resultMap> <select id="getDefectiveLimit" resultMap="defectiveList"> select * from tb_defective_products <where> <if test="dto.startTime!=null"> and start_time>=#{dto.startTime} </if> <if test="dto.endTime!=null"> and start_time<=#{dto.endTime} </if> <if test="dto.senderId!=null"> and sender_id=#{dto.senderId} </if> <if test="dto.confirmStatus!=null"> and confirm_status=#{confirmStatus} </if> </where> order by start_time desc </select> <select id="selectDefectiveHis"> select * from tb_defective_products_history where deft_id=#{deftId} order by record_time desc </select> </mapper>