Selaa lähdekoodia

Merge branch 'server-165' of uskycloud/usky-modules into master

gez 11 kuukautta sitten
vanhempi
commit
54bc190748
37 muutettua tiedostoa jossa 1295 lisäystä ja 156 poistoa
  1. 19 0
      service-fire/service-fire-biz/pom.xml
  2. 3 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionAttendanceController.java
  3. 1 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionContentController.java
  4. 38 2
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionRecordController.java
  5. 1 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionSiteController.java
  6. 4 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionTypeController.java
  7. 2 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/PatrolInspectionRecordPictureMapper.java
  8. 5 0
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/PatrolInspectionRecordService.java
  9. 302 1
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionRecordServiceImpl.java
  10. 25 1
      service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PatrolInspectionRecordExportVo.java
  11. 22 0
      service-iot/service-iot-api/src/main/java/com/usky/iot/RemoteMceService.java
  12. 32 0
      service-iot/service-iot-api/src/main/java/com/usky/iot/factory/RemoteMceFallbackFactory.java
  13. 1 0
      service-iot/service-iot-biz/pom.xml
  14. 3 3
      service-iot/service-iot-biz/src/main/java/com/usky/iot/constant/constant.java
  15. 20 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/MceControllerApi.java
  16. 21 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/MceMbuserController.java
  17. 10 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/MceReceiveController.java
  18. 111 139
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/WeChatController.java
  19. 4 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceContent.java
  20. 68 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceMbuser.java
  21. 4 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceReceive.java
  22. 4 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceSetting.java
  23. 16 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/MceMbuserMapper.java
  24. 2 1
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceContentService.java
  25. 24 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceMbuserService.java
  26. 3 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceReceiveService.java
  27. 49 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/ExecutorConfig.java
  28. 137 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/HttpClientUtils.java
  29. 3 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceTypeServiceImpl.java
  30. 32 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceContentServiceImpl.java
  31. 137 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceMbuserServiceImpl.java
  32. 77 4
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceReceiveServiceImpl.java
  33. 7 5
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceSettingServiceImpl.java
  34. 31 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/SendWeChatMessageRequestVO.java
  35. 11 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/TemplateData.java
  36. 48 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/TemplateMsgEntityVO.java
  37. 18 0
      service-iot/service-iot-biz/src/main/resources/mapper/iot/MceMbuserMapper.xml

+ 19 - 0
service-fire/service-fire-biz/pom.xml

@@ -94,6 +94,25 @@
             <version>0.0.1</version>
             <scope>compile</scope>
         </dependency>
+
+        <!--图片处理依赖-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.4</version>
+        </dependency>
+
+
     </dependencies>
 
     <build>

+ 3 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionAttendanceController.java

