소스 검색

公司回复消息添加

M墨鱼—_mo 5 년 전
부모
커밋
f03b5484c0

+ 2 - 2
web/src/main/java/com/jpsoft/smart/modules/base/controller/HomePageController.java

@@ -144,7 +144,7 @@ public class HomePageController {
 
 
             if (userService.hasRole(subject, "SYSADMIN")) {
-                for (int i=1;i<31;i++){
+                for (int i=30;i>0;i--){
                     Calendar   calendar   =   new GregorianCalendar();
                     calendar.setTime(new Date());
                     calendar.add(Calendar.DATE,-i);
@@ -163,7 +163,7 @@ public class HomePageController {
             } else  {
                 CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
                 list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
-                for (int i=1;i<31;i++) {
+                for (int i=30;i>0;i--) {
                     Calendar calendar = new GregorianCalendar();
                     calendar.setTime(new Date());
                     calendar.add(Calendar.DATE, -i);

+ 112 - 120
web/src/main/java/com/jpsoft/smart/modules/wechat/controller/WxController.java

@@ -2,9 +2,11 @@ package com.jpsoft.smart.modules.wechat.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.jpsoft.smart.config.WxConfig;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.InformationInfo;
 import com.jpsoft.smart.modules.base.entity.OwnerInfo;
 import com.jpsoft.smart.modules.base.entity.WarningPusher;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.InformationInfoService;
 import com.jpsoft.smart.modules.base.service.OwnerInfoService;
 import com.jpsoft.smart.modules.base.service.WarningPusherService;
@@ -74,7 +76,7 @@ public class WxController {
     private ReplyMessageService replyMessageService;
 
     @Autowired
-    private ValueOperations<String,Object> valueOperations;
+    private ValueOperations<String, Object> valueOperations;
 
     @Autowired
     private RedisServiceImpl redisService;
@@ -91,6 +93,9 @@ public class WxController {
     @Autowired
     private InformationInfoService informationInfoService;
 
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
 
     @ApiOperation(value = "获取微信配置")
     @GetMapping(value = "/getConfig")
@@ -177,15 +182,15 @@ public class WxController {
 
         try {
 
-                HashMap<String, Object> wxMap = new HashMap<>();
+            HashMap<String, Object> wxMap = new HashMap<>();
 
-                wxMap.put("appId", wxPayProperties.getAppId());
+            wxMap.put("appId", wxPayProperties.getAppId());
 
-                HashMap<String, Object> dataMap = new HashMap<String, Object>();
+            HashMap<String, Object> dataMap = new HashMap<String, Object>();
 
-                dataMap.put("wxConfig", wxMap);
+            dataMap.put("wxConfig", wxMap);
 
-                data = dataMap;
+            data = dataMap;
 
         } catch (Exception ex) {
             code = 500;
@@ -216,7 +221,7 @@ public class WxController {
             } else {
                 OwnerInfo ownerInfo = ownerInfoService.get(accessControl.getOwnerId());
                 AccessControlVo accessControlVo = new AccessControlVo();
-                BeanUtils.copyProperties(accessControl,accessControlVo);
+                BeanUtils.copyProperties(accessControl, accessControlVo);
                 accessControlVo.setName(ownerInfo.getName());
                 accessControlVo.setPhoneNum(ownerInfo.getTel());
 
@@ -236,7 +241,7 @@ public class WxController {
 
         }
 
-        return new MessageResult(result, message, data,code);
+        return new MessageResult(result, message, data, code);
     }
 
 
@@ -371,7 +376,7 @@ public class WxController {
 
 
             List<Map> ownerInfoList = ownerInfoService.findByTel(bindPhoneVo.getPhoneNum());
-            if (ownerInfoList.size()<=0){
+            if (ownerInfoList.size() <= 0) {
                 throw new Exception("人员信息未录入,请联系物业公司");
             }
             AccessControl accessControl = accessControlService.findByOwnerId(ownerInfoList.get(0).get("id").toString());
@@ -536,7 +541,7 @@ public class WxController {
         }
 
         JSONObject resultJSON = apiUtil.httpRequest("https://api.parkline.cc/api/facecgi", apiToken, "300", "215301", "01", bindFaceVo.getPhoneNum(), bindFaceVo.getFiledata());
-        System.out.println("返回码:"+resultJSON.getInteger("code")+"-------------");
+        System.out.println("返回码:" + resultJSON.getInteger("code") + "-------------");
         if (!resultJSON.getString("code").equals("100101")) {
             code = resultJSON.getInteger("code");
             if (code == 100100) {
@@ -576,7 +581,7 @@ public class WxController {
         if (accessControl == null) {
             return new MessageResult(false, "此微信还未绑定住户", "", 400);
         }
-        List<InformationInfo> informationInfoList = informationInfoService.findByOwnerIdAndType(accessControl.getOwnerId(),repairsVo.getType());
+        List<InformationInfo> informationInfoList = informationInfoService.findByOwnerIdAndType(accessControl.getOwnerId(), repairsVo.getType());
 
         data = informationInfoList;
 
@@ -594,35 +599,35 @@ public class WxController {
         Object data = "";
         boolean result = true;
 
-        try{
+        try {
 
 
-        if (StringUtils.isBlank(repairsVo.getOpenId()) || StringUtils.isBlank(repairsVo.getContent())) {
-            throw new Exception("参数错误");
-        }
-        if (repairsVo.getType() == null) {
-            throw new Exception("类型不能为空");
-        }
+            if (StringUtils.isBlank(repairsVo.getOpenId()) || StringUtils.isBlank(repairsVo.getContent())) {
+                throw new Exception("参数错误");
+            }
+            if (repairsVo.getType() == null) {
+                throw new Exception("类型不能为空");
+            }
 
-        AccessControl accessControl = accessControlService.findByOpenId(repairsVo.getOpenId());
-        if (accessControl == null) {
-            throw new Exception("此微信还未绑定住户");
-        }
-        InformationInfo informationInfo = new InformationInfo();
-        informationInfo.setId(UUID.randomUUID().toString());
-        informationInfo.setDelFlag(false);
-        informationInfo.setCreateBy(repairsVo.getOpenId());
-        informationInfo.setCreateTime(new Date());
-        informationInfo.setStatus("0");
-        informationInfo.setContent(repairsVo.getContent());
-        informationInfo.setOwnerId(accessControl.getOwnerId());
-        informationInfo.setType(repairsVo.getType());
-
-        informationInfoService.insert(informationInfo);
-
-        }catch (Exception e){
+            AccessControl accessControl = accessControlService.findByOpenId(repairsVo.getOpenId());
+            if (accessControl == null) {
+                throw new Exception("此微信还未绑定住户");
+            }
+            InformationInfo informationInfo = new InformationInfo();
+            informationInfo.setId(UUID.randomUUID().toString());
+            informationInfo.setDelFlag(false);
+            informationInfo.setCreateBy(repairsVo.getOpenId());
+            informationInfo.setCreateTime(new Date());
+            informationInfo.setStatus("0");
+            informationInfo.setContent(repairsVo.getContent());
+            informationInfo.setOwnerId(accessControl.getOwnerId());
+            informationInfo.setType(repairsVo.getType());
+
+            informationInfoService.insert(informationInfo);
+
+        } catch (Exception e) {
             e.printStackTrace();
-            log.error(e.getMessage(),e);
+            log.error(e.getMessage(), e);
             message = e.getMessage();
             result = false;
             code = 400;
@@ -642,22 +647,21 @@ public class WxController {
         Object data = "";
         boolean result = true;
 
-        try{
-
+        try {
 
 
-        if (id == null) {
-            throw new Exception("id为空");
-        }
+            if (id == null) {
+                throw new Exception("id为空");
+            }
 
 
-        InformationInfo informationInfo = informationInfoService.get(id);
-        data = informationInfo;
+            InformationInfo informationInfo = informationInfoService.get(id);
+            data = informationInfo;
 
 
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
-            log.error(e.getMessage(),e);
+            log.error(e.getMessage(), e);
             message = e.getMessage();
             code = 400;
             result = false;
@@ -665,22 +669,21 @@ public class WxController {
         return new MessageResult(result, message, data, code);
     }
 
-    @ApiOperation(value="验证服务器地址的有效性")
+    @ApiOperation(value = "验证服务器地址的有效性")
     @GetMapping("/get")
     @ResponseBody
     public String index(@RequestParam(defaultValue = "") String signature,
                         @RequestParam(defaultValue = "") String timestamp,
                         @RequestParam(defaultValue = "") String nonce,
-                        @RequestParam(defaultValue = "") String echostr){
+                        @RequestParam(defaultValue = "") String echostr) {
         log.warn("signature=" + signature);
         log.warn("timestamp=" + timestamp);
         log.warn("nonce=" + nonce);
         log.warn("echostr=" + echostr);
 
-        if (WeixinUtil.checkSignature(wxConfig.getToken(),signature,timestamp,nonce)){
+        if (WeixinUtil.checkSignature(wxConfig.getToken(), signature, timestamp, nonce)) {
             return echostr;
-        }
-        else{
+        } else {
             return "index";
         }
     }
@@ -690,24 +693,24 @@ public class WxController {
     @ApiOperation(value = "创建二维码")
     @PostMapping("/qrcode/create")
     @ApiImplicitParams({
-            @ApiImplicitParam(name="expire_seconds", paramType="query", required=true, value="该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。"),
-            @ApiImplicitParam(name="action_name", paramType="query", required=true, value="二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值"),
-            @ApiImplicitParam(name="scene_id", paramType="query", value="场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)"),
-            @ApiImplicitParam(name="scene_str", paramType="query", value="场景值ID(字符串形式的ID),字符串类型,长度限制为1到64")
+            @ApiImplicitParam(name = "expire_seconds", paramType = "query", required = true, value = "该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。"),
+            @ApiImplicitParam(name = "action_name", paramType = "query", required = true, value = "二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值"),
+            @ApiImplicitParam(name = "scene_id", paramType = "query", value = "场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)"),
+            @ApiImplicitParam(name = "scene_str", paramType = "query", value = "场景值ID(字符串形式的ID),字符串类型,长度限制为1到64")
     })
-    public cn.hutool.json.JSONObject createQrcode(@RequestParam(name = "expire_seconds",defaultValue = "300") long expireSeconds,
-                                                  @RequestParam(name = "action_name",defaultValue = "QR_STR_SCENE") String actionName,
-                                                  @RequestParam(name = "scene_id",required = false) String sceneId,
-                                                  @RequestParam(name = "scene_str",required = false) String sceneStr){
+    public cn.hutool.json.JSONObject createQrcode(@RequestParam(name = "expire_seconds", defaultValue = "300") long expireSeconds,
+                                                  @RequestParam(name = "action_name", defaultValue = "QR_STR_SCENE") String actionName,
+                                                  @RequestParam(name = "scene_id", required = false) String sceneId,
+                                                  @RequestParam(name = "scene_str", required = false) String sceneStr) {
         cn.hutool.json.JSONObject resultObj = new cn.hutool.json.JSONObject();
 
         try {
             StringBuilder urlBuilder = new StringBuilder();
-            AccessToken accessToken = WeixinUtil.getAccessToken(wxConfig.getAppId(),wxConfig.getAppSecret());
+            AccessToken accessToken = WeixinUtil.getAccessToken(wxConfig.getAppId(), wxConfig.getAppSecret());
 
             urlBuilder.append(wxConfig.getCreateQrCodeUrl())
                     .append("?access_token=")
-                    .append(URLEncoder.encode(accessToken.getToken(),"UTF-8"));
+                    .append(URLEncoder.encode(accessToken.getToken(), "UTF-8"));
 
             cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject();
             jsonObject.put("expire_seconds", expireSeconds);
@@ -720,24 +723,23 @@ public class WxController {
 
             keyBuilder.append(accessToken);
 
-            if(StringUtils.isNotEmpty(sceneId)) {
+            if (StringUtils.isNotEmpty(sceneId)) {
                 scene.put("scene_id", sceneId);
                 keyBuilder.append(sceneId);
             }
 
-            if(StringUtils.isNotEmpty(sceneStr)) {
+            if (StringUtils.isNotEmpty(sceneStr)) {
                 scene.put("scene_str", sceneStr);
                 keyBuilder.append(sceneStr);
             }
 
-            String qrcodeUrl = (String)valueOperations.get("QRCODE_" + keyBuilder.toString());
+            String qrcodeUrl = (String) valueOperations.get("QRCODE_" + keyBuilder.toString());
 
-            if (StringUtils.isNotEmpty(qrcodeUrl)){
-                resultObj.put("data",qrcodeUrl);
+            if (StringUtils.isNotEmpty(qrcodeUrl)) {
+                resultObj.put("data", qrcodeUrl);
                 resultObj.put("result", true);
-            }
-            else{
-                actionInfo.put("scene",scene);
+            } else {
+                actionInfo.put("scene", scene);
 
                 jsonObject.put("action_info", actionInfo);
 
@@ -771,18 +773,16 @@ public class WxController {
                         resultObj.put("data", qrcodeUrl);
                         resultObj.put("result", true);
                     }
-                }
-                else{
+                } else {
                     resultObj.put("result", false);
                     resultObj.put("message", "weixin服务器未正常返回!");
                 }
             }
-        }
-        catch (Exception ex){
-            log.error(ex.getMessage(),ex);
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
 
-            resultObj.put("message",ex.getMessage());
-            resultObj.put("result",false);
+            resultObj.put("message", ex.getMessage());
+            resultObj.put("result", false);
         }
 
         return resultObj;
@@ -790,19 +790,18 @@ public class WxController {
 
     @ApiOperation(value = "处理消息事件")
     @PostMapping("/get")
-    public void processEvent(HttpServletRequest request, HttpServletResponse response){
-        try{
+    public void processEvent(HttpServletRequest request, HttpServletResponse response) {
+        try {
             log.warn("收到post请求");
 
             cn.hutool.json.JSONObject requestJson = null;
 
-            if("json".equals(wxConfig.getContentType())){
+            if ("json".equals(wxConfig.getContentType())) {
                 String jsonStr = new BufferedReader(new InputStreamReader(request.getInputStream()))
                         .lines().parallel().collect(Collectors.joining(System.lineSeparator()));
 
                 requestJson = new cn.hutool.json.JSONObject(jsonStr);
-            }
-            else {
+            } else {
                 requestJson = WeixinUtil.xmlToJson(request.getInputStream());
             }
 
@@ -819,10 +818,10 @@ public class WxController {
             正常扫码是:"EventKey":"7000,2142006";
             当未关注时,扫码是"EventKey":"qrscene_7000,2142006"
             */
-            if(StringUtils.isNotEmpty(eventKey) && eventKey.indexOf("_")!=-1){
+            if (StringUtils.isNotEmpty(eventKey) && eventKey.indexOf("_") != -1) {
                 String[] arr = eventKey.split("_");
 
-                if(arr.length>0){
+                if (arr.length > 0) {
                     eventKey = arr[1];
                 }
             }
@@ -835,7 +834,7 @@ public class WxController {
 
             boolean processed = false;
 
-            if (StringUtils.isNotEmpty(eventKey) && eventKey.indexOf(",")!=-1) {
+            if (StringUtils.isNotEmpty(eventKey) && eventKey.indexOf(",") != -1) {
                 String[] keys = eventKey.split(",");
                 String eventCode = keys[0];
                 String id = keys[1];
@@ -844,51 +843,46 @@ public class WxController {
                 ReplyMessage replyMessage = replyMessageService.findByEvent(eventCode);
 
                 if (replyMessage != null) {
+                    if (eventCode == "5000") {
+                        WarningPusher warningPusher = warningPusherService.get(id);
+                        if (warningPusher == null) {
+                            WeixinUtil.replyTextMessage(response, wechatId, openId, "绑定信息不存在,请联系管理员");
+                        } else if (StringUtils.isNotBlank(warningPusher.getOpenId())) {
+                            WeixinUtil.replyTextMessage(response, wechatId, openId, "此二维码已被绑定,请联系管理员");
+                        } else {
+                            warningPusher.setOpenId(openId);
+                            warningPusher.setUpdateTime(new Date());
+                            warningPusherService.update(warningPusher);
+                            WeixinUtil.replyTextMessage(response, wechatId, openId, replyMessage.getMessage());
+                        }
 
-                    WarningPusher warningPusher = warningPusherService.get(id);
-                    if (warningPusher == null){
-                        WeixinUtil.replyTextMessage(response, wechatId, openId,"绑定信息不存在,请联系管理员");
                     }
-                    else if (StringUtils.isNotBlank(warningPusher.getOpenId())){
-                        WeixinUtil.replyTextMessage(response, wechatId, openId,"此二维码已被绑定,请联系管理员");
-                    }else {
-                        warningPusher.setOpenId(openId);
-                        warningPusher.setUpdateTime(new Date());
-                        warningPusherService.update(warningPusher);
-                        WeixinUtil.replyTextMessage(response, wechatId, openId,replyMessage.getMessage());
+                    if ("4000".equals(eventCode)){
+                        CompanyInfo companyInfo = companyInfoService.get(id);
+                        if (companyInfo == null){
+                            WeixinUtil.replyTextMessage(response,wechatId,openId,"您的公司暂时不在我们的管辖内,请联系管理员!");
+                        }else {
+                            WeixinUtil.replyArticlesMessage(response,wechatId,openId,companyInfo.getName(),replyMessage.getMessage(),companyInfo.getLogo(),"http://wisdomhousewechat.sudaonline.net/prevention-xxd/upyes.html");
+                        }
                     }
 
 
-
                     processed = true;
                 }
-            }
-            else if ("文章".equals(eventKey)){
+            } else if ("文章".equals(eventKey)) {
 
-                WeixinUtil.replyArticlesMessage(response,wechatId,openId,"复工复学疫情防控监管平台","即日起接受预定,货源紧张,先订先得。\n预定电话:13972127999 市企业联合会蔡秘书长;\n19971390396 刘经理;15607217777 付经理。","http://wisdomhousewechat.sudaonline.net/1111.jpg","https://mp.weixin.qq.com/s/nXYp0m8OOYdWBRu-80SnmQ");
-            }
-            else {
-                WeixinUtil.replyTextMessage(response, wechatId, openId,"您好,欢迎关注荆鹏云管家。\n" +
+                WeixinUtil.replyArticlesMessage(response, wechatId, openId, "复工复学疫情防控监管平台", "即日起接受预定,货源紧张,先订先得。\n预定电话:13972127999 市企业联合会蔡秘书长;\n19971390396 刘经理;15607217777 付经理。", "http://wisdomhousewechat.sudaonline.net/1111.jpg", "https://mp.weixin.qq.com/s/nXYp0m8OOYdWBRu-80SnmQ");
+            } else {
+                WeixinUtil.replyTextMessage(response, wechatId, openId, "您好,欢迎关注荆鹏云管家。\n" +
                         "\n" +
                         "疫情监管产品介绍:<a href=\"https://mp.weixin.qq.com/s/nXYp0m8OOYdWBRu-80SnmQ\">点击查看详情</a>");
             }
-            //开发者在5秒内未回复任何内容
-//                for (EventCallback callback : callbackList) {
-//                    if (StringUtils.isNotEmpty(eventKey) && eventKey.startsWith(callback.getCode())) {
-//                        callback.process(wechatId, openId, eventKey);
-//
-//                        WeixinUtil.replyTextMessage(response, wechatId, openId, callback.getMessage());
-//
-//                        processed = true;
-//                        break;
-//                    }
-//                }
-//            }
-
-            if(!processed) {
+
+
+            if (!processed) {
                 String responseText = "success";
 
-                if("subscribe".equals(event)){
+                if ("subscribe".equals(event)) {
                    /* ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId,event);
 
                     if(replyMessage!=null) {
@@ -898,14 +892,12 @@ public class WxController {
                         log.warn(openId + ",事件:" + event + "未设置自动回复!");
                         response.getWriter().print(responseText);
                     }*/
-                }
-                else {
+                } else {
                     response.getWriter().print(responseText);
                 }
             }
-        }
-        catch (Exception ex){
-            log.error(ex.getMessage(),ex);
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
 
             try {
                 response.getWriter().print("fail");