Explorar o código

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java
%!s(int64=5) %!d(string=hai) anos
pai
achega
06e7c6db0a

+ 6 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/constant/Constant.java

@@ -58,6 +58,12 @@ public class Constant {
     public static final String PART_FILE_3D = "3D";//零件3d
     public static final Double ELECTRICITY_THRESHOLD = 0.2;//电量阈值
     public static final Double TEMPERATURE_THRESHOLD = 15.0;//温度阈值
+    public static final String ELECTRICITY_TYPE = "电量告警";//告警类1 电量告警
+    public static final String ELECTRICITY_CONTENT= "电量过低";//告警内容 电量过低
+    public static final String TEMPERATURE_TYPE = "温度告警";//告警类2 温度告警
+    public static final String TEMPERATURE_CONTENT = "温度过高";//告警类2 温度过高
+    public static final String MAIN_TAIN_TYPE = "保养计划";//告警类2 温度过高
+    public static final String MAIN_TAIN_CONTENT = "模具运行次数已达";//保养内容
 //    public static void main(String[] args){
 //        System.out.println("222222");
 //        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="

+ 14 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldEquipmentController.java

@@ -129,5 +129,19 @@ public class MouldEquipmentController {
         HttpRespMsg msg = mouldEquipmentService.MouldEquipmentAlarm();
         return msg;
     }
+
+    /**
+     * 给模具更换云模盒时所获取的设备列表
+     * 参数 token 用户唯一身份凭证 mould 模具id
+     * @return
+     */
+    @ApiOperation("给模具更换云模盒时所获取的设备列表")
+    @RequestMapping("/getEquipmentListByOldMouldAndUser")
+    @ResponseBody
+    public HttpRespMsg getEquipmentListByOldMouldAndUser(UserVO userVO){
+        HttpRespMsg msg = new HttpRespMsg();
+        msg = mouldEquipmentService.getEquipmentListByOldMouldAndUser(userVO);
+        return msg;
+    }
 }
 

+ 33 - 18
cloud-model/src/main/java/com/hssx/cloudmodel/entity/MouldEquipment.java