@@ -4,6 +4,8 @@ package com.usky.fire.controller.web;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.util.StringUtils;
+import com.usky.common.log.annotation.Log;
+import com.usky.common.log.enums.BusinessType;
 import com.usky.fire.domain.PatrolInspectionAttendance;
 import com.usky.fire.service.PatrolInspectionAttendanceService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -48,6 +50,7 @@ public class PatrolInspectionAttendanceController {
      * @param patrolInspectionAttendance
      * @return
      */
+    @Log(title = " 签到、签退信息记录", businessType = BusinessType.INSERT)
     @PostMapping("/add")
     public ApiResult<Void> add(@RequestBody PatrolInspectionAttendance patrolInspectionAttendance){
         patrolInspectionAttendanceService.add(patrolInspectionAttendance);

+ 1 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionContentController.java

@@ -94,6 +94,7 @@ public class PatrolInspectionContentController {
      * @return
      * @throws IOException
      */
+    @Log(title = "巡检内容", businessType = BusinessType.EXPORT)
     @PostMapping("/contentListExport")
     public void export(HttpServletResponse response,
                        @RequestParam(value = "contentTitle", required = false) String contentTitle,

+ 38 - 2
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionRecordController.java

@@ -1,19 +1,28 @@
 package com.usky.fire.controller.web;
 
-
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.log.annotation.Log;
+import com.usky.common.log.enums.BusinessType;
 import com.usky.fire.domain.PatrolInspectionRecord;
 import com.usky.fire.service.PatrolInspectionRecordService;
 import com.usky.fire.service.vo.PatrolInspectionRecordExportVo;
 import com.usky.fire.service.vo.PatrolInspectionRecordVo;
 import com.usky.fire.service.vo.RecordStatisticsVo;
+import org.apache.commons.io.IOUtils;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.net.URL;
 import java.util.List;
 
 /**
@@ -92,6 +101,7 @@ public class PatrolInspectionRecordController {
      * @param idList        记录ID
      * @throws IOException
      */
+    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
     @PostMapping("/recordLsitExport")
     public void export(HttpServletResponse response,
                        @RequestParam(value = "areaName", required = false) String areaName,
@@ -105,5 +115,31 @@ public class PatrolInspectionRecordController {
         ExcelUtil<PatrolInspectionRecordExportVo> util = new ExcelUtil<PatrolInspectionRecordExportVo>(PatrolInspectionRecordExportVo.class);
         util.exportExcel(response, list, "巡检记录", "巡检记录");
     }
+
+
+    /**
+     * 巡查自检-巡检记录-导出(添加多媒体数据)
+     *
+     * @param response
+     * @param areaName      区域名称
+     * @param siteName      地点名称
+     * @param name          人员名称
+     * @param planType      计划类型
+     * @param startDateTime 开始时间
+     * @param endDateTime   结束时间
+     * @param idList        记录ID
+     * @throws IOException
+     */
+    @PostMapping("/recordLsitExportMultimedia")
+    public void exportMultimedia(HttpServletResponse response,
+                                 @RequestParam(value = "areaName", required = false) String areaName,
+                                 @RequestParam(value = "siteName", required = false) String siteName,
+                                 @RequestParam(value = "name", required = false) String name,
+                                 @RequestParam(value = "planType", required = false) Integer planType,
+                                 @RequestParam(value = "startDateTime", required = false) String startDateTime,
+                                 @RequestParam(value = "endDateTime", required = false) String endDateTime,
+                                 @RequestParam(value = "idList", required = false) String idList) throws IOException {
+        patrolInspectionRecordService.exportImage(response,areaName, siteName, name, planType, startDateTime, endDateTime, idList);
+    }
 }
 

+ 1 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionSiteController.java

@@ -146,6 +146,7 @@ public class PatrolInspectionSiteController {
      * @param idList   地点ID
      * @return
      */
+    @Log(title = "巡检地点", businessType = BusinessType.EXPORT)
     @PostMapping("/patrolInspectionSiteListExport")
     public void export(HttpServletResponse response,
                        @RequestParam(required = false) Integer areaId,

+ 4 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/PatrolInspectionTypeController.java

@@ -3,6 +3,8 @@ package com.usky.fire.controller.web;
 
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.log.annotation.Log;
+import com.usky.common.log.enums.BusinessType;
 import com.usky.fire.domain.PatrolInspectionType;
 import com.usky.fire.service.PatrolInspectionTypeService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +41,7 @@ public class PatrolInspectionTypeController {
      * @param patrolInspectionType
      * @return
      */
+    @Log(title = "操作类型", businessType = BusinessType.INSERT)
     @PostMapping("/add")
     public ApiResult<Void> add(@RequestBody PatrolInspectionType patrolInspectionType){
         patrolInspectionTypeService.add(patrolInspectionType);
@@ -50,6 +53,7 @@ public class PatrolInspectionTypeController {
      * @param deleteType
      * @return
      */
+    @Log(title = "操作类型", businessType = BusinessType.DELETE)
     @GetMapping("/delete")
     public ApiResult<Void> delete(@RequestBody PatrolInspectionType deleteType){
         patrolInspectionTypeService.softDelete(deleteType);

+ 2 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/PatrolInspectionRecordPictureMapper.java

@@ -2,6 +2,7 @@ package com.usky.fire.mapper;
 
 import com.usky.fire.domain.PatrolInspectionRecordPicture;
 import com.usky.common.mybatis.core.CrudMapper;
+import org.springframework.stereotype.Repository;
 
 /**
  * <p>
@@ -11,6 +12,7 @@ import com.usky.common.mybatis.core.CrudMapper;
  * @author JCB
  * @since 2022-07-21
  */
+@Repository
 public interface PatrolInspectionRecordPictureMapper extends CrudMapper<PatrolInspectionRecordPicture> {
 
 }

+ 5 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/PatrolInspectionRecordService.java

@@ -7,6 +7,9 @@ import com.usky.fire.service.vo.PatrolInspectionRecordExportVo;
 import com.usky.fire.service.vo.PatrolInspectionRecordVo;
 import com.usky.fire.service.vo.RecordStatisticsVo;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.MalformedURLException;
 import java.util.List;
 
 /**
@@ -40,4 +43,6 @@ public interface PatrolInspectionRecordService extends CrudService<PatrolInspect
     List<PatrolInspectionRecordExportVo> recordLsitExport(String areaName, String siteName, String name,
                                                           Integer planType, String startDateTime,
                                                           String endDateTime,String idList);
+    void exportImage(HttpServletResponse response, String areaName, String siteName, String name, Integer planType,
+                            String startDateTime, String endDateTime, String idList) throws IOException;
 }

+ 302 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionRecordServiceImpl.java

@@ -1,5 +1,6 @@
 package com.usky.fire.service.impl;
 
+import com.ruoyi.common.core.utils.file.ImageUtils;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -13,12 +14,25 @@ import com.usky.common.security.utils.SecurityUtils;
 import com.usky.fire.domain.*;
 import com.usky.fire.mapper.PatrolInspectionPlanMapper;
 import com.usky.fire.mapper.PatrolInspectionRecordMapper;
+import com.usky.fire.mapper.PatrolInspectionRecordPictureMapper;
 import com.usky.fire.service.*;
 import com.usky.fire.service.vo.*;
 import com.usky.system.model.LoginUser;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
@@ -58,6 +72,9 @@ public class PatrolInspectionRecordServiceImpl extends AbstractCrudService<Patro
     @Autowired
     private PatrolInspectionPlanMapper patrolInspectionPlanMapper;
 
+    @Autowired
+    private PatrolInspectionRecordPictureMapper orphansInspectionRecordPictureMapper;
+
     @Override
     public CommonPage<PatrolInspectionRecord> patrolInspectionRecordLsit(String areaName, String siteName, String name,
                                                                          Integer planType, String startDateTime, String endDateTime,
@@ -148,7 +165,9 @@ public class PatrolInspectionRecordServiceImpl extends AbstractCrudService<Patro
             contentOptionVo.setCreateTime(contentOptionList.get(i).getCreateTime());
             contentOptionVo.setSelectStatus(false);
             for (int j = 0; j < patrolInspectionRecordOptionList.size(); j++) {
-                contentOptionVo.setRemarks(patrolInspectionRecordOptionList.get(j).getRemarks());
+                if(contentOptionList.get(i).getContentId()==patrolInspectionContentList.get(j).getId()){
+                    contentOptionVo.setRemarks(patrolInspectionRecordOptionList.get(j).getRemarks());
+                }
                 if (contentOptionList.get(i).getId() == patrolInspectionRecordOptionList.get(j).getContentOptionId()) {
                     contentOptionVo.setSelectStatus(true);
                 }
@@ -399,4 +418,286 @@ public class PatrolInspectionRecordServiceImpl extends AbstractCrudService<Patro
         }
         return list;
     }
+
+    @Override
+    public void exportImage(HttpServletResponse response, String areaName, String siteName, String name, Integer planType,
+                            String startDateTime, String endDateTime, String idList) throws IOException {
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        String userType = null;
+        if (loginUser != null && !"".equals(loginUser)) {
+            userType = loginUser.getUserType();
+        }
+        LambdaQueryWrapper<PatrolInspectionRecord> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(PatrolInspectionRecord::getTenantId, SecurityUtils.getTenantId())
+                .like(StringUtils.isNotBlank(areaName), PatrolInspectionRecord::getAreaName, areaName)
+                .like(StringUtils.isNotBlank(siteName), PatrolInspectionRecord::getSiteName, siteName)
+                .like(StringUtils.isNotBlank(name), PatrolInspectionRecord::getName, name)
+                .eq(planType != null && planType != 0, PatrolInspectionRecord::getPlanType, planType)
+                .between(StringUtils.isNotBlank(startDateTime) && StringUtils.isNotBlank(endDateTime), PatrolInspectionRecord::getCreateTime, startDateTime, endDateTime)
+                .eq("00".equals(userType), PatrolInspectionRecord::getCreator, SecurityUtils.getUsername());
+        if (StringUtils.isNotBlank(idList)) {
+            List<Integer> listId = new ArrayList<>();
+            String[] idArray = idList.split(",");
+            for (int i = 0; i < idArray.length; i++) {
+                listId.add(Integer.parseInt(idArray[i]));
+            }
+            queryWrapper.in(PatrolInspectionRecord::getId, listId);
+        }
+        queryWrapper.orderByDesc(PatrolInspectionRecord::getId);
+        List<PatrolInspectionRecord> patrolInspectionRecordList = this.list(queryWrapper);
+        List<PatrolInspectionRecordExportVo> list = new ArrayList<>();
+        for (int i = 0; i < patrolInspectionRecordList.size(); i++) {
+            PatrolInspectionRecordExportVo patrolInspectionRecordExportVo = new PatrolInspectionRecordExportVo();
+            patrolInspectionRecordExportVo.setXh(i + 1);
+            patrolInspectionRecordExportVo.setId(patrolInspectionRecordList.get(i).getId());
+            patrolInspectionRecordExportVo.setSiteNubmber(patrolInspectionRecordList.get(i).getSiteNubmber());
+            patrolInspectionRecordExportVo.setSiteType(patrolInspectionRecordList.get(i).getSiteType());
+            patrolInspectionRecordExportVo.setAreaName(patrolInspectionRecordList.get(i).getAreaName());
+            patrolInspectionRecordExportVo.setSiteName(patrolInspectionRecordList.get(i).getSiteName());
+            patrolInspectionRecordExportVo.setName(patrolInspectionRecordList.get(i).getName());
+            patrolInspectionRecordExportVo.setPhone(patrolInspectionRecordList.get(i).getPhone());
+            patrolInspectionRecordExportVo.setPlanType(patrolInspectionRecordList.get(i).getPlanType());
+            patrolInspectionRecordExportVo.setLongitude(patrolInspectionRecordList.get(i).getLongitude());
+            patrolInspectionRecordExportVo.setLatitude(patrolInspectionRecordList.get(i).getLatitude());
+            patrolInspectionRecordExportVo.setStartDate(patrolInspectionRecordList.get(i).getStartDate().format(df));
+            patrolInspectionRecordExportVo.setEndDate(patrolInspectionRecordList.get(i).getEndDate().format(df));
+            patrolInspectionRecordExportVo.setCreateTime(patrolInspectionRecordList.get(i).getCreateTime().format(df));
+            LambdaQueryWrapper<PatrolInspectionRecordPicture> queryWrapperJpg = Wrappers.lambdaQuery();//导出图片
+            queryWrapperJpg.select(PatrolInspectionRecordPicture::getPictureUrl)
+                    .eq(PatrolInspectionRecordPicture::getRecordId, patrolInspectionRecordList.get(i).getId());
+            List<PatrolInspectionRecordPicture> pictures = orphansInspectionRecordPictureMapper.selectList(queryWrapperJpg);
+            if (pictures.size() > 0) {
+                for (int j = 0; j < pictures.size() && j < 5; j++) {
+                    String pictureUrl = pictures.get(j).getPictureUrl();
+                    switch (j) {
+                        case 0:
+                            patrolInspectionRecordExportVo.setImagePath1(pictureUrl);
+                            break;
+                        case 1:
+                            patrolInspectionRecordExportVo.setImagePath2(pictureUrl);
+                            break;
+                        case 2:
+                            patrolInspectionRecordExportVo.setImagePath3(pictureUrl);
+                            break;
+                        case 3:
+                            patrolInspectionRecordExportVo.setImagePath4(pictureUrl);
+                            break;
+                        case 4:
+                            patrolInspectionRecordExportVo.setImagePath5(pictureUrl);
+                            break;
+                        default:
+                            break;
+                    }
+                }
+            }
+            list.add(patrolInspectionRecordExportVo);
+        }
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet = workbook.createSheet("巡检记录");
+        // 添加列标题行
+        Row headerRow = sheet.createRow(1);
+        String[] headers = {
+                "序号", "地点号码", "地点类型", "区域名称", "地点名称", "巡检人员", "联系电话",
+                "计划类型", "经度", "纬度", "开始时间", "结束时间", "巡检时间", "巡检照片1",
+                "巡检照片2", "巡检照片3", "巡检照片4", "巡检照片5"
+        };
+        // 添加总标题行
+        Row titleRow = sheet.createRow(0);
+        Cell titleCell = titleRow.createCell(0);
+        titleCell.setCellValue("巡检记录");
+        CellStyle titleCellStyle = workbook.createCellStyle();
+        // 设置字体为黑色加粗
+        Font titleFont = workbook.createFont();
+        titleFont.setFontName("宋体");
+        titleFont.setFontHeightInPoints((short) 16);
+        titleFont.setColor(IndexedColors.BLACK.getIndex());
+        titleFont.setBold(true);
+        titleCellStyle.setFont(titleFont);
+        // 设置水平居中和垂直居中
+        titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
+        titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        titleCell.setCellStyle(titleCellStyle);
+        titleRow.setHeightInPoints(30);
+        // 合并标题单元格以横跨所有列
+        int totalColumns = headers.length;
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, totalColumns - 1));
+        //设置列标题
+        for (int i = 0; i < headers.length; i++) {
+            Cell cell = headerRow.createCell(i);
+            cell.setCellValue(headers[i]);
+            CellStyle headerCellStyle = workbook.createCellStyle();
+            headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+            headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+            headerCellStyle.setBorderBottom(BorderStyle.THIN);
+            headerCellStyle.setBorderTop(BorderStyle.THIN);
+            headerCellStyle.setBorderLeft(BorderStyle.THIN);
+            headerCellStyle.setBorderRight(BorderStyle.THIN);
+            // 设置背景颜色为灰色
+            headerCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
+            headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+            // 设置字体为白色
+            Font headerFont = workbook.createFont();
+            headerFont.setFontName("宋体");
+            headerFont.setFontHeightInPoints((short) 10);
+            headerFont.setColor(IndexedColors.WHITE.getIndex());
+            headerFont.setBold(true);
+            headerRow.setHeightInPoints(13.5f);
+            headerCellStyle.setFont(headerFont);
+            cell.setCellStyle(headerCellStyle);
+        }
+
+        Row fixedRow = sheet.createRow(list.size() + 3); // 数据行数 + 标题行数(1) + 固定行(1) + 空一行
+        CellStyle fixedCellStyle = workbook.createCellStyle();
+
+        // 创建字体样式
+        Font fixedFont = workbook.createFont();
+        fixedFont.setFontName("宋体");
+        fixedFont.setBold(true);
+        fixedFont.setFontHeightInPoints((short) 12);
+        fixedCellStyle.setFont(fixedFont);
+
+        // 创建“负责人签名”单元格
+        Cell cellSign = fixedRow.createCell(0);
+        cellSign.setCellValue("负责人签名:");
+        cellSign.setCellStyle(fixedCellStyle);
+
+        // 创建“日期”单元格
+        Cell cellDate = fixedRow.createCell(4); // 假设日期单元格在第五列
+        cellDate.setCellValue("日期:");
+        cellDate.setCellStyle(fixedCellStyle);
+
+        // 合并单元格
+//        sheet.addMergedRegion(new CellRangeAddress(list.size() + 2, list.size() + 2, 0, 0)); // 负责人签名
+//        sheet.addMergedRegion(new CellRangeAddress(list.size() + 2, list.size() + 2, 4, 4)); // 日期
+
+        // 设置固定行的高度
+        fixedRow.setHeightInPoints(20);
+
+        // 设置数据行样式
+        CellStyle dataCellStyle = workbook.createCellStyle();
+        Font dataFont = workbook.createFont();
+        dataFont.setFontName("Arial");
+        dataFont.setFontHeightInPoints((short) 10);
+        dataCellStyle.setFont(dataFont);
+        dataCellStyle.setAlignment(HorizontalAlignment.CENTER);
+        dataCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        dataCellStyle.setBorderBottom(BorderStyle.THIN);
+        dataCellStyle.setBorderTop(BorderStyle.THIN);
+        dataCellStyle.setBorderLeft(BorderStyle.THIN);
+        dataCellStyle.setBorderRight(BorderStyle.THIN);
+        // 添加数据
+        for (int i = 0; i < list.size(); i++) {
+            PatrolInspectionRecordExportVo record = list.get(i);
+            Row row = sheet.createRow(i + 2);
+
+            for (int j = 0; j < headers.length; j++) {
+                Cell cell = row.createCell(j);
+                cell.setCellStyle(dataCellStyle);
+
+                // 根据 j 变量来确定应该填充数据的单元格索引
+                switch (j) {
+                    case 0:
+                        cell.setCellValue(record.getXh());
+                        break;
+                    case 1:
+                        cell.setCellValue(record.getSiteNubmber());
+                        break;
+                    case 2:
+                        cell.setCellValue(record.getSiteType() == 1 ? "二维码" : "NFC");
+                        break;
+                    case 3:
+                        cell.setCellValue(record.getAreaName());
+                        break;
+                    case 4:
+                        cell.setCellValue(record.getSiteName());
+                        break;
+                    case 5:
+                        cell.setCellValue(record.getName());
+                        break;
+                    case 6:
+                        cell.setCellValue(record.getPhone());
+                        break;
+                    case 7:
+                        cell.setCellValue(record.getPlanType() == 1 ? "普通计划" : "按次计划");
+                        break;
+                    case 8:
+                        cell.setCellValue(record.getLongitude());
+                        break;
+                    case 9:
+                        cell.setCellValue(record.getLatitude());
+                        break;
+                    case 10:
+                        cell.setCellValue(record.getStartDate());
+                        break;
+                    case 11:
+                        cell.setCellValue(record.getEndDate());
+                        break;
+                    case 12:
+                        cell.setCellValue(record.getCreateTime());
+                        break;
+                    default:
+                        break;
+                }
+                CreationHelper helper = workbook.getCreationHelper();
+                Drawing<?> drawing = sheet.createDrawingPatriarch();
+                ClientAnchor anchor;
+                if (record.getImagePath1() != null || record.getImagePath2() != null
+                        || record.getImagePath3() != null || record.getImagePath4() != null || record.getImagePath5() != null) {
+                    for (int k = 0; k < 5; k++) {
+                        String imagePath = null;
+                        switch (k) {
+                            case 0:
+                                imagePath = record.getImagePath1();
+                                break;
+                            case 1:
+                                imagePath = record.getImagePath2();
+                                break;
+                            case 2:
+                                imagePath = record.getImagePath3();
+                                break;
+                            case 3:
+                                imagePath = record.getImagePath4();
+                                break;
+                            case 4:
+                                imagePath = record.getImagePath5();
+                                break;
+                        }
+
+                        if (imagePath != null) {
+                            byte[] imageBytes = getImageBytes(imagePath);
+                            int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
+
+                            anchor = helper.createClientAnchor();
+                            anchor.setCol1(headers.length - 5 + k);
+                            anchor.setRow1(i + 2);
+
+                            Picture pict = drawing.createPicture(anchor, pictureIdx);
+                            pict.resize(1, 1);
+                        }
+                    }
+                }
+            }
+
+        }
+
+        for (int i = 0; i < headers.length; i++) {
+            sheet.setColumnWidth(i, (int) (16.09 * 256));
+        }
+
+        // 输出Excel文件
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setHeader("Content-Disposition", "attachment; filename=巡检记录.xlsx");
+        workbook.write(response.getOutputStream());
+        workbook.close();
+    }
+
+    public byte[] getImageBytes(String imageUrl) throws IOException {
+        URL url = new URL(imageUrl);
+        BufferedImage image = ImageIO.read(url);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ImageIO.write(image, "jpg", baos);
+        return baos.toByteArray();
+    }
+
 }

+ 25 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PatrolInspectionRecordExportVo.java

@@ -143,5 +143,29 @@ public class PatrolInspectionRecordExportVo implements Serializable {
      */
     private String creator;
 
-
+    /**
+     * 图片数据
+     */
+    @Excel(name = "巡检照片1")
+    private String imagePath1;
+    /**
+     * 图片数据
+     */
+    @Excel(name = "巡检照片2")
+    private String imagePath2;
+    /**
+     * 图片数据
+     */
+    @Excel(name = "巡检照片3")
+    private String imagePath3;
+    /**
+     * 图片数据
+     */
+    @Excel(name = "巡检照片4")
+    private String imagePath4;
+    /**
+     * 图片数据
+     */
+    @Excel(name = "巡检照片5")
+    private String imagePath5;
 }

+ 22 - 0
service-iot/service-iot-api/src/main/java/com/usky/iot/RemoteMceService.java

@@ -0,0 +1,22 @@
+package com.usky.iot;
+
+import com.usky.common.core.bean.ApiResult;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author han
+ * @date 2024/04/26 14:07
+ */
+@FeignClient(contextId = "remoteMceService", value = "service-iot")
+public interface RemoteMceService {
+    /**
+     * 新增消息
+     *
+     * @return 消息结果
+     */
+    @RequestMapping(value = "addMce")
+    ApiResult<Void> addMce(@RequestParam(value = "mceReceive",required = false) String mceReceive);
+}

+ 32 - 0
service-iot/service-iot-api/src/main/java/com/usky/iot/factory/RemoteMceFallbackFactory.java

@@ -0,0 +1,32 @@
+package com.usky.iot.factory;
+
+import com.alibaba.fastjson.JSONObject;
+import com.usky.common.core.bean.ApiResult;
+import com.usky.common.core.exception.FeignBadRequestException;
+import com.usky.iot.RemoteMceService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cloud.openfeign.FallbackFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author han
+ * @date 2024/04/02 15:07
+ */
+//@Component
+//public class RemoteMceFallbackFactory implements FallbackFactory<RemoteMceService> {
+//    private static final Logger log = LoggerFactory.getLogger(RemoteMceFallbackFactory.class);
+//
+//    @Override
+//    public RemoteMceService create(Throwable throwable)
+//    {
+//        log.error("iot服务调用失败:{}", throwable.getMessage());
+//        return new RemoteMceService()
+//        {
+//            @Override
+//            public ApiResult<Void> addMce(String mceReceive) {
+//                throw new FeignBadRequestException(500,"新增消息异常"+throwable.getMessage());
+//            }
+//        };
+//    }
+//}

+ 1 - 0
service-iot/service-iot-biz/pom.xml

@@ -71,6 +71,7 @@
             <artifactId>weixin-java-mp</artifactId>
             <version>4.3.0</version>
         </dependency>
+
     </dependencies>
 
     <build>

+ 3 - 3
service-iot/service-iot-biz/src/main/java/com/usky/iot/constant/constant.java

@@ -12,15 +12,15 @@ public class constant {
     // 回调地址,获取open_id
     public static final String WE_CHAT_CALL_BACK_DOMAIN_URL = "http://localhost:9887/weChat/getWeChatOpenId";
     // 回调域名
-    public static final String call_back_domain = "aiot.usky.cn";
+    public static final String call_back_domain = "manager.usky.cn";
     // 微信公众号的token获取地址
     public static final String WE_CHAT_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
     // 微信公众号消息推送地址
     public static final String WE_CHAT_REQUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s";
     // 微信公众号推送消息模板id
-    public static final String WE_CHAT_TEMPLATE_ID = "**********";
+    public static final String WE_CHAT_TEMPLATE_ID = "FmrNuMzgh0E8bWg1j8a2R3zTmRarHYtZ72TSzPrF9Iw";
     // 微信公众号的消息回调地址(这儿可根据业务需求自定义动作,可选)
-    public static final String WE_CHAT_CUSTOMER_CALL_URL = "https://***.***.***.***/***/***/accountInfo?keyword=%s";
+    public static final String WE_CHAT_CUSTOMER_CALL_URL = "http://manager.usky.cn/mobile/#/pages/common/textview/index?id=%s";
     // 微信公众号的主题颜色
     public static final String WE_CHAT_TOP_COLOR = "#A349A4";
     // 微信公众号微信用户授权地址

+ 20 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/MceControllerApi.java

@@ -0,0 +1,20 @@
+package com.usky.iot.controller.api;
+
+import com.usky.common.core.bean.ApiResult;
+import com.usky.iot.RemoteMceService;
+import com.usky.iot.service.MceReceiveService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class MceControllerApi implements RemoteMceService {
+
+    @Autowired
+    private MceReceiveService mceReceiveService;
+
+    @Override
+    public ApiResult<Void> addMce(String mceReceive) {
+        mceReceiveService.add(mceReceive);
+        return ApiResult.success();
+    }
+}

+ 21 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/MceMbuserController.java

@@ -0,0 +1,21 @@
+package com.usky.iot.controller.web;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 前端控制器
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Controller
+@RequestMapping("/mceMbuser")
+public class MceMbuserController {
+
+}
+

+ 10 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/MceReceiveController.java

@@ -101,5 +101,15 @@ public class MceReceiveController {
         mceReceiveService.updateMceReceive(mceReceive);
         return ApiResult.success();
     }
+
+    /**
+     * 消息接收接口
+     * @return
+     */
+    @PostMapping("/mceAdd")
+    ApiResult<Void> add(@RequestBody String mceReceive){
+        mceReceiveService.add(mceReceive);
+        return ApiResult.success();
+    }
 }
 

+ 111 - 139
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/WeChatController.java

@@ -1,23 +1,35 @@
 package com.usky.iot.controller.web;
 
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.exception.BusinessException;
+import com.usky.common.core.util.HttpUtils;
 import com.usky.common.redis.core.RedisHelper;
+import com.usky.common.security.utils.SecurityUtils;
 import com.usky.iot.constant.constant;
-import com.usky.iot.domain.SysWxOpuser;
-import com.usky.iot.service.SysWxOpuserService;
+import com.usky.iot.domain.MceMbuser;
+import com.usky.iot.service.MceMbuserService;
+import com.usky.iot.service.vo.SendWeChatMessageRequestVO;
 import com.usky.iot.service.vo.SignUpRequestVO;
+import com.usky.iot.service.vo.TemplateData;
+import com.usky.iot.service.vo.TemplateMsgEntityVO;
+import lombok.extern.slf4j.Slf4j;
 import ma.glasnost.orika.impl.util.StringUtil;
 import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
 import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.enums.WxMpApiUrl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ExitCodeEvent;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.servlet.view.RedirectView;
 
 import javax.annotation.Resource;
@@ -25,9 +37,13 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +51,7 @@ import java.util.Objects;
 
 @RestController
 @RequestMapping("/weChat")
+@Slf4j
 public class WeChatController {
     @Autowired
     private WxMpService wxMpService;
@@ -43,7 +60,7 @@ public class WeChatController {
     @Resource
     private HttpServletResponse response;
     @Autowired
-    private SysWxOpuserService sysWxOpuserService;
+    private MceMbuserService mceMbuserService;
     @Autowired
     private RedisHelper redisHelper;
 
@@ -51,55 +68,46 @@ public class WeChatController {
      * 调用的第一个接口,获取微信公众号CODE,获取openid
      */
     @GetMapping("/getFirst1")
-    public void getFirst1(){
+    public void getFirst1() throws UnsupportedEncodingException {
         String http = "https://";
         String code = request.getParameter("code");
         String userAgent = request.getHeader("User-Agent");
 
-        if(userAgent.contains("MicroMessenger")){ //wx
-            request.getSession().setAttribute("type","wx");
-            if(StringUtils.isBlank(code)){
-                String url = URLDecoder.decode(http+constant.call_back_domain+request.getRequestURI());
-                String sendUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+constant.WE_CHAT_APP_ID+"&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect";
-                try{
-                    System.out.println("sendUrl: "+sendUrl);
-                    response.sendRedirect(sendUrl);
-                }catch (IOException e){
-                    throw new BusinessException(e.getMessage());
-                }
-            }else{
-                System.out.println("code:  "+code);
-                try {
-                    WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
-
-                    String openid = wxOAuth2AccessToken.getOpenId();
-                    String access_token = wxOAuth2AccessToken.getAccessToken();
-                    System.out.println("openid:  "+openid);
-                    request.getSession().setAttribute("openid",openid);
-                    LambdaQueryWrapper<SysWxOpuser> queryWrapper = Wrappers.lambdaQuery();
-                    queryWrapper.select(SysWxOpuser::getPhone)
-                            .eq(SysWxOpuser::getStatus,1)
-                            .eq(SysWxOpuser::getOpenid,openid);
-                    SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
-                    if(one != null){
-                        request.getSession().setAttribute("phone",one.getPhone());
-                    }
-//
-//                    response.sendRedirect("https://qhome.usky.cn/work/index.html#/pages/login/login?flag=true");
-                } catch (Exception e) {
-                    throw new BusinessException(e.getMessage());
-                }
-            }
+        System.out.println("userAgent:  "+userAgent);
 
-        }else{ //app
-            request.getSession().setAttribute("type","app");
-            request.getSession().setAttribute("app_token","");
+        if(StringUtils.isBlank(code)){
+            String temp = http+constant.call_back_domain+"/prod-api/service-iot"+request.getRequestURI();
+//                String temp = "https://manager.usky.cn/prod-api/service-iot/weChat/getFirst1";
+            String url = URLDecoder.decode(temp, "UTF-8");
+            String sendUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+constant.WE_CHAT_APP_ID+"&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect";
             try{
-                response.sendRedirect("");
+                System.out.println("sendUrl: "+sendUrl);
+                response.sendRedirect(sendUrl);
             }catch (IOException e){
                 throw new BusinessException(e.getMessage());
             }
-
+        }else{
+            System.out.println("code:  "+code);
+            try {
+                WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
+
+                String openid = wxOAuth2AccessToken.getOpenId();
+                String access_token = wxOAuth2AccessToken.getAccessToken();
+                System.out.println("openid:  "+openid);
+//                request.getSession().setAttribute("openid",openid);
+//                LambdaQueryWrapper<MceMbuser> queryWrapper = Wrappers.lambdaQuery();
+//                queryWrapper.select(MceMbuser::getPhone)
+//                        .eq(MceMbuser::getOpenid,openid);
+//                MceMbuser one = mceMbuserService.getOne(queryWrapper);
+//                if(one != null){
+//                    request.getSession().setAttribute("phone",one.getPhone());
+//                }
+
+                String sendUrl = "https://manager.usky.cn/mobile/#/pages/login?openId="+openid;
+                response.sendRedirect(URLDecoder.decode(sendUrl, "UTF-8"));
+            } catch (Exception e) {
+                throw new BusinessException(e.getMessage());
+            }
         }
     }
 
@@ -107,98 +115,72 @@ public class WeChatController {
      * 跳转首页权限
      */
     @GetMapping("/getPageAuthorization")
-    public void getPageAuthorization(){
+    public void getPageAuthorization() throws UnsupportedEncodingException {
         String http = "https://";
         String code = request.getParameter("code");
         String userAgent = request.getHeader("User-Agent");
-        if(null != request.getSession().getAttribute("app_token") && (null != request.getSession().getAttribute("phone"))){
-            LambdaQueryWrapper<SysWxOpuser> queryWrapper = Wrappers.lambdaQuery();
-            queryWrapper.eq(SysWxOpuser::getPhone,request.getSession().getAttribute("phone"))
-                    .eq(SysWxOpuser::getStatus,1)
-                    .eq(SysWxOpuser::getType,"app");
-            SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
-            if(one != null){
-                String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
-                try{
-                    System.out.println("sendUrl: "+sendUrl);
-                    response.sendRedirect(sendUrl);
-                }catch (IOException e){
-                    throw new BusinessException(e.getMessage());
-                }
+        if(!userAgent.contains("MicroMessenger")){
+            try{
+                response.sendRedirect(URLDecoder.decode("https://manager.usky.cn/mobile/#/pages/login", "UTF-8"));
+            }catch (IOException e){
+                throw new BusinessException(e.getMessage());
             }
 
         }else{
-            if(!userAgent.contains("MicroMessenger")){
+            String openId = request.getParameter("openId");
+            if((openId != null) && (StringUtils.isNotBlank(openId))){
                 try{
-                    response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
+                    LambdaQueryWrapper<MceMbuser> queryWrapper = Wrappers.lambdaQuery();
+                    queryWrapper.eq(MceMbuser::getOpenid,openId);
+                    MceMbuser one = mceMbuserService.getOne(queryWrapper);
+                    if(one != null){
+                        String sendUrl = "https://manager.usky.cn/mobile/#/pages/index?op="+one.getOpenid();
+                        response.sendRedirect(URLDecoder.decode(sendUrl, "UTF-8"));
+                    }else{
+                        String sendUrl = "https://manager.usky.cn/mobile/#/pages/login?openId="+openId;
+                        response.sendRedirect(URLDecoder.decode(sendUrl, "UTF-8"));
+                    }
                 }catch (IOException e){
                     throw new BusinessException(e.getMessage());
                 }
 
             }else{
-                if((null == request.getSession().getAttribute("openid")) && (StringUtils.isBlank(request.getSession().getAttribute("openid").toString()))){
-                    if(StringUtils.isBlank(code)){
-                        String url = URLDecoder.decode(http+constant.call_back_domain+request.getRequestURI());
-                        String sendUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+constant.WE_CHAT_APP_ID+"&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect";
-                        try{
-                            System.out.println("sendUrl: "+sendUrl);
-                            response.sendRedirect(sendUrl);
-                        }catch (IOException e){
-                            throw new BusinessException(e.getMessage());
-                        }
-                    }else{
-                        System.out.println("code:  "+code);
-                        try {
-                            WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
-
-                            String openid = wxOAuth2AccessToken.getOpenId();
-                            String access_token = wxOAuth2AccessToken.getAccessToken();
-                            System.out.println("openid:  "+openid);
-                            request.getSession().setAttribute("openid",openid);
-                            LambdaQueryWrapper<SysWxOpuser> queryWrapper = Wrappers.lambdaQuery();
-                            queryWrapper.eq(SysWxOpuser::getType,"wx")
-                                    .eq(SysWxOpuser::getStatus,1)
-                                    .eq(SysWxOpuser::getOpenid,openid);
-                            SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
-                            if(one != null){
-                                request.getSession().setAttribute("phone",one.getPhone());
-
-                                String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
-                                response.sendRedirect(sendUrl);
-                            }else{
-                                request.getSession().removeAttribute("openid");
-                                request.getSession().removeAttribute("phone");
-
-                                response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
-                            }
-
-
-                        } catch (Exception e) {
-                            throw new BusinessException(e.getMessage());
-                        }
+                if(StringUtils.isBlank(code)){
+                    String temp = http+constant.call_back_domain+"/prod-api/service-iot"+request.getRequestURI();
+                    String url = URLDecoder.decode(temp, "UTF-8");
+                    String sendUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+constant.WE_CHAT_APP_ID+"&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect";
+                    try{
+                        System.out.println("sendUrl: "+sendUrl);
+                        response.sendRedirect(sendUrl);
+                    }catch (IOException e){
+                        throw new BusinessException(e.getMessage());
                     }
                 }else{
-                    try{
-                        LambdaQueryWrapper<SysWxOpuser> queryWrapper = Wrappers.lambdaQuery();
-                        queryWrapper.eq(SysWxOpuser::getType,"wx")
-                                .eq(SysWxOpuser::getStatus,1)
-                                .eq(SysWxOpuser::getOpenid,request.getSession().getAttribute("openid"));
-                        SysWxOpuser one = sysWxOpuserService.getOne(queryWrapper);
+                    System.out.println("code:  "+code);
+                    try {
+                        WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
+
+                        String openid = wxOAuth2AccessToken.getOpenId();
+                        String access_token = wxOAuth2AccessToken.getAccessToken();
+                        System.out.println("openid:  "+openid);
+                        LambdaQueryWrapper<MceMbuser> queryWrapper = Wrappers.lambdaQuery();
+                        queryWrapper.eq(MceMbuser::getOpenid,openid);
+                        MceMbuser one = mceMbuserService.getOne(queryWrapper);
                         if(one != null){
-                            request.getSession().setAttribute("phone",one.getPhone());
-                            String sendUrl = "https://aiot.usky.cn/work/#/pages/index?op="+one.getOpenid();
-                            response.sendRedirect(sendUrl);
-                        }else{
-                            request.getSession().removeAttribute("openid");
-                            request.getSession().removeAttribute("phone");
 
-                            response.sendRedirect("https://aiot.usky.cn/work/#/pages/login");
+                            String sendUrl = "https://manager.usky.cn/mobile/#/pages/index?op="+one.getOpenid();
+                            response.sendRedirect(URLDecoder.decode(sendUrl, "UTF-8"));
+                        }else{
+                            String sendUrl = "https://manager.usky.cn/mobile/#/pages/login?openId="+openid;
+                            response.sendRedirect(URLDecoder.decode(sendUrl, "UTF-8"));
                         }
-                    }catch (IOException e){
+
+
+                    } catch (Exception e) {
                         throw new BusinessException(e.getMessage());
                     }
-
                 }
+
             }
         }
 
@@ -225,23 +207,22 @@ public class WeChatController {
             throw new BusinessException("验证码错误");
         }
 
-        LambdaQueryWrapper<SysWxOpuser> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(SysWxOpuser::getPhone,phone)
-                .eq(SysWxOpuser::getType,request.getSession().getAttribute("type"));
-        List<SysWxOpuser> list = sysWxOpuserService.list(queryWrapper);
+        LambdaQueryWrapper<MceMbuser> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(MceMbuser::getPhone,phone);
+        List<MceMbuser> list = mceMbuserService.list(queryWrapper);
         if(CollectionUtils.isEmpty(list)){
-            SysWxOpuser one = new SysWxOpuser();
+            MceMbuser one = new MceMbuser();
             one.setPhone(phone);
             if(request.getSession().getAttribute("type") == "app"){
                 one.setOpenid(request.getSession().getAttribute("app_token").toString());
             }else{
                 one.setOpenid(request.getSession().getAttribute("openid").toString());
             }
-            one.setType(request.getSession().getAttribute("type").toString());
-            one.setCreatedTime(LocalDateTime.now());
-            one.setStatus(1);
+            one.setCreateBy(SecurityUtils.getUsername());
+            one.setUserId(SecurityUtils.getUserId());
+            one.setCreateTime(LocalDateTime.now());
 
-            if(sysWxOpuserService.save(one)){
+            if(mceMbuserService.save(one)){
 
             }else{
                 map.put("msg","注册失败,请重新注册");
@@ -261,24 +242,15 @@ public class WeChatController {
 
 
 
+
     /**
-     * Description:[获取微信公众号的Access_Token]
-     *
-     * @return JSONResult
-     * @date 2019-05-19
-     * @author huazai
+     * 微信消息提醒
+     * @return
      */
-    @GetMapping("/getWeChatAccessToken")
-    public String getWeChatAccessToken() {
-        try {
-            // 微信公众号官方获取AccessToken
-            String accessToken = wxMpService.getAccessToken();
+    @PostMapping("sendWeChatMessage")
+    public JSONObject sendWeChatMessage(@RequestBody SendWeChatMessageRequestVO requestVO) {
+        return mceMbuserService.sendWeChatMessage(requestVO);
 
-            return accessToken;
-        } catch (Exception e) {
-
-        }
-        return null;
     }
 
 }

+ 4 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceContent.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -60,6 +62,7 @@ public class MceContent implements Serializable {
     /**
      * 创建时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime createTime;
 
     /**
@@ -70,6 +73,7 @@ public class MceContent implements Serializable {
     /**
      * 更新时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
 

+ 68 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceMbuser.java

@@ -0,0 +1,68 @@
+package com.usky.iot.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class MceMbuser implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 电话号码
+     */
+    private String phone;
+
+    /**
+     * 微信用户id
+     */
+    private String openid;
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 应用ID
+     */
+    private String cids;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新人
+     */
+    private String updateBy;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+
+}

+ 4 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceReceive.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -75,6 +77,7 @@ public class MceReceive implements Serializable {
     /**
      * 创建时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime createTime;
 
     /**
@@ -85,6 +88,7 @@ public class MceReceive implements Serializable {
     /**
      * 更新时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
 

+ 4 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/MceSetting.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -60,6 +62,7 @@ public class MceSetting implements Serializable {
     /**
      * 创建时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime createTime;
 
     /**
@@ -70,6 +73,7 @@ public class MceSetting implements Serializable {
     /**
      * 更新时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
 

+ 16 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/MceMbuserMapper.java

@@ -0,0 +1,16 @@
+package com.usky.iot.mapper;
+
+import com.usky.iot.domain.MceMbuser;
+import com.usky.common.mybatis.core.CrudMapper;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 Mapper 接口
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+public interface MceMbuserMapper extends CrudMapper<MceMbuser> {
+
+}

+ 2 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceContentService.java

@@ -1,5 +1,6 @@
 package com.usky.iot.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.usky.iot.domain.MceContent;
 import com.usky.common.mybatis.core.CrudService;
 
@@ -12,5 +13,5 @@ import com.usky.common.mybatis.core.CrudService;
  * @since 2024-04-19
  */
 public interface MceContentService extends CrudService<MceContent> {
-
+    void sendApp(JSONObject mceReceiveVO, String cids, Integer mceReceiveId, Integer sendType);
 }

+ 24 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceMbuserService.java

@@ -0,0 +1,24 @@
+package com.usky.iot.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.usky.iot.domain.MceMbuser;
+import com.usky.common.mybatis.core.CrudService;
+import com.usky.iot.service.vo.SendWeChatMessageRequestVO;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 服务类
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+public interface MceMbuserService extends CrudService<MceMbuser> {
+
+    /**
+     * 微信消息提醒
+     * @return
+     */
+    JSONObject sendWeChatMessage(SendWeChatMessageRequestVO requestVO);
+}

+ 3 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/MceReceiveService.java

@@ -1,6 +1,7 @@
 package com.usky.iot.service;
 
 import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.BaseBuild;
 import com.usky.iot.domain.DmpDeviceInfo;
@@ -29,4 +30,6 @@ public interface MceReceiveService extends CrudService<MceReceive> {
     Map<String, Object> mceReceiveStatic();
 
     void updateMceReceive(MceReceive mceReceive);
+
+    void add(String mceReceive);
 }

+ 49 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/ExecutorConfig.java

@@ -0,0 +1,49 @@
+package com.usky.iot.service.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+@EnableAsync
+@Slf4j
+public class ExecutorConfig {
+
+    /** 核心线程数(默认线程数) */
+    private int corePoolSize = 10;
+    /** 最大线程数 */
+    private int maxPoolSize = 20;
+    /** 允许线程空闲时间(单位:默认为秒) */
+    private static final int keepAliveTime = 60;
+    /** 缓冲队列大小 */
+    private int queueCapacity = 10;
+
+    @Bean
+    public Executor asyncServiceExecutor(){
+        log.info("start asyncServiceExecutor++++++++++++++++++++++");
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //配置核心线程数
+        executor.setCorePoolSize(corePoolSize);
+        //配置最大线程数
+        executor.setMaxPoolSize(maxPoolSize);
+        //配置空闲时间
+        executor.setKeepAliveSeconds(keepAliveTime);
+        //配置队列大小
+        executor.setQueueCapacity(queueCapacity);
+        //配置线程前缀名
+        executor.setThreadNamePrefix("async-service-");
+
+        // rejection-policy:当pool已经达到max size的时候,如何处理新任务
+        // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+
+        //执行初始化
+        executor.initialize();
+        return executor;
+    }
+}

+ 137 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/HttpClientUtils.java

@@ -0,0 +1,137 @@
+package com.usky.iot.service.config;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ 1. 跨域请求工具类
+ */
+public class HttpClientUtils {
+
+    public static String doGet(String url, Map<String, String> param) {
+
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+
+        String resultString = "";
+        CloseableHttpResponse response = null;
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+
+            // 执行请求
+            response = httpclient.execute(httpGet);
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return resultString;
+    }
+
+    public static String doGet(String url) {
+        return doGet(url, null);
+    }
+
+    public static String doPost(String url, Map<String, String> param) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.setHeader("Content-Type", "application/json");
+            // 创建参数列表
+            if (param != null) {
+                List<NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+
+    public static String doPost(String url) {
+        return doPost(url, null);
+    }
+
+    public static String doPostJson(String url, String json) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 创建请求内容
+            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
+            httpPost.setEntity(entity);
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+}

+ 3 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceTypeServiceImpl.java

@@ -51,6 +51,9 @@ public class DmpDeviceTypeServiceImpl extends AbstractCrudService<DmpDeviceTypeM
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void edit(DmpDeviceType dmpDeviceType) {
+        if (checkNameUnique(dmpDeviceType)) {
+            throw new BusinessException("修改设备类型'" + dmpDeviceType.getTypeName() + "'失败,该设备类型已经存在");
+        }
         dmpDeviceType.setUpdatedBy(SecurityUtils.getUsername());
         dmpDeviceType.setUpdatedTime(LocalDateTime.now());
         this.updateById(dmpDeviceType);

+ 32 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceContentServiceImpl.java

@@ -1,9 +1,17 @@
 package com.usky.iot.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
 import com.usky.iot.domain.MceContent;
 import com.usky.iot.mapper.MceContentMapper;
 import com.usky.iot.service.MceContentService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.MceMbuserService;
+import com.usky.iot.service.config.HttpClientUtils;
+import com.usky.iot.service.vo.SendWeChatMessageRequestVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 /**
@@ -14,7 +22,31 @@ import org.springframework.stereotype.Service;
  * @author han
  * @since 2024-04-19
  */
+@Slf4j
 @Service
 public class MceContentServiceImpl extends AbstractCrudService<MceContentMapper, MceContent> implements MceContentService {
 
+    @Autowired
+    private MceMbuserService mceMbuserService;
+
+    //异步多线程调用
+    @Async("asyncServiceExecutor")
+    public void sendApp(JSONObject mceReceiveVO, String cids,Integer mceReceiveId, Integer sendType){
+        if (sendType.equals(0)){
+            String appUrl = "https://fc-mp-85a26092-1305-4bf1-998f-b609512c8f7b.next.bspapp.com/uniPushMessage";
+            JsonObject jsonObject = new JsonObject();
+            jsonObject.addProperty("cids", cids);
+            jsonObject.addProperty("title", mceReceiveVO.get("infoTitle").toString());
+            jsonObject.addProperty("content", mceReceiveVO.get("infoContent").toString());
+            String resultString = HttpClientUtils.doPostJson(appUrl,jsonObject.toString());
+        }else if (sendType.equals(1)){
+            SendWeChatMessageRequestVO sendWeChatMessageRequestVO = new SendWeChatMessageRequestVO();
+            sendWeChatMessageRequestVO.setInfoContent(mceReceiveVO.get("infoContent").toString());
+            sendWeChatMessageRequestVO.setInfoTitle(mceReceiveVO.get("infoTitle").toString());
+            sendWeChatMessageRequestVO.setInfoId(mceReceiveId);
+            sendWeChatMessageRequestVO.setOpenId(cids);
+            sendWeChatMessageRequestVO.setInfoType(mceReceiveVO.get("infoType").toString());
+            mceMbuserService.sendWeChatMessage(sendWeChatMessageRequestVO);
+        }
+    }
 }

+ 137 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceMbuserServiceImpl.java

@@ -0,0 +1,137 @@
+package com.usky.iot.service.impl;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.usky.common.core.exception.BusinessException;
+import com.usky.common.redis.core.RedisHelper;
+import com.usky.iot.constant.constant;
+import com.usky.iot.domain.MceMbuser;
+import com.usky.iot.mapper.MceMbuserMapper;
+import com.usky.iot.service.MceMbuserService;
+import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.vo.SendWeChatMessageRequestVO;
+import com.usky.iot.service.vo.TemplateData;
+import com.usky.iot.service.vo.TemplateMsgEntityVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.client.RestTemplate;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>
+ * 消息中心_移动端注册表 服务实现类
+ * </p>
+ *
+ * @author han
+ * @since 2024-04-26
+ */
+@Service
+@Slf4j
+public class MceMbuserServiceImpl extends AbstractCrudService<MceMbuserMapper, MceMbuser> implements MceMbuserService {
+
+    @Autowired
+    private RedisHelper redisHelper;
+
+    public String getWeChatAccessToken() {
+        try {
+            // 微信公众号官方获取AccessToken
+            RestTemplate restTemplate = new RestTemplate();
+            String requestParams = String.format(constant.WE_CHAT_ACCESS_TOKEN_URL, constant.WE_CHAT_APP_ID, constant.WE_CHAT_SECRET);
+            ResponseEntity<String> responseEntity = restTemplate.getForEntity(requestParams, String.class);
+
+            String accessToken = JSONObject.parseObject(responseEntity.getBody()).getString("access_token");
+            log.info("we_chat_access_token: " + accessToken);
+
+            return accessToken;
+        } catch (Exception e) {
+            log.info("异常信息:{}", e);
+        }
+        return null;
+    }
+
+    public static long getTimeDifference(String oldTime,String newTime) throws ParseException {
+
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long NTime =df.parse(newTime).getTime();
+        //从对象中拿到时间
+        long OTime = df.parse(oldTime).getTime();
+        long diff=(NTime-OTime)/1000/60;
+        return diff;
+    }
+
+    @Override
+    public JSONObject sendWeChatMessage(@RequestBody SendWeChatMessageRequestVO requestVO) {
+
+        String infoType = requestVO.getInfoType();
+        String infoTitle = requestVO.getInfoTitle();
+        String infoContent = requestVO.getInfoContent();
+        Integer infoId = requestVO.getInfoId();
+        String openId = requestVO.getOpenId();
+
+        //access_token时效校验,判断获取access_token获取时间是否超过有效时间,超过就调用更新,保证一直有效
+        if(!redisHelper.hasKey("access_key")){
+            redisHelper.set("access_time", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+            redisHelper.set("access_key",this.getWeChatAccessToken());
+        }else{
+            try{
+                String access_time = redisHelper.get("access_time").toString();
+                String now_time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                long i = getTimeDifference(access_time,now_time);
+                if(i > 115){ //大于115分钟
+                    redisHelper.set("access_time",LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+                    redisHelper.set("access_key",this.getWeChatAccessToken());
+                }
+            }catch (Exception e){
+                throw new BusinessException(e.getMessage());
+            }
+
+        }
+
+        Object obj = redisHelper.get("access_key");
+        if(obj == null){
+            throw new BusinessException("token不能为空");
+        }
+
+        String token = obj.toString();
+
+        TemplateMsgEntityVO messageVo=new TemplateMsgEntityVO();
+        messageVo.setTTitle(infoTitle);
+        messageVo.setTKeyword1(infoContent);
+//        messageVo.setTKeyword2("测试2");
+//        messageVo.setTKeyword3("测试3");
+        messageVo.setTRemark(infoContent);
+        messageVo.setTUrl(String.format(constant.WE_CHAT_CUSTOMER_CALL_URL,infoId));
+        messageVo.setTemplateId(constant.WE_CHAT_TEMPLATE_ID);
+
+        String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="  + token;
+        Map<String,Object> content=new HashMap<>();
+        Map<String, TemplateData> data = new HashMap<>();
+        data.put("first",new TemplateData(messageVo.getTTitle(),"#44b549"));
+        data.put("keyword1",new TemplateData(messageVo.getTKeyword1(),"#173177"));
+//        data.put("keyword2",new TemplateData(messageVo.getTKeyword2(),"#173177"));
+//        data.put("keyword3",new TemplateData(messageVo.getTKeyword3(),"#173177"));
+        data.put("remark",new TemplateData(messageVo.getTRemark(),"#173177"));
+
+        content.put("touser",openId);
+        content.put("url",messageVo.getTUrl());
+        content.put("template_id",messageVo.getTemplateId());
+        content.put("data",data);
+        String resp = HttpUtil.post(requestUrl, JSONUtil.parseObj(content).toString());
+        System.out.println(content.toString());
+        System.out.println(JSONUtil.parseObj(content));
+        JSONObject result = JSONObject.parseObject(resp);
+        System.out.println("发送消息:" + resp);
+        return result;
+    }
+}

+ 77 - 4
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceReceiveServiceImpl.java

@@ -10,24 +10,29 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.gson.JsonObject;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.common.security.utils.SecurityUtils;
-import com.usky.iot.domain.BaseBuild;
 import com.usky.iot.domain.MceContent;
+import com.usky.iot.domain.MceMbuser;
 import com.usky.iot.domain.MceReceive;
+import com.usky.iot.domain.MceSetting;
 import com.usky.iot.mapper.MceReceiveMapper;
 import com.usky.iot.service.MceContentService;
+import com.usky.iot.service.MceMbuserService;
 import com.usky.iot.service.MceReceiveService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.MceSettingService;
+import com.usky.iot.service.config.HttpClientUtils;
 import com.usky.system.RemoteUserService;
 import com.usky.system.domain.SysUser;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -43,9 +48,15 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
     @Autowired
     private MceContentService mceContentService;
 
+    @Autowired
+    private MceMbuserService mceMbuserService;
+
     @Autowired
     private RemoteUserService remoteUserService;
 
+    @Autowired
+    private MceSettingService mceSettingService;
+
     @Override
     public CommonPage<Object> mceList(String infoTitle, String infoType, String startTime, String endTime, Integer current, Integer size) {
         List<Object> list = new ArrayList<>();
@@ -66,8 +77,9 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
                     .between(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime),MceReceive::getCreateTime,
                             startTime,endTime)
                     .eq(StringUtils.isNotBlank(infoType),MceReceive::getInfoType, infoType)
-//                .eq(MceReceive::getReceiverId, SecurityUtils.getUserId())
-                    .in(CollectionUtils.isNotEmpty(contentIds),MceReceive::getContentId,contentIds);
+                    .eq(MceReceive::getReceiverId, SecurityUtils.getUserId())
+                    .in(CollectionUtils.isNotEmpty(contentIds),MceReceive::getContentId,contentIds)
+                    .orderByDesc(MceReceive::getId);
 //                .inSql(StringUtils.isNotBlank(infoTitle),MceReceive::getContentId,"SELECT id FROM mce_content WHERE " +
 //                        "info_title like '%" + infoTitle + "%' AND tenant_id = "+SecurityUtils.getTenantId()+"");
             page = this.page(page,lambdaQuery);
@@ -207,4 +219,65 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
         }
         this.update(updateWrapper);
     }
+
+    @Override
+    public void add(String mceReceive){
+        JSONObject mceReceiveVO = JSONObject.parseObject(mceReceive);
+        MceContent mceContent = new MceContent();
+        mceContent.setInfoTitle(mceReceiveVO.get("infoTitle").toString());
+        mceContent.setInfoContent(mceReceiveVO.get("infoContent").toString());
+        mceContent.setInfoType(mceReceiveVO.get("infoType").toString());
+        mceContent.setCreateBy(SecurityUtils.getUsername());
+        mceContent.setCreateTime(LocalDateTime.now());
+//        mceContent.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue());
+
+        mceContent.setTenantId(SecurityUtils.getTenantId());
+        mceContentService.save(mceContent);
+        Integer contentId = mceContent.getId();
+        ApiResult<List<SysUser>> userAllList = remoteUserService.userAllList();
+        List<SysUser> list = userAllList.getData();
+        if (CollectionUtils.isNotEmpty(list)) {
+            List<Integer> userIds = new ArrayList<>();
+            for (int g = 0; g < list.size(); g++) {
+                userIds.add(list.get(g).getUserId().intValue());
+            }
+            LambdaQueryWrapper<MceMbuser> lambdaQuery3 = Wrappers.lambdaQuery();
+            lambdaQuery3.in(MceMbuser::getUserId,userIds);
+            List<MceMbuser> list3 = mceMbuserService.list(lambdaQuery3);
+            for (int i = 0; i < list.size(); i++) {
+                MceReceive mceReceive1 = new MceReceive();
+                mceReceive1.setReceiverId(list.get(i).getUserId().intValue());
+                mceReceive1.setContentId(contentId);
+                mceReceive1.setReadFlag(0);
+                mceReceive1.setInfoType(mceReceiveVO.get("infoType").toString());
+                mceReceive1.setModuleId((int)mceReceiveVO.get("id"));
+                mceReceive1.setReceiverName(list.get(i).getUserName());
+                mceReceive1.setCreateBy(SecurityUtils.getUsername());
+                mceReceive1.setCreateTime(LocalDateTime.now());
+                mceReceive1.setTenantId(list.get(i).getTenantId());
+//                mceReceive1.setDeptId(list.get(i).getDeptId().intValue());
+                this.save(mceReceive1);
+                Integer mceReceiveId = mceReceive1.getId();
+                LambdaQueryWrapper<MceSetting> lambdaQuery = Wrappers.lambdaQuery();
+                lambdaQuery.eq(MceSetting::getCreateBy,list.get(i).getUserName());
+                List<MceSetting> list1 = mceSettingService.list(lambdaQuery);
+                if (CollectionUtils.isNotEmpty(list1)){
+                    JSONObject appMode = JSONObject.parseObject(list1.get(0).getAppMode());
+                    JSONObject wcMode = JSONObject.parseObject(list1.get(0).getWcMode());
+                    for (int j = 0; j < list3.size(); j++){
+                        if (appMode.get(mceReceiveVO.get("infoType").toString()).equals(true)){
+                            if (list.get(i).getUserId().equals(list3.get(j).getUserId()) && StringUtils.isNotBlank(list3.get(j).getCids())){
+                                mceContentService.sendApp(mceReceiveVO,list3.get(j).getCids(),0,0);
+                            }
+                        }
+                        if (wcMode.get(mceReceiveVO.get("infoType").toString()).equals(true)){
+                            if (list.get(i).getUserId().equals(list3.get(j).getUserId()) && StringUtils.isNotBlank(list3.get(j).getOpenid())){
+                                mceContentService.sendApp(mceReceiveVO,list3.get(j).getOpenid(),mceReceiveId,1);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

+ 7 - 5
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/MceSettingServiceImpl.java

@@ -57,18 +57,20 @@ public class MceSettingServiceImpl extends AbstractCrudService<MceSettingMapper,
         List<MceSetting> list1 = this.list(lambdaQuery);
         Map<String, Object> map = new HashMap<>();
         if (CollectionUtils.isEmpty(list1)) {
-            Map<String, Integer> map1 = new HashMap<>();
-            map1.put("meetingNotice", 1);
-            map1.put("noticeBulletin", 1);
-            map1.put("inspectionSystem", 1);
-            map1.put("deviceAlarm", 1);
+            Map<String, Object> map1 = new HashMap<>();
+            map1.put("1", true);
+            map1.put("2", true);
+            map1.put("3", true);
+            map1.put("4", true);
             map.put("appMode",map1);
             map.put("pcMode",map1);
             map.put("wcMode",map1);
+            map.put("id",0);
         }else {
             map.put("appMode",JSONObject.parseObject(list1.get(0).getAppMode()));
             map.put("pcMode",JSONObject.parseObject(list1.get(0).getPcMode()));
             map.put("wcMode",JSONObject.parseObject(list1.get(0).getWcMode()));
+            map.put("id",list1.get(0).getId());
         }
         return map;
     }

+ 31 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/SendWeChatMessageRequestVO.java

@@ -0,0 +1,31 @@
+package com.usky.iot.service.vo;
+
+import lombok.Data;
+
+@Data
+public class SendWeChatMessageRequestVO {
+    /**
+     * 消息类型
+     */
+    String infoType;
+
+    /**
+     * 消息标题
+     */
+    String infoTitle;
+
+    /**
+     * 消息内容
+     */
+    String infoContent;
+
+    /**
+     * 消息Id
+     */
+    Integer infoId;
+
+    /**
+     * openId
+     */
+    String openId;
+}

+ 11 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/TemplateData.java

@@ -0,0 +1,11 @@
+package com.usky.iot.service.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@AllArgsConstructor
+@Data
+public class TemplateData {
+    private String value;
+    private String color;
+}

+ 48 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/TemplateMsgEntityVO.java

@@ -0,0 +1,48 @@
+package com.usky.iot.service.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class TemplateMsgEntityVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 标题
+     */
+    private String tTitle;
+    /**
+     * 第一行
+     */
+    private String tKeyword1;
+    /**
+     * 第二行
+     */
+    private String tKeyword2;
+    /**
+     * 第三行
+     */
+    private String tKeyword3;
+    /**
+     * 第四行
+     */
+    private String tKeyword4;
+    /**
+     * 备注
+     */
+    private String tRemark;
+    /**
+     * 跳转连接
+     */
+    private String tUrl;
+    /**
+     * 模板Id
+     */
+    private String templateId;
+    /**
+     * 状态
+     */
+    private int tStatus;
+
+}

+ 18 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/MceMbuserMapper.xml

@@ -0,0 +1,18 @@
+<?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.usky.iot.mapper.MceMbuserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.usky.iot.domain.MceMbuser">
+        <id column="id" property="id" />
+        <result column="phone" property="phone" />
+        <result column="openid" property="openid" />
+        <result column="user_id" property="userId" />
+        <result column="cids" property="cids" />
+        <result column="create_by" property="createBy" />
+        <result column="create_time" property="createTime" />
+        <result column="update_by" property="updateBy" />
+        <result column="update_time" property="updateTime" />
+    </resultMap>
+
+</mapper>