@@ -103,6 +103,39 @@ public class MouldEquipment extends Model<MouldEquipment> {
     @TableField("agent")
     private String agent;
 
+    public Integer getStage() {
+        return stage;
+    }
+
+    public void setStage(Integer stage) {
+        this.stage = stage;
+    }
+
+    /**
+     * 状态,0-正常,1-温度过高,2-电量过低
+     */
+    @TableField("stage")
+    private Integer stage;
+
+    @Override
+    public String toString() {
+        return "MouldEquipment{" +
+                "id=" + id +
+                ", equipmentName='" + equipmentName + '\'' +
+                ", startTime=" + startTime +
+                ", endTime=" + endTime +
+                ", useLife=" + useLife +
+                ", belongCompanyId=" + belongCompanyId +
+                ", equipmentNo='" + equipmentNo + '\'' +
+                ", isUse=" + isUse +
+                ", hillNumber='" + hillNumber + '\'' +
+                ", lng=" + lng +
+                ", lat=" + lat +
+                ", temperature=" + temperature +
+                ", agent='" + agent + '\'' +
+                ", stage=" + stage +
+                '}';
+    }
 
     public Integer getId() {
         return id;
@@ -213,22 +246,4 @@ public class MouldEquipment extends Model<MouldEquipment> {
         return this.id;
     }
 
-    @Override
-    public String toString() {
-        return "MouldEquipment{" +
-        "id=" + id +
-        ", equipmentName=" + equipmentName +
-        ", startTime=" + startTime +
-        ", endTime=" + endTime +
-        ", useLife=" + useLife +
-        ", belongCompanyId=" + belongCompanyId +
-        ", equipmentNo=" + equipmentNo +
-        ", isUse=" + isUse +
-        ", hillNumber=" + hillNumber +
-        ", lng=" + lng +
-        ", lat=" + lat +
-        ", temperature=" + temperature +
-        ", agent=" + agent +
-        "}";
-    }
 }

+ 1 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/entity/vo/MouldVO.java

@@ -28,4 +28,5 @@ public class MouldVO extends Mould {
     private Integer managerId;
     private Double lng;
     private Double lat;
+    private Integer stage;
 }

+ 2 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldEquipmentService.java

@@ -30,4 +30,6 @@ public interface MouldEquipmentService extends IService<MouldEquipment> {
     HttpRespMsg MouldEquipmentAlarm();
 
     HttpRespMsg importMouldEquipmentExcel(MultipartFile file, UserVO userVO);
+
+    HttpRespMsg getEquipmentListByOldMouldAndUser(UserVO userVO);
 }

+ 57 - 12
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldEquipmentServiceImpl.java

@@ -1,5 +1,7 @@
 package com.hssx.cloudmodel.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -10,8 +12,8 @@ import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.mapper.*;
 import com.hssx.cloudmodel.service.MouldEquipmentService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.hssx.cloudmodel.util.HttpRespMsg;
-import com.hssx.cloudmodel.util.PageUtil;
+import com.hssx.cloudmodel.util.*;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
@@ -22,14 +24,14 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -148,13 +150,27 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
     @Override
     public HttpRespMsg MouldEquipmentAlarm() {
         HttpRespMsg msg = new HttpRespMsg();
+        String token = GainTokenUtil.getToken();
         List<MouldEquipment> mouldEquipments = mouldEquipmentMapper.selectList(new QueryWrapper<MouldEquipment>().eq("is_use", 1));
         for (MouldEquipment mouldEquipment : mouldEquipments) {
             Mould mould = mouldMapper.selectOne(new QueryWrapper<Mould>().eq("equipment_id", mouldEquipment.getId()));
+            Project project = projectMapper.selectById(mould.getProjectId());
+            List<Integer> uids = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("project_id", project.getId())).stream().map(ProjectUser::getUserId).collect(Collectors.toList());
+            uids.add(project.getManagerId());
+            uids.add(project.getCreatorId());
+            uids.add(-1);
+            List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", uids).isNotNull("openid").eq("is_disable",1));
             if (Constant.ELECTRICITY_THRESHOLD >= Double.parseDouble(mouldEquipment.getHillNumber())) {
+                mouldEquipment.setStage(2);
+                mouldEquipmentMapper.updateById(mouldEquipment);
                 //公众号的推送to do
-
-                Project project = projectMapper.selectById(mould.getProjectId());
+                userList.forEach(u ->{
+                    try {
+                        WechatTemplateUtil.sendEmergencyTemplateMessage(u.getOpenid(),mouldEquipment.getEquipmentName(),Constant.ELECTRICITY_TYPE,Constant.ELECTRICITY_CONTENT,token);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                });
                 //查询到参与该项目的人
                 List<Integer> userIds = new ArrayList<>();
                 userIds.add(-1);
@@ -203,9 +219,16 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
                 }
             }
             if (Constant.TEMPERATURE_THRESHOLD <= mouldEquipment.getTemperature()) {
+                mouldEquipment.setStage(1);
+                mouldEquipmentMapper.updateById(mouldEquipment);
                 //公众号的推送to do
-
-                Project project = projectMapper.selectById(mould.getProjectId());
+                userList.forEach(u ->{
+                    try {
+                        WechatTemplateUtil.sendEmergencyTemplateMessage(u.getOpenid(),mouldEquipment.getEquipmentName(),Constant.TEMPERATURE_TYPE,Constant.TEMPERATURE_CONTENT,token);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                });
                 //查询到参与该项目的人
                 List<Integer> userIds = new ArrayList<>();
                 userIds.add(-1);
@@ -330,6 +353,26 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
         return msg;
     }
 
+    @Override
+    public HttpRespMsg getEquipmentListByOldMouldAndUser(UserVO userVO) {
+        HttpRespMsg msg = new HttpRespMsg();
+        User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
+        if(user==null){
+            msg.setError("用户不存在或者未登录");
+        }else{
+            Mould mould = mouldMapper.selectById(userVO.getMouldId());
+            User admin = userMapper.selectById(projectMapper.selectById(mould.getProjectId()).getCreatorId());
+            List<Integer> mouldsEquipmentIds = mouldMapper.selectList(new QueryWrapper<Mould>().eq("company_id", admin.getCompanyId()).isNotNull("equipment_id")).stream().map(Mould::getEquipmentId).collect(Collectors.toList());
+            mouldsEquipmentIds.add(-1);
+            List<Integer> equipmentIds = mouldEquipmentMapper.selectList(new QueryWrapper<MouldEquipment>().eq("belong_company_id", admin.getCompanyId())).stream().map(MouldEquipment::getId).collect(Collectors.toList());
+            equipmentIds.add(-1);
+            equipmentIds.removeAll(mouldsEquipmentIds);//把已经使用的设备剔除
+            List<MouldEquipmentVO> list = mouldEquipmentMapper.getListByCompanyId(admin.getCompanyId(), equipmentIds);
+            msg.data = list;
+        }
+        return msg;
+    }
+
     /**
      * 输入流转file
      *
@@ -350,4 +393,6 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
             e.printStackTrace();
         }
     }
+
+
 }

+ 24 - 95
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -541,24 +541,24 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
             for (Integer id : ids) {
                 Mould mould = mouldMapper.selectById(id);
                 if (0 == userVO.getDwgType()) {
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3));
-                }else if(1 == userVO.getDwgType()){
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3));
+                } else if (1 == userVO.getDwgType()) {
                     //模具2D
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNull("part_id").eq("dwg_type",0).eq("blong_type",0));
-                }else if(2 == userVO.getDwgType()){
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNull("part_id").eq("dwg_type", 0).eq("blong_type", 0));
+                } else if (2 == userVO.getDwgType()) {
                     //模具3D
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNull("part_id").eq("dwg_type",1).eq("blong_type",0));
-                }else if(3 == userVO.getDwgType()){
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNull("part_id").eq("dwg_type", 1).eq("blong_type", 0));
+                } else if (3 == userVO.getDwgType()) {
                     //零件2D
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNotNull("part_id").eq("dwg_type",0).eq("blong_type",1));
-                }else if(4 == userVO.getDwgType()){
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNotNull("part_id").eq("dwg_type", 0).eq("blong_type", 1));
+                } else if (4 == userVO.getDwgType()) {
                     //零件3D
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNotNull("part_id").eq("dwg_type",0).eq("blong_type",1));
-                }else{
-                     mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).eq("blong_type",3));
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).isNotNull("part_id").eq("dwg_type", 0).eq("blong_type", 1));
+                } else {
+                    mouldFiles = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", id).eq("state", 3).eq("blong_type", 3));
                 }
 //                feedBackDirectMultiDownload(request, response, downloadPath, mould, mouldFiles, path);
-                String filePath =  this.download(downloadPath, mould, mouldFiles, path,currentUser);
+                String filePath = this.download(downloadPath, mould, mouldFiles, path, currentUser);
                 msg.data = filePath;
             }
         }
@@ -637,6 +637,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                 dynamics.setOperatorId(user.getId());
                 dynamics.setOperatorName(user.getUsername());
                 dynamics.setMouldId(userVO.getMouldId());
+                dynamics.setFileId(partFile.getId());
                 mouldOperationDynamicsMapper.insert(dynamics);
 //                }
                 msg.data = partFile;
@@ -740,11 +741,11 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
         return msg;
     }
 
-
-    public String download(String downloadPath, Mould vo, List<MouldFile> mouldFiles, String oldFilePath, User user){
+    //生成.zip文件
+    public String download(String downloadPath, Mould vo, List<MouldFile> mouldFiles, String oldFilePath, User user) {
         //需要压缩的文件--包括文件地址和文件名
         // 要生成的压缩文件地址和文件名称
-        String desPath = oldFilePath+vo.getModelNo() + vo.getModelName()+".zip";
+        String desPath = oldFilePath + vo.getModelNo() + vo.getModelName() + ".zip";
         File zipFile = new File(desPath);
         ZipOutputStream zipStream = null;
         FileInputStream zipSource = null;
@@ -752,8 +753,8 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
         try {
             //构造最终压缩包的输出流
             zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
-            if(mouldFiles.size()>0){
-                for(int i =0;i<mouldFiles.size();i++){
+            if (mouldFiles.size() > 0) {
+                for (int i = 0; i < mouldFiles.size(); i++) {
                     //添加下载动态
                     MouldOperationDynamics mod = new MouldOperationDynamics();
                     mod.setApplicantId(mouldFiles.get(i).getUplodtorId());
@@ -766,7 +767,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     mod.setMouldId(vo.getId());
                     mod.setBelongType(mouldFiles.get(i).getBlongType());
                     mouldOperationDynamicsMapper.insert(mod);
-                    File file = new File(oldFilePath.substring(0, oldFilePath.length() - "/upload/".length())+mouldFiles.get(i).getFileUrl());
+                    File file = new File(oldFilePath.substring(0, oldFilePath.length() - "/upload/".length()) + mouldFiles.get(i).getFileUrl());
                     //将需要压缩的文件格式化为输入流
                     zipSource = new FileInputStream(file);
                     //压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
@@ -778,8 +779,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     int read = 0;
                     //创建读写缓冲区
                     byte[] buf = new byte[1024 * 10];
-                    while((read = bufferStream.read(buf, 0, 1024 * 10)) != -1)
-                    {
+                    while ((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) {
                         zipStream.write(buf, 0, read);
                     }
                 }
@@ -789,85 +789,14 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
         } finally {
             //关闭流
             try {
-                if(null != bufferStream) bufferStream.close();
-                if(null != zipStream) zipStream.close();
-                if(null != zipSource) zipSource.close();
+                if (null != bufferStream) bufferStream.close();
+                if (null != zipStream) zipStream.close();
+                if (null != zipSource) zipSource.close();
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }
-        return "/upload/"+vo.getModelNo() + vo.getModelName()+".zip";
+        return "/upload/" + vo.getModelNo() + vo.getModelName() + ".zip";
     }
 
-    public Map<String, Object> feedBackDirectMultiDownload(HttpServletRequest request, HttpServletResponse response, String downloadPath, Mould vo, List<MouldFile> mouldFiles, String oldFilePath) throws IOException {
-        //压缩文件初始设置
-        String path = downloadPath;
-        String base_name = vo.getModelNo() + vo.getModelName();
-        String fileZip = base_name + ".zip"; // 拼接zip文件
-        String filePath = path + "\\" + fileZip;//之后用来生成zip文件
-
-        //mouldFiles为根据前台传过来的信息,通过数据库查询所得出的pdf文件路径集合(具体到后缀),此处省略
-        File[] files = new File[mouldFiles.size()];//
-        for (int i = 0; i < mouldFiles.size(); i++) {
-            files[i] = new File(mouldFiles.get(i).getFileUrl());//获取所有需要下载的文件
-        }
-        // 创建临时压缩文件
-        try {
-            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
-            ZipOutputStream zos = new ZipOutputStream(bos);
-            ZipEntry ze = null;
-            for (int i = 0; i < files.length; i++) {//将所有需要下载的pdf文件都写入临时zip文件
-                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(files[i]));
-                ze = new ZipEntry(mouldFiles.get(i).getFileName());
-                zos.putNextEntry(ze);
-                int s = -1;
-                while ((s = bis.read()) != -1) {
-                    zos.write(s);
-                }
-                bis.close();
-            }
-            zos.flush();
-            zos.close();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        //以上,临时压缩文件创建完成
-        //进行浏览器下载
-        //获得浏览器代理信息
-        final String userAgent = request.getHeader("USER-AGENT");
-        //判断浏览器代理并分别设置响应给浏览器的编码格式
-        String finalFileName = null;
-        if (StringUtils.contains(userAgent, "MSIE") || StringUtils.contains(userAgent, "Trident")) {//IE浏览器
-            finalFileName = URLEncoder.encode(fileZip, "UTF8");
-            System.out.println("IE浏览器");
-        } else if (StringUtils.contains(userAgent, "Mozilla")) {//google,火狐浏览器
-            finalFileName = new String(fileZip.getBytes(), "ISO8859-1");
-        } else {
-            finalFileName = URLEncoder.encode(fileZip, "UTF8");//其他浏览器
-        }
-        response.setContentType("application/x-download");//告知浏览器下载文件,而不是直接打开,浏览器默认为打开
-        response.setHeader("Content-Disposition", "attachment;filename=\"" + finalFileName + "\"");//下载文件的名称
-
-        ServletOutputStream servletOutputStream = response.getOutputStream();
-        DataOutputStream temps = new DataOutputStream(
-                servletOutputStream);
-
-        DataInputStream in = new DataInputStream(new FileInputStream(filePath));//浏览器下载文件的路径
-        byte[] b = new byte[2048];
-        File reportZip = new File(filePath);//之后用来删除临时压缩文件
-        try {
-            while ((in.read(b)) != -1) {
-                temps.write(b);
-            }
-            temps.flush();
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (temps != null) temps.close();
-            if (in != null) in.close();
-            if (reportZip != null) reportZip.delete();//删除服务器本地产生的临时压缩文件
-            servletOutputStream.close();
-        }
-        return null;
-    }
 }

+ 20 - 130
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldServiceImpl.java

@@ -14,10 +14,7 @@ import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.mapper.*;
 import com.hssx.cloudmodel.service.MouldService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.hssx.cloudmodel.util.HttpKit;
-import com.hssx.cloudmodel.util.HttpRespMsg;
-import com.hssx.cloudmodel.util.ListUtil;
-import com.hssx.cloudmodel.util.WechatTemplateMessage;
+import com.hssx.cloudmodel.util.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.springframework.beans.BeanUtils;
@@ -105,7 +102,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                 if (oldModelNo.indexOf("-") == -1) {
                     newMouldNo.append(oldModelNo).append("-").append("1");
                 } else {
-                    int i = Integer.parseInt(oldModelNo.substring(oldModelNo.length()-1));
+                    int i = Integer.parseInt(oldModelNo.substring(oldModelNo.length() - 1));
                     i++;
                     newMouldNo.append(oldModelNo.substring(0, oldModelNo.length() - 1)).append(i + "");
                 }
@@ -246,7 +243,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                     map.put("download", 1);
                     map.put("view", 1);
                     map.put("approve", approve);
-                }else {
+                } else {
                     //该项目的参与人
                     Integer update = 0;
                     Integer download = 0;
@@ -282,6 +279,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         HttpRespMsg msg = new HttpRespMsg();
         //查询所有被分配到项目的模具
         List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>().isNotNull("project_id").isNotNull("maintain_count"));
+        String token = GainTokenUtil.getToken();
         for (Mould mould : moulds) {
             List<Integer> counts = ListUtil.convertIntegerIdsArrayToList(mould.getMaintainCount());
             Collections.sort(counts);
@@ -293,6 +291,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                     }
                 }
             }
+            final Integer sumCount = noticeCount;
             //添加通知消息
             Project project = projectMapper.selectById(mould.getProjectId());
             if (noticeCount != 0) {
@@ -301,13 +300,19 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                 m.setId(mould.getId());
                 m.setIsMaintain(1);
                 mouldMapper.updateById(m);
-//                //提示保养,向模具资产方人员公众号推送消息
-//                User user = userMapper.selectOne(new QueryWrapper<User>().eq("parent_id", Constant.SYS_ID).eq("company_id", mould.getCompanyId()));
-//                MouldEquipmentVO mouldEquipmentVO = new MouldEquipmentVO();
-//                mouldEquipmentVO.setPlanType(Constant.PLAN_TYPE);
-//                mouldEquipmentVO.setArea(mould.getArea());
-//                mouldEquipmentVO.setName(mould.getModelName());
-//                msg = sendMaintainTemplateMessage(Constant.MAINTAIN_NOTICE_TEMPLATE_ID, user.getOpenid(), Constant.WECHAT_APPID, Constant.WECHAT_SECRET, mouldEquipmentVO);
+                List<Integer> uids = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("project_id", project.getId())).stream().map(ProjectUser::getUserId).collect(Collectors.toList());
+                uids.add(project.getManagerId());
+                uids.add(project.getCreatorId());
+                uids.add(-1);
+                List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", uids).isNotNull("openid").eq("is_disable", 1));
+                //公众号的推送to do
+                userList.forEach(u ->{
+                    try {
+                        WechatTemplateUtil.sendMaintainTemplateMessage(u.getOpenid(),mould.getModelNo()+"-"+mould.getModelName(),Constant.MAIN_TAIN_TYPE,Constant.MAIN_TAIN_CONTENT +sumCount+"次数",token);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                });
                 //添加通知消息
                 //查询到参与该项目的人
                 List<Integer> userIds = new ArrayList<>();
@@ -343,7 +348,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                 } else {
                     newsNotice.setNoticeType(Constant.MAINTAIN_TYPE);
                     newsNotice.setProjectId(project.getId());
-                    newsNotice.setProjectName(project.getProjectName()+"-"+mould.getModelName());
+                    newsNotice.setProjectName(project.getProjectName() + "-" + mould.getModelName());
                     newsNotice.setRefId(mould.getId());
                     newsNotice.setContent(Constant.MAIN_TAIN_NOTICE);
                     newsNoticeMapper.insert(newsNotice);
@@ -389,7 +394,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
                 } else {
                     newsNotice.setNoticeType(Constant.MAINTAIN_TYPE);
                     newsNotice.setProjectId(project.getId());
-                    newsNotice.setProjectName(project.getProjectName()+"-"+mould.getModelName());
+                    newsNotice.setProjectName(project.getProjectName() + "-" + mould.getModelName());
                     newsNotice.setRefId(mould.getId());
                     newsNotice.setContent(Constant.SCRAP_NOTICE);
                     newsNoticeMapper.insert(newsNotice);
@@ -554,119 +559,4 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         }
         return msg;
     }
-
-    //告警模板推送通用接口
-
-    /**
-     * templateId 模板id,touserOpenId 被推送者的openId,appId微信公众号的appId
-     * firstData 推送标题
-     */
-    public HttpRespMsg sendEmergencyTemplateMessage(String templateId, String touserOpenId, String appId, String
-            secret, MouldEquipmentVO mouldEquipmentVO) throws Exception {
-        HttpRespMsg msg = new HttpRespMsg();
-        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-                + appId + "&secret=" + secret;
-        String resp;
-        String resp1;
-        resp1 = HttpKit.get(url, true);
-        resp1 = StringEscapeUtils.unescapeJava(resp1);
-        JSONObject json = (JSONObject) JSON.parse(resp1);
-        // 获取值赋值给全局变量
-        if (!json.containsKey("errcode")) {
-            String newAccessToken = json.getString("access_token");
-            String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
-                    + newAccessToken;
-            WechatTemplateMessage wechat = new WechatTemplateMessage();
-            wechat.setTemplate_id(templateId);
-            wechat.setTouser(touserOpenId);
-            wechat.setAppid(appId);
-            Map<String, Map<String, String>> data = new HashMap<>();
-            Map<String, String> first = new HashMap<>();
-            Map<String, String> value1 = new HashMap<>();
-            Map<String, String> value2 = new HashMap<>();
-            Map<String, String> value3 = new HashMap<>();
-            Map<String, String> value4 = new HashMap<>();
-            Map<String, String> remark = new HashMap<>();
-            // 推送信息主体
-            first.put("value", "告警通知");//firstData推送标题
-            data.put("first", first);
-            value1.put("value", mouldEquipmentVO.getEquipmentName());
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-            data.put("keyword1", value1);
-            value2.put("value", mouldEquipmentVO.getEmergencyType());
-            data.put("keyword2", value2);
-            value3.put("value", sdf.format(new Date()));
-            data.put("keyword3", value3);
-            value4.put("value", mouldEquipmentVO.getEmergencyContent());
-            data.put("keyword4", value4);
-            remark.put("value", "请尽快检查该设备");
-            data.put("remark", remark);
-            wechat.setData(data);
-            String jsonString = JSONObject.toJSONString(wechat);
-            // System.out.println("jsonString"+jsonString);
-            resp = HttpKit.post(url1, jsonString);
-            // System.out.println("resp0"+resp);
-            resp = StringEscapeUtils.unescapeJava(resp);
-            // System.out.println("resp"+resp);
-            json = (JSONObject) JSON.parse(resp);
-        }
-        return msg;
-    }
-    //保养
-
-    /**
-     * templateId 模板id,touserOpenId 被推送者的openId,appId微信公众号的appId
-     * firstData 推送标题
-     */
-    public HttpRespMsg sendMaintainTemplateMessage(String templateId, String touserOpenId, String appId, String
-            secret, MouldEquipmentVO mouldEquipmentVO) throws Exception {
-        HttpRespMsg msg = new HttpRespMsg();
-        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-                + appId + "&secret=" + secret;
-        String resp;
-        String resp1;
-        resp1 = HttpKit.get(url, true);
-        resp1 = StringEscapeUtils.unescapeJava(resp1);
-        JSONObject json = (JSONObject) JSON.parse(resp1);
-        // 获取值赋值给全局变量
-        if (!json.containsKey("errcode")) {
-            String newAccessToken = json.getString("access_token");
-            String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
-                    + newAccessToken;
-            WechatTemplateMessage wechat = new WechatTemplateMessage();
-            wechat.setTemplate_id(templateId);
-            wechat.setTouser(touserOpenId);
-            wechat.setAppid(appId);
-            Map<String, Map<String, String>> data = new HashMap<>();
-            Map<String, String> first = new HashMap<>();
-            Map<String, String> value1 = new HashMap<>();
-            Map<String, String> value2 = new HashMap<>();
-            Map<String, String> value3 = new HashMap<>();
-            Map<String, String> value4 = new HashMap<>();
-            Map<String, String> remark = new HashMap<>();
-            // 推送信息主体
-            first.put("value", "你好,你有新的保养通知");//firstData推送标题
-            data.put("first", first);
-            value1.put("value", mouldEquipmentVO.getEquipmentName());
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
-            data.put("keyword1", value1);
-            value2.put("value", mouldEquipmentVO.getArea());
-            data.put("keyword2", value2);
-            value3.put("value", sdf.format(new Date()));
-            data.put("keyword3", value3);
-            value4.put("value", mouldEquipmentVO.getPlanType());
-            data.put("keyword4", value4);
-            remark.put("value", "模具初始模次不满足运行了");
-            data.put("remark", remark);
-            wechat.setData(data);
-            String jsonString = JSONObject.toJSONString(wechat);
-            // System.out.println("jsonString"+jsonString);
-            resp = HttpKit.post(url1, jsonString);
-            // System.out.println("resp0"+resp);
-            resp = StringEscapeUtils.unescapeJava(resp);
-            // System.out.println("resp"+resp);
-            json = (JSONObject) JSON.parse(resp);
-        }
-        return msg;
-    }
 }

+ 35 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/GainTokenUtil.java

@@ -0,0 +1,35 @@
+package com.hssx.cloudmodel.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.hssx.cloudmodel.constant.Constant;
+import org.apache.commons.lang3.StringEscapeUtils;
+
+/**
+ * Author: 吴涛涛 cuiyi@itany.com
+ * Date : 2019 - 08 - 29 14:55
+ * Description:<描述>
+ * Version: 1.0
+ */
+public class GainTokenUtil {
+
+    public static String getToken() {
+        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
+                + Constant.WECHAT_APPID + "&secret=" + Constant.WECHAT_SECRET;
+        String resp1;
+        String newAccessToken="";
+        try {
+            resp1 = HttpKit.get(url, true);
+            resp1 = StringEscapeUtils.unescapeJava(resp1);
+            JSONObject json = (JSONObject) JSON.parse(resp1);
+            // 获取值赋值给全局变量
+            if (!json.containsKey("errcode")) {
+                newAccessToken = json.getString("access_token");
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return newAccessToken;
+    }
+}

+ 112 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/WechatTemplateUtil.java

@@ -0,0 +1,112 @@
+package com.hssx.cloudmodel.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.hssx.cloudmodel.constant.Constant;
+import com.hssx.cloudmodel.entity.vo.MouldEquipmentVO;
+import org.apache.commons.lang3.StringEscapeUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Author: 吴涛涛 cuiyi@itany.com
+ * Date : 2019 - 08 - 29 14:46
+ * Description:<描述>
+ * Version: 1.0
+ */
+public class WechatTemplateUtil {
+
+    /**
+     * 云模盒告警模板
+     * touserOpenId 被推送者的openId
+     * firstData 推送标题
+     * equipmentName 设备名称,emergencyType 告警类型,emergencyContent 内容,newAccessToken token
+     */
+    public static void sendEmergencyTemplateMessage(String touserOpenId,String equipmentName,String emergencyType,String emergencyContent,String newAccessToken) throws Exception {
+        HttpRespMsg msg = new HttpRespMsg();
+        String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+                + newAccessToken;
+        WechatTemplateMessage wechat = new WechatTemplateMessage();
+        wechat.setTemplate_id(Constant.WARNING_NOTICE_TEMPLATE_ID);
+        wechat.setTouser(touserOpenId);
+        wechat.setAppid(Constant.WECHAT_APPID);
+        Map<String, Map<String, String>> data = new HashMap<>();
+        Map<String, String> first = new HashMap<>();
+        Map<String, String> value1 = new HashMap<>();
+        Map<String, String> value2 = new HashMap<>();
+        Map<String, String> value3 = new HashMap<>();
+        Map<String, String> value4 = new HashMap<>();
+        Map<String, String> remark = new HashMap<>();
+        // 推送信息主体
+        first.put("value", "告警通知");//firstData推送标题
+        data.put("first", first);
+        value1.put("value", equipmentName);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        data.put("keyword1", value1);
+        value2.put("value", emergencyType);
+        data.put("keyword2", value2);
+        value3.put("value", sdf.format(new Date()));
+        data.put("keyword3", value3);
+        value4.put("value", emergencyContent);
+        data.put("keyword4", value4);
+        remark.put("value", "请尽快检查该设备");
+        data.put("remark", remark);
+        wechat.setData(data);
+        String jsonString = JSONObject.toJSONString(wechat);
+        // System.out.println("jsonString"+jsonString);
+        String resp = HttpKit.post(url1, jsonString);
+        // System.out.println("resp0"+resp);
+        resp = StringEscapeUtils.unescapeJava(resp);
+        // System.out.println("resp"+resp);
+        JSONObject json = (JSONObject) JSON.parse(resp);
+    }
+
+    /**
+     * 模具保养
+     * templateId 模板id,touserOpenId 被推送者的openId,appId微信公众号的appId
+     * firstData 推送标题
+     * mouldName 模具名称,maintain 方式(保养),maintainCause 保养原因,newAccessToken token
+     */
+    public static void sendMaintainTemplateMessage( String touserOpenId,String mouldName,String maintain,String maintainCause,String newAccessToken) throws Exception {
+        // 获取值赋值给全局变量
+            String url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+                    + newAccessToken;
+            WechatTemplateMessage wechat = new WechatTemplateMessage();
+            wechat.setTemplate_id(Constant.MAINTAIN_NOTICE_TEMPLATE_ID);
+            wechat.setTouser(touserOpenId);
+            wechat.setAppid(Constant.WECHAT_APPID );
+            Map<String, Map<String, String>> data = new HashMap<>();
+            Map<String, String> first = new HashMap<>();
+            Map<String, String> value1 = new HashMap<>();
+            Map<String, String> value2 = new HashMap<>();
+            Map<String, String> value3 = new HashMap<>();
+            Map<String, String> value4 = new HashMap<>();
+            Map<String, String> remark = new HashMap<>();
+            // 推送信息主体
+            first.put("value", "你好,你有新的保养通知");//firstData推送标题
+            data.put("first", first);
+            value1.put("value", mouldName);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
+            data.put("keyword1", value1);
+            value2.put("value","暂无");
+            data.put("keyword2", value2);
+            value3.put("value", sdf.format(new Date()));
+            data.put("keyword3", value3);
+            value4.put("value", maintain);
+            data.put("keyword4", value4);
+            remark.put("value", maintainCause);
+            data.put("remark", remark);
+            wechat.setData(data);
+            String jsonString = JSONObject.toJSONString(wechat);
+            // System.out.println("jsonString"+jsonString);
+            String resp = HttpKit.post(url1, jsonString);
+            // System.out.println("resp0"+resp);
+            resp = StringEscapeUtils.unescapeJava(resp);
+            // System.out.println("resp"+resp);
+        JSONObject json = (JSONObject) JSON.parse(resp);
+
+    }
+}

+ 5 - 3
cloud-model/src/main/resources/mapper/MouldEquipmentMapper.xml

@@ -17,11 +17,12 @@
         <result column="lat" property="lat" />
         <result column="temperature" property="temperature" />
         <result column="agent" property="agent" />
+        <result column="stage" property="stage" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, equipment_name, start_time, end_time, use_life, belong_company_id, equipment_no, is_use, hill_number, lng, lat, temperature, agent
+        id, equipment_name, start_time, end_time, use_life, belong_company_id, equipment_no, is_use, hill_number, lng, lat, temperature, agent,stage
     </sql>
     <resultMap id="BaseResultMapVO" type="com.hssx.cloudmodel.entity.vo.MouldEquipmentVO">
         <id column="id" property="id" />
@@ -37,13 +38,14 @@
         <result column="modelNo" property="modelNo" />
         <result column="agent" property="agent" />
         <result column="modelName" property="modelName" />
+        <result column="stage" property="stage" />
     </resultMap>
 
     <select id="getListByCompanyId" resultMap="BaseResultMapVO">
         select
         tbme.id id, tbme.equipment_name equipment_name, tbme.start_time start_time, tbme.end_time end_time,
         tbme.use_life use_life, tbme.belong_company_id belong_company_id, tbme.equipment_no equipment_no,
-        tbme.is_use, tbme.hill_number,tbc.company_name companyName,tbme.agent
+        tbme.is_use, tbme.hill_number,tbc.company_name companyName,tbme.agent,tbme.stage
         from
         tb_mould_equipment tbme
         left join
@@ -64,7 +66,7 @@
         select
         tbme.id id, tbme.equipment_name equipment_name, tbme.start_time start_time, tbme.end_time end_time,tbme.agent,
         tbme.use_life use_life, tbme.belong_company_id belong_company_id, tbme.equipment_no equipment_no,
-        tbme.is_use, tbme.hill_number,tbc.company_name companyName,tbm.model_no modelNo,tbm.model_name modelName
+        tbme.is_use, tbme.hill_number,tbc.company_name companyName,tbm.model_no modelNo,tbm.model_name modelName,tbme.stage
         from
         tb_mould_equipment tbme
         left join

+ 5 - 4
cloud-model/src/main/resources/mapper/MouldMapper.xml

@@ -65,6 +65,7 @@
         <result column="managerId" property="managerId" />
         <result column="mangerName" property="mangerName"/>
         <result column="equipmentNo" property="equipmentNo"/>
+        <result column="stage" property="stage"/>
         <result column="endTime" property="endTime"/>
         <result column="hillNumber" property="hillNumber"/>
         <result column="ownerCompanyName" property="ownerCompanyName"/>
@@ -86,7 +87,7 @@
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbc.company_name companyName,tbco.company_name produceCompany,tbm.pre_update_id,
         tbp.manager mangerName,tbm.area area,tbmp.hill_number hillNumber,tbm.oc_cycle oc_cycle,tbp.manager_id managerId,
         tbmp.equipment_no equipmentNo,tbm.setting_life setting_life,tbp.owner_company_name ownerCompanyName,tbm.run_times run_times,
-        tbmp.lng,tbmp.lat
+        tbmp.lng,tbmp.lat,tbmp.stage
         from
         tb_mould tbm
         left join
@@ -128,7 +129,7 @@
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbc.company_name companyName,tbm.holes,tbm.pre_update_id,tbco.company_name produceCompany,
         tbp.manager mangerName,tbm.area area,tbmp.hill_number hillNumber,tbm.oc_cycle oc_cycle,tbm.creator_id creator_id,
         tbmp.equipment_no equipmentNo,tbm.setting_life setting_life,tbp.owner_company_name ownerCompanyName,tbm.run_times run_times,
-        tbmp.lng,tbmp.lat
+        tbmp.lng,tbmp.lat,tbmp.stage
         from
         tb_mould tbm
         left join
@@ -171,7 +172,7 @@
         tbm.id id,tbm.model_no model_no, tbm.model_name,tbm.initial_modulus initial_modulus,tbp.manager_id managerId,tbm.produce_company_id produce_company_id,
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbco.company_name produceCompany,tbm.creator_id creator_id,tbm.holes,
         tbp.manager mangerName,tbm.area area,tbm.rfid rfid,tbm.oc_cycle oc_cycle,tbc.company_name companyName,tbm.pre_update_id,
-        tbmp.equipment_no equipmentNo,tbmp.hill_number hillNumber,tbm.setting_life setting_life,tbm.run_times run_times
+        tbmp.equipment_no equipmentNo,tbmp.hill_number hillNumber,tbm.setting_life setting_life,tbm.run_times run_times,tbmp.stage
         from
         tb_mould tbm
         left join
@@ -199,7 +200,7 @@ select
         tbmp.end_time endTime,tbm.state state,tbp.project_name projectName,tbc.company_name companyName,tbm.pre_update_id,tbm.company_id,tbco.company_name produceCompany,tbm.produce_company_id,
         tbp.manager mangerName,tbm.area area,tbmp.hill_number hillNumber,tbm.oc_cycle oc_cycle,tbp.manager_id managerId,
         tbmp.equipment_no equipmentNo,tbm.setting_life setting_life,tbp.owner_company_name ownerCompanyName,tbm.run_times run_times,
-        tbmp.lng,tbmp.lat
+        tbmp.lng,tbmp.lat,tbmp.stage
         from
         tb_mould tbm
         left join