Your Name лет назад: 2
Родитель
Сommit
36c4a77dee

+ 1 - 38
service-job/src/main/java/com/java110/job/adapt/Repair/MachineAddOwnerRepairAdapt.java

@@ -56,23 +56,12 @@ public class MachineAddOwnerRepairAdapt extends DatabusAdaptImpl {
     @Autowired
     private ICommunityInnerServiceSMO communityInnerServiceSMO;
 
-    @Autowired
-    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
-
-    @Autowired
-    private ISmallWechatAttrInnerServiceSMO smallWechatAttrInnerServiceSMOImpl;
-
     @Autowired
     private IPrivilegeInnerServiceSMO privilegeInnerServiceSMO;
 
     @Autowired
     private IStaffAppAuthInnerServiceSMO staffAppAuthInnerServiceSMO;
 
-    @Autowired
-    private RestTemplate outRestTemplate;
-
-    //模板信息推送地址
-    private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
 
     @Override
     public void execute(Business business, List<Business> businesses) {
@@ -135,32 +124,7 @@ public class MachineAddOwnerRepairAdapt extends DatabusAdaptImpl {
      * @param communityDto
      */
     private void sendMessage(JSONObject paramIn, CommunityDto communityDto) {
-        //查询公众号配置
-        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
-        smallWeChatDto.setWeChatType("1100");
-        smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
-        smallWeChatDto.setObjId(communityDto.getCommunityId());
-        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
-        if (smallWeChatDto == null || smallWeChatDtos.size() <= 0) {
-            logger.info("未配置微信公众号信息,定时任务执行结束");
-            return;
-        }
-        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
-        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
-        smallWechatAttrDto.setCommunityId(communityDto.getCommunityId());
-        smallWechatAttrDto.setWechatId(weChatDto.getWeChatId());
-        smallWechatAttrDto.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE);
-        List<SmallWechatAttrDto> smallWechatAttrDtos = smallWechatAttrInnerServiceSMOImpl.querySmallWechatAttrs(smallWechatAttrDto);
-        if (smallWechatAttrDtos == null || smallWechatAttrDtos.size() <= 0) {
-            logger.info("未配置微信公众号消息模板");
-            return;
-        }
-        String templateId = smallWechatAttrDtos.get(0).getValue();
-        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
-        if (StringUtil.isEmpty(accessToken)) {
-            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
-            return;
-        }
+
         //查询小区物业公司
         CommunityMemberDto communityMemberDto = new CommunityMemberDto();
         communityMemberDto.setCommunityId(communityDto.getCommunityId());
@@ -179,7 +143,6 @@ public class MachineAddOwnerRepairAdapt extends DatabusAdaptImpl {
             if (userIds.contains(userDto.getUserId())) {
                 continue;
             }
-
             JSONObject content = new JSONObject();
             content.put("repairTypeName",paramIn.getString("repairTypeName"));
             if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {

+ 179 - 394
service-job/src/main/java/com/java110/job/adapt/Repair/MachineDistributeLeaflets.java

@@ -1,28 +1,20 @@
 package com.java110.job.adapt.Repair;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.factory.CommunitySettingFactory;
-import com.java110.core.factory.WechatFactory;
 import com.java110.core.log.LoggerFactory;
 import com.java110.dto.community.CommunityDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.machine.MachinePrinterDto;
-import com.java110.dto.owner.OwnerAppUserDto;
 import com.java110.dto.printerRule.PrinterRuleDto;
 import com.java110.dto.printerRule.PrinterRuleMachineDto;
 import com.java110.dto.printerRule.PrinterRuleRepairDto;
 import com.java110.dto.repair.RepairDto;
 import com.java110.dto.repair.RepairUserDto;
 import com.java110.dto.wechat.SmallWeChatDto;
-import com.java110.dto.wechat.SmallWechatAttrDto;
-import com.java110.dto.user.StaffAppAuthDto;
 import com.java110.dto.user.UserDto;
 import com.java110.dto.system.Business;
-import com.java110.dto.wechat.Content;
-import com.java110.dto.wechat.Data;
-import com.java110.dto.wechat.PropertyFeeTemplateMessage;
 import com.java110.intf.common.*;
 import com.java110.intf.community.ICommunityInnerServiceSMO;
 import com.java110.intf.community.IRepairInnerServiceSMO;
@@ -33,6 +25,7 @@ import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
 import com.java110.intf.user.IStaffAppAuthInnerServiceSMO;
 import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.msgNotify.MsgNotifyFactory;
 import com.java110.job.printer.IPrinter;
 import com.java110.po.owner.RepairUserPo;
 import com.java110.utils.cache.MappingCache;
@@ -107,8 +100,6 @@ public class MachineDistributeLeaflets extends DatabusAdaptImpl {
     @Autowired
     private IMachinePrinterV1InnerServiceSMO machinePrinterV1InnerServiceSMOImpl;
 
-    //模板信息推送地址
-    private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
 
     @Override
     public void execute(Business business, List<Business> businesses) {
@@ -141,230 +132,132 @@ public class MachineDistributeLeaflets extends DatabusAdaptImpl {
         List<RepairUserDto> repairUserDtos = repairUserInnerServiceSMO.queryRepairUsers(repairUserDto);
         //获取员工处理状态(10001 处理中;10002 结单;10003 退单;10004 转单;10005 提交;10006 已派单;10007 已评价;10008 已回访;10009 待支付;11000 待评价;12000 已支付;12001 暂停)
         String state = repairUserDtos.get(0).getState();
-        if (!state.equals("10005")) {
-            //获取报修id
-            String repairId = repairUserDtos.get(0).getRepairId();
-            RepairDto repairDto = new RepairDto();
-            repairDto.setRepairId(repairId);
-            List<RepairDto> repairDtos = repairInnerServiceSMO.queryRepairs(repairDto);
-            //查询报修状态(1000 未派单;1100 接单;1200 退单;1300 转单;1400 申请支付;1500 支付失败;1700 待评价;1800 电话回访;1900 办理完成;2000 未办理结单)
-            String repairState = repairDtos.get(0).getState();
-            //获取联系人姓名
-            String repairName = repairDtos.get(0).getRepairName();
-            //获取联系人电话
-            String tel = repairDtos.get(0).getTel();
-            //获取位置信息
-            String repairObjName = repairDtos.get(0).getRepairObjName();
-            //报修对象ID
-            String repairObjId = repairDtos.get(0).getRepairObjId();
-            //获取报修内容
-            String context = repairDtos.get(0).getContext();
-            //获取派单时间
-            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            String time = format.format(repairUserDtos.get(0).getCreateTime());
-            //获取小区id
-            String communityId = repairDtos.get(0).getCommunityId();
-            //查询小区信息
-            CommunityDto communityDto = new CommunityDto();
-            communityDto.setCommunityId(communityId);
-            List<CommunityDto> communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto);
-            if (repairState.equals("1100") && businessRepairUser.getString("state").equals("10006")) { //派单
-                JSONObject paramIn = new JSONObject();
-                for (Business business : businesses) {
-                    String businessTypeCd = business.getBusinessTypeCd();
-                    if (!StringUtil.isEmpty(businessTypeCd) && businessTypeCd.equals("130200030001")) {
-                        JSONObject data = business.getData();
-                        if (!StringUtil.isEmpty(data.getString("state")) && data.getString("state").equals("10001")) {
-                            paramIn.put("staffId", data.getString("staffId"));
-                            paramIn.put("staffName", data.getString("staffName"));
-                        } else if (data.getString("state").equals("10006")) {
-                            paramIn.put("preStaffId", data.getString("preStaffId"));
-                            paramIn.put("preStaffName", data.getString("preStaffName"));
-                        }
-                    }
-                }
-                paramIn.put("repairName", repairName);
-                paramIn.put("repairObjName", repairObjName);
-                paramIn.put("tel", tel);
-                paramIn.put("communityId", communityId);
-                paramIn.put("context", context);
-                paramIn.put("time", time);
-                paramIn.put("repairObjId", repairObjId);
-                paramIn.put("repairId", repairId);
-                //给维修师傅推送信息
-                sendMsg(paramIn, communityDtos.get(0));
-                //派单成功给业主推送信息
-                publishMsg(paramIn, communityDtos.get(0));
-
-                // 自动打印小票
-                autoPrintRepair(repairUserDtos.get(0).getRuId(),repairDtos.get(0).getRepairType(),communityDtos.get(0));
-                
-                //为企业微信群发消息
-                sendMsgToWechatGroup(paramIn, communityDtos.get(0));
-
-                
-            } else if (repairState.equals("1100") && !businessRepairUser.getString("state").equals("10006")) {
-                JSONObject paramIn = new JSONObject();
-                paramIn.put("staffId", businessRepairUser.getString("staffId"));
-                paramIn.put("context", context);
-                paramIn.put("time", time);
-                paramIn.put("repairObjId", repairObjId);
-                paramIn.put("preStaffId", businessRepairUser.getString("preStaffId"));
-                paramIn.put("repairName", repairName);
-                paramIn.put("tel", tel);
-                paramIn.put("repairObjName", repairObjName);
-                //抢单成功给维修师傅推送信息
-                publishMessage(paramIn, communityDtos.get(0));
-                //抢单成功给业主推送信息
-                publishMsg(paramIn, communityDtos.get(0));
-            } else if (repairState.equals("1300")) {   //转单
-                JSONObject paramIn = new JSONObject();
-                paramIn.put("repairName", repairName);
-                paramIn.put("repairObjName", repairObjName);
-                paramIn.put("tel", tel);
-                paramIn.put("context", context);
-                paramIn.put("time", time);
-                paramIn.put("staffId", businessRepairUser.getString("staffId"));
-                paramIn.put("preStaffName", businessRepairUser.getString("preStaffName"));
-                //给维修师傅推送信息
-                sendMessage(paramIn, communityDtos.get(0));
-            }
-        }
-    }
-
-    /**
-     * // 自动打印小票
-     * @param ruId
-     * @param repairType
-     * @param communityDto
-     */
-    private void autoPrintRepair(String ruId,String repairType, CommunityDto communityDto) {
-
-        PrinterRuleRepairDto printerRuleRepairDto = new PrinterRuleRepairDto();
-        printerRuleRepairDto.setCommunityId(communityDto.getCommunityId());
-        printerRuleRepairDto.setRepairType(repairType);
-        List<PrinterRuleRepairDto> printerRuleRepairDtos = printerRuleRepairV1InnerServiceSMOImpl.queryPrinterRuleRepairs(printerRuleRepairDto);
-
-        if (printerRuleRepairDtos == null || printerRuleRepairDtos.size() < 1) {
+        if (RepairUserDto.STATE_SUBMIT.equals(state)) {
             return;
         }
-
-        PrinterRuleDto printerRuleDto = new PrinterRuleDto();
-        printerRuleDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
-        printerRuleDto.setCommunityId(communityDto.getCommunityId());
-        printerRuleDto.setState(PrinterRuleDto.STATE_NORMAL);
-        int count = printerRuleV1InnerServiceSMOImpl.queryPrinterRulesCount(printerRuleDto);
-
-        if (count < 1) {
-            return;
-        }
-
-        PrinterRuleMachineDto printerRuleMachineDto = new PrinterRuleMachineDto();
-        printerRuleMachineDto.setCommunityId(communityDto.getCommunityId());
-        printerRuleMachineDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
-        List<PrinterRuleMachineDto> printerRuleMachineDtos = printerRuleMachineV1InnerServiceSMOImpl.queryPrinterRuleMachines(printerRuleMachineDto);
-        if (printerRuleMachineDtos == null || printerRuleMachineDtos.size() < 1) {
-            return;
-        }
-
-        for (PrinterRuleMachineDto tmpPrinterRuleMachineDto : printerRuleMachineDtos) {
-            try {
-                doPrint(tmpPrinterRuleMachineDto, ruId);
-            } catch (Exception e) {
-                e.printStackTrace();
+        //获取报修id
+        String repairId = repairUserDtos.get(0).getRepairId();
+        RepairDto repairDto = new RepairDto();
+        repairDto.setRepairId(repairId);
+        List<RepairDto> repairDtos = repairInnerServiceSMO.queryRepairs(repairDto);
+        //查询报修状态(1000 未派单;1100 接单;1200 退单;1300 转单;1400 申请支付;1500 支付失败;1700 待评价;1800 电话回访;1900 办理完成;2000 未办理结单)
+        String repairState = repairDtos.get(0).getState();
+        //获取联系人姓名
+        String repairName = repairDtos.get(0).getRepairName();
+        //获取联系人电话
+        String tel = repairDtos.get(0).getTel();
+        //获取位置信息
+        String repairObjName = repairDtos.get(0).getRepairObjName();
+        //报修对象ID
+        String repairObjId = repairDtos.get(0).getRepairObjId();
+        //获取报修内容
+        String context = repairDtos.get(0).getContext();
+        //获取派单时间
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String time = format.format(repairUserDtos.get(0).getCreateTime());
+        //获取小区id
+        String communityId = repairDtos.get(0).getCommunityId();
+        //查询小区信息
+        CommunityDto communityDto = new CommunityDto();
+        communityDto.setCommunityId(communityId);
+        List<CommunityDto> communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto);
+        if (repairState.equals("1100") && businessRepairUser.getString("state").equals("10006")) { //派单
+            JSONObject paramIn = new JSONObject();
+            for (Business business : businesses) {
+                String businessTypeCd = business.getBusinessTypeCd();
+                if (!StringUtil.isEmpty(businessTypeCd) && businessTypeCd.equals("130200030001")) {
+                    JSONObject data = business.getData();
+                    if (!StringUtil.isEmpty(data.getString("state")) && data.getString("state").equals("10001")) {
+                        paramIn.put("staffId", data.getString("staffId"));
+                        paramIn.put("staffName", data.getString("staffName"));
+                    } else if (data.getString("state").equals("10006")) {
+                        paramIn.put("preStaffId", data.getString("preStaffId"));
+                        paramIn.put("preStaffName", data.getString("preStaffName"));
+                    }
+                }
             }
+            paramIn.put("repairName", repairName);
+            paramIn.put("repairObjName", repairObjName);
+            paramIn.put("tel", tel);
+            paramIn.put("communityId", communityId);
+            paramIn.put("context", context);
+            paramIn.put("time", time);
+            paramIn.put("repairObjId", repairObjId);
+            paramIn.put("repairId", repairId);
+            //给维修师傅推送信息
+            sendStaffMsg(paramIn, communityDtos.get(0));
+            //派单成功给业主推送信息
+            sendOwnerMsg(paramIn, communityDtos.get(0));
+
+            // 自动打印小票
+            autoPrintRepair(repairUserDtos.get(0).getRuId(), repairDtos.get(0).getRepairType(), communityDtos.get(0));
+
+            //为企业微信群发消息
+            sendMsgToWechatGroup(paramIn, communityDtos.get(0));
+
+
+        } else if (repairState.equals("1100") && !businessRepairUser.getString("state").equals("10006")) {
+            JSONObject paramIn = new JSONObject();
+            paramIn.put("staffId", businessRepairUser.getString("staffId"));
+            paramIn.put("context", context);
+            paramIn.put("time", time);
+            paramIn.put("repairObjId", repairObjId);
+            paramIn.put("preStaffId", businessRepairUser.getString("preStaffId"));
+            paramIn.put("repairName", repairName);
+            paramIn.put("tel", tel);
+            paramIn.put("repairObjName", repairObjName);
+            //抢单成功给维修师傅推送信息
+            sendStaffMsg(paramIn, communityDtos.get(0));
+            //抢单成功给业主推送信息
+            sendOwnerMsg(paramIn, communityDtos.get(0));
+        } else if (repairState.equals("1300")) {   //转单
+            JSONObject paramIn = new JSONObject();
+            paramIn.put("repairName", repairName);
+            paramIn.put("repairObjName", repairObjName);
+            paramIn.put("tel", tel);
+            paramIn.put("context", context);
+            paramIn.put("time", time);
+            paramIn.put("staffId", businessRepairUser.getString("staffId"));
+            paramIn.put("preStaffName", businessRepairUser.getString("preStaffName"));
+            //给维修师傅推送信息
+            sendStaffMsg(paramIn, communityDtos.get(0));
         }
 
-
     }
 
-    private void doPrint(PrinterRuleMachineDto tmpPrinterRuleMachineDto, String ruId) {
-        MachinePrinterDto machinePrinterDto = new MachinePrinterDto();
-        machinePrinterDto.setCommunityId(tmpPrinterRuleMachineDto.getCommunityId());
-        machinePrinterDto.setMachineId(tmpPrinterRuleMachineDto.getMachineId());
-        List<MachinePrinterDto> machinePrinterDtos = machinePrinterV1InnerServiceSMOImpl.queryMachinePrinters(machinePrinterDto);
-
-        Assert.listOnlyOne(machinePrinterDtos, "云打印机不存在");
-
-        IPrinter printer = ApplicationContextFactory.getBean(machinePrinterDtos.get(0).getImplBean(), IPrinter.class);
-
-        if (printer == null) {
-            throw new CmdException("打印机异常,未包含适配器");
-        }
-
-        printer.printRepair(ruId, tmpPrinterRuleMachineDto.getCommunityId(), Integer.parseInt(tmpPrinterRuleMachineDto.getQuantity()), machinePrinterDtos.get(0));
-
-
-    }
 
     /**
-     * 转单给维修师傅推送信息
+     * 派单给维修师傅推送信息
      *
      * @param paramIn
      * @param communityDto
      */
-    private void sendMessage(JSONObject paramIn, CommunityDto communityDto) {
-        //查询公众号配置
-        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
-        smallWeChatDto.setWeChatType("1100");
-        smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
-        smallWeChatDto.setObjId(communityDto.getCommunityId());
-        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
-        if (smallWeChatDto == null || smallWeChatDtos.size() <= 0) {
-            logger.info("未配置微信公众号信息,定时任务执行结束");
-            return;
-        }
-        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
-        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
-        smallWechatAttrDto.setCommunityId(communityDto.getCommunityId());
-        smallWechatAttrDto.setWechatId(weChatDto.getWeChatId());
-        smallWechatAttrDto.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
-        List<SmallWechatAttrDto> smallWechatAttrDtos = smallWechatAttrInnerServiceSMOImpl.querySmallWechatAttrs(smallWechatAttrDto);
-        if (smallWechatAttrDtos == null || smallWechatAttrDtos.size() <= 0) {
-            logger.info("未配置微信公众号消息模板");
-            return;
-        }
-        String templateId = smallWechatAttrDtos.get(0).getValue();
-        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
-        if (StringUtil.isEmpty(accessToken)) {
-            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
-            return;
-        }
-        String url = sendMsgUrl + accessToken;
-        //根据 userId 查询到openId
-        StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
-        staffAppAuthDto.setStaffId(paramIn.getString("staffId"));
-        staffAppAuthDto.setAppType("WECHAT");
-        List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
-        if (staffAppAuthDtos.size() > 0) {
-            String openId = staffAppAuthDtos.get(0).getOpenId();
-            Data data = new Data();
-            PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
-            templateMessage.setTemplate_id(templateId);
-            templateMessage.setTouser(openId);
-            data.setFirst(new Content("您有新的维修任务,维修信息如下:"));
-            data.setKeyword1(new Content(paramIn.getString("repairName")));
-            data.setKeyword2(new Content(paramIn.getString("tel")));
-            data.setKeyword3(new Content(paramIn.getString("time")));
-            data.setKeyword4(new Content(paramIn.getString("context") + "\r\n" + "报修位置:" + paramIn.getString("repairObjName")));
-            data.setRemark(new Content(paramIn.getString("preStaffName") + "转单给您,请及时登录公众号接单确认!"));
-            templateMessage.setData(data);
-            //获取员工公众号地址
-            String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN,"STAFF_WECHAT_URL");
-            templateMessage.setUrl(wechatUrl);
-            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
-            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
-            logger.info("微信模板返回内容:{}", responseEntity);
+    private void sendStaffMsg(JSONObject paramIn, CommunityDto communityDto) {
+        JSONObject content = new JSONObject();
+        content.put("repairName", paramIn.getString("repairName"));
+        content.put("tel", paramIn.getString("tel"));
+        content.put("time", paramIn.getString("time"));
+        String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL");
+        content.put("url", wechatUrl);
+        //获取具体位置
+        String address = "";
+        if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
+            address = paramIn.getString("repairObjName");
+        } else {
+            address = communityDto.getName() + paramIn.getString("repairObjName");
         }
+        content.put("address", address);
+        MsgNotifyFactory.sendDistributeRepairStaffMsg(communityDto.getCommunityId(), paramIn.getString("staffId"), content);
     }
 
+
     /**
-     * 派单给维修师傅推送信息
+     * 派单(抢单)成功后给业主推送信息
      *
      * @param paramIn
      * @param communityDto
      */
-    private void sendMsg(JSONObject paramIn, CommunityDto communityDto) {
+    private void sendOwnerMsg(JSONObject paramIn, CommunityDto communityDto) {
         //查询公众号配置
         SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
         smallWeChatDto.setWeChatType("1100");
@@ -375,58 +268,36 @@ public class MachineDistributeLeaflets extends DatabusAdaptImpl {
             logger.info("未配置微信公众号信息,定时任务执行结束");
             return;
         }
-        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
-        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
-        smallWechatAttrDto.setCommunityId(communityDto.getCommunityId());
-        smallWechatAttrDto.setWechatId(weChatDto.getWeChatId());
-        smallWechatAttrDto.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
-        List<SmallWechatAttrDto> smallWechatAttrDtos = smallWechatAttrInnerServiceSMOImpl.querySmallWechatAttrs(smallWechatAttrDto);
-        if (smallWechatAttrDtos == null || smallWechatAttrDtos.size() <= 0) {
-            logger.info("未配置微信公众号消息模板");
-            return;
-        }
-        String templateId = smallWechatAttrDtos.get(0).getValue();
-        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
-        if (StringUtil.isEmpty(accessToken)) {
-            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
+        //查询维修员工信息
+        UserDto userDto = new UserDto();
+        userDto.setUserId(paramIn.getString("staffId"));
+        userDto.setStatusCd("0");
+        List<UserDto> users = userInnerServiceSMO.getUsers(userDto);
+        //获取维修员工姓名
+        String name = users.get(0).getName();
+        //获取维修员工联系方式
+        String tel = users.get(0).getTel();
+        //获取用户id
+        String preStaffId = paramIn.getString("preStaffId");
+        if (StringUtil.isEmpty(preStaffId)) {
             return;
         }
-        //获取具体位置
-        String address = "";
-        if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
-            address = paramIn.getString("repairObjName");
+
+        JSONObject content = new JSONObject();
+        content.put("name", name);
+        content.put("tel", tel);
+        content.put("time", paramIn.getString("time"));
+        String wechatUrl = UrlCache.getOwnerUrl();
+        if (!StringUtil.isEmpty(wechatUrl) && wechatUrl.contains("?")) {
+            wechatUrl += ("&wAppId=" + smallWeChatDtos.get(0).getAppId());
         } else {
-            address = communityDto.getName() + paramIn.getString("repairObjName");
+            wechatUrl += ("?wAppId=" + smallWeChatDtos.get(0).getAppId());
         }
-        String url = sendMsgUrl + accessToken;
-        //根据 userId 查询到openId
-        StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
-        staffAppAuthDto.setStaffId(paramIn.getString("staffId"));
-        staffAppAuthDto.setStaffName(paramIn.getString("staffName"));
-        staffAppAuthDto.setAppType("WECHAT");
-        List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
-        if (staffAppAuthDtos.size() > 0) {
-            String openId = staffAppAuthDtos.get(0).getOpenId();
-            Data data = new Data();
-            PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
-            templateMessage.setTemplate_id(templateId);
-            templateMessage.setTouser(openId);
-            data.setFirst(new Content("您有新的维修任务,维修信息如下:"));
-            data.setKeyword1(new Content(paramIn.getString("repairName")));
-            data.setKeyword2(new Content(paramIn.getString("tel")));
-            data.setKeyword3(new Content(paramIn.getString("time")));
-            data.setKeyword4(new Content(paramIn.getString("context") + "\r\n" + "报修位置:" + address));
-            data.setRemark(new Content("请及时登录公众号接单确认!"));
-            templateMessage.setData(data);
-            //获取员工公众号地址
-            String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN,"STAFF_WECHAT_URL");
-            templateMessage.setUrl(wechatUrl);
-            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
-            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
-            logger.info("微信模板返回内容:{}", responseEntity);
-        }
-    }
+        content.put("url", wechatUrl);
 
+        MsgNotifyFactory.sendDistributeRepairOwnerMsg(communityDto.getCommunityId(), preStaffId, content);
+
+    }
 
     private void sendMsgToWechatGroup(JSONObject paramIn, CommunityDto communityDto) {
 
@@ -477,7 +348,7 @@ public class MachineDistributeLeaflets extends DatabusAdaptImpl {
             return;
         }
 
-        String imgUrl = MappingCache.getValue(MappingConstant.FILE_DOMAIN,"IMG_PATH");
+        String imgUrl = MappingCache.getValue(MappingConstant.FILE_DOMAIN, "IMG_PATH");
         FileRelDto fileRelDto = new FileRelDto();
         fileRelDto.setObjId(paramIn.getString("repairId"));
         List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
@@ -512,154 +383,68 @@ public class MachineDistributeLeaflets extends DatabusAdaptImpl {
 
 
     /**
-     * 派单(抢单)成功后给业主推送信息
+     * // 自动打印小票
      *
-     * @param paramIn
+     * @param ruId
+     * @param repairType
      * @param communityDto
      */
-    private void publishMsg(JSONObject paramIn, CommunityDto communityDto) {
-        //查询公众号配置
-        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
-        smallWeChatDto.setWeChatType("1100");
-        smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
-        smallWeChatDto.setObjId(communityDto.getCommunityId());
-        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
-        if (smallWeChatDto == null || smallWeChatDtos.size() <= 0) {
-            logger.info("未配置微信公众号信息,定时任务执行结束");
+    private void autoPrintRepair(String ruId, String repairType, CommunityDto communityDto) {
+
+        PrinterRuleRepairDto printerRuleRepairDto = new PrinterRuleRepairDto();
+        printerRuleRepairDto.setCommunityId(communityDto.getCommunityId());
+        printerRuleRepairDto.setRepairType(repairType);
+        List<PrinterRuleRepairDto> printerRuleRepairDtos = printerRuleRepairV1InnerServiceSMOImpl.queryPrinterRuleRepairs(printerRuleRepairDto);
+
+        if (printerRuleRepairDtos == null || printerRuleRepairDtos.size() < 1) {
             return;
         }
-        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
-        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
-        smallWechatAttrDto.setCommunityId(communityDto.getCommunityId());
-        smallWechatAttrDto.setWechatId(weChatDto.getWeChatId());
-        smallWechatAttrDto.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
-        List<SmallWechatAttrDto> smallWechatAttrDtos = smallWechatAttrInnerServiceSMOImpl.querySmallWechatAttrs(smallWechatAttrDto);
-        if (smallWechatAttrDtos == null || smallWechatAttrDtos.size() <= 0) {
-            logger.info("未配置微信公众号消息模板");
+
+        PrinterRuleDto printerRuleDto = new PrinterRuleDto();
+        printerRuleDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
+        printerRuleDto.setCommunityId(communityDto.getCommunityId());
+        printerRuleDto.setState(PrinterRuleDto.STATE_NORMAL);
+        int count = printerRuleV1InnerServiceSMOImpl.queryPrinterRulesCount(printerRuleDto);
+
+        if (count < 1) {
             return;
         }
-        String templateId = smallWechatAttrDtos.get(0).getValue();
-        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
-        if (StringUtil.isEmpty(accessToken)) {
-            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
+
+        PrinterRuleMachineDto printerRuleMachineDto = new PrinterRuleMachineDto();
+        printerRuleMachineDto.setCommunityId(communityDto.getCommunityId());
+        printerRuleMachineDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
+        List<PrinterRuleMachineDto> printerRuleMachineDtos = printerRuleMachineV1InnerServiceSMOImpl.queryPrinterRuleMachines(printerRuleMachineDto);
+        if (printerRuleMachineDtos == null || printerRuleMachineDtos.size() < 1) {
             return;
         }
-        //查询维修员工信息
-        UserDto userDto = new UserDto();
-        userDto.setUserId(paramIn.getString("staffId"));
-        userDto.setStatusCd("0");
-        List<UserDto> users = userInnerServiceSMO.getUsers(userDto);
-        //获取维修员工姓名
-        String name = users.get(0).getName();
-        //获取维修员工联系方式
-        String tel = users.get(0).getTel();
-        //获取用户id
-        String preStaffId = paramIn.getString("preStaffId");
-        if (!StringUtil.isEmpty(preStaffId)) {
-            OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
-            ownerAppUserDto.setUserId(preStaffId);
-            ownerAppUserDto.setAppType("WECHAT");
-            //查询绑定业主
-            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMO.queryOwnerAppUsers(ownerAppUserDto);
-            if (ownerAppUserDtos.size() > 0) {
-                //获取openId
-                String openId = ownerAppUserDtos.get(0).getOpenId();
-                String url = sendMsgUrl + accessToken;
-                Data data = new Data();
-                PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
-                templateMessage.setTemplate_id(templateId);
-                templateMessage.setTouser(openId);
-                data.setFirst(new Content("您的报修受理成功,维修人员信息如下:"));
-                data.setKeyword1(new Content(paramIn.getString("context")));
-                data.setKeyword2(new Content(name));
-                data.setKeyword3(new Content(tel));
-                data.setKeyword4(new Content(paramIn.getString("time")));
-                data.setRemark(new Content("您的报修已受理,请保持电话畅通,以便维修人员及时跟您取得联系!感谢您的使用!"));
-                templateMessage.setData(data);
-                //获取业主公众号地址
-                String wechatUrl = UrlCache.getOwnerUrl();
-                if (!StringUtil.isEmpty(wechatUrl) && wechatUrl.contains("?")) {
-                    wechatUrl += ("&wAppId=" + weChatDto.getAppId());
-                } else {
-                    wechatUrl += ("?wAppId=" + weChatDto.getAppId());
-                }
 
-                templateMessage.setUrl(wechatUrl);
-                logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
-                ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
-                logger.info("微信模板返回内容:{}", responseEntity);
+        for (PrinterRuleMachineDto tmpPrinterRuleMachineDto : printerRuleMachineDtos) {
+            try {
+                doPrint(tmpPrinterRuleMachineDto, ruId);
+            } catch (Exception e) {
+                e.printStackTrace();
             }
         }
+
+
     }
 
-    /**
-     * 抢单成功后给维修师傅推送信息
-     *
-     * @param paramIn
-     * @param communityDto
-     */
-    private void publishMessage(JSONObject paramIn, CommunityDto communityDto) {
-        //查询公众号配置
-        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
-        smallWeChatDto.setWeChatType("1100");
-        smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
-        smallWeChatDto.setObjId(communityDto.getCommunityId());
-        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
-        if (smallWeChatDto == null || smallWeChatDtos.size() <= 0) {
-            logger.info("未配置微信公众号信息,定时任务执行结束");
-            return;
-        }
-        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
-        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
-        smallWechatAttrDto.setCommunityId(communityDto.getCommunityId());
-        smallWechatAttrDto.setWechatId(weChatDto.getWeChatId());
-        smallWechatAttrDto.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
-        List<SmallWechatAttrDto> smallWechatAttrDtos = smallWechatAttrInnerServiceSMOImpl.querySmallWechatAttrs(smallWechatAttrDto);
-        if (smallWechatAttrDtos == null || smallWechatAttrDtos.size() <= 0) {
-            logger.info("未配置微信公众号消息模板");
-            return;
-        }
-        String templateId = smallWechatAttrDtos.get(0).getValue();
-        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
-        if (StringUtil.isEmpty(accessToken)) {
-            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
-            return;
-        }
-        //获取具体位置
-        String address = "";
-        if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
-            address = paramIn.getString("repairObjName");
-        } else {
-            address = communityDto.getName() + paramIn.getString("repairObjName");
-        }
-        //根据 userId 查询到openId
-        StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
-        staffAppAuthDto.setStaffId(paramIn.getString("staffId"));
-        staffAppAuthDto.setAppType("WECHAT");
-        List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
 
-        if(staffAppAuthDtos == null || staffAppAuthDtos.size() < 1){
-            logger.error("员工未做员工认证");
-            return;
+    private void doPrint(PrinterRuleMachineDto tmpPrinterRuleMachineDto, String ruId) {
+        MachinePrinterDto machinePrinterDto = new MachinePrinterDto();
+        machinePrinterDto.setCommunityId(tmpPrinterRuleMachineDto.getCommunityId());
+        machinePrinterDto.setMachineId(tmpPrinterRuleMachineDto.getMachineId());
+        List<MachinePrinterDto> machinePrinterDtos = machinePrinterV1InnerServiceSMOImpl.queryMachinePrinters(machinePrinterDto);
+
+        Assert.listOnlyOne(machinePrinterDtos, "云打印机不存在");
+
+        IPrinter printer = ApplicationContextFactory.getBean(machinePrinterDtos.get(0).getImplBean(), IPrinter.class);
+
+        if (printer == null) {
+            throw new CmdException("打印机异常,未包含适配器");
         }
-        String openId = staffAppAuthDtos.get(0).getOpenId();
-        String url = sendMsgUrl + accessToken;
-        Data data = new Data();
-        PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
-        templateMessage.setTemplate_id(templateId);
-        templateMessage.setTouser(openId);
-        data.setFirst(new Content("恭喜您抢单成功,报修信息如下:"));
-        data.setKeyword1(new Content(paramIn.getString("repairName")));
-        data.setKeyword2(new Content(paramIn.getString("tel")));
-        data.setKeyword3(new Content(paramIn.getString("time")));
-        data.setKeyword4(new Content(paramIn.getString("context") + "\r\n" + "报修位置:" + address));
-        data.setRemark(new Content("请及时与客户取得联系!"));
-        templateMessage.setData(data);
-        //获取员工公众号地址
-        String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN,"STAFF_WECHAT_URL");
-        templateMessage.setUrl(wechatUrl);
-        logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
-        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
-        logger.info("微信模板返回内容:{}", responseEntity);
+
+        printer.printRepair(ruId, tmpPrinterRuleMachineDto.getCommunityId(), Integer.parseInt(tmpPrinterRuleMachineDto.getQuantity()), machinePrinterDtos.get(0));
+
     }
 }

+ 30 - 0
service-job/src/main/java/com/java110/job/msgNotify/IMsgNotify.java

@@ -61,4 +61,34 @@ public interface IMsgNotify {
      * @return
      */
     ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content);
+
+    /**
+     * 派单给维修师傅
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    repairName,
+     *                    tel,
+     *                    time,
+     *                    address
+     *                    }
+     * @return
+     */
+    ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content);
+
+    /**
+     * 派单给业主通知
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    name,
+     *                    tel,
+     *                    time,
+     *                    url
+     *                    }
+     * @return
+     */
+    ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content);
 }

+ 111 - 16
service-job/src/main/java/com/java110/job/msgNotify/MsgNotifyFactory.java

@@ -1,16 +1,20 @@
 package com.java110.job.msgNotify;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.core.log.LoggerFactory;
+import com.java110.job.adapt.Repair.MachineAddOwnerRepairAdapt;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
 
 /**
  * 消息通知工具类
  */
 public class MsgNotifyFactory {
+    private static Logger logger = LoggerFactory.getLogger(MsgNotifyFactory.class);
 
     public static final String DEFAULT_MSG_NOTIFY_WAY = "DEFAULT_MSG_NOTIFY_WAY";
 
@@ -32,8 +36,17 @@ public class MsgNotifyFactory {
      * @return
      */
     public static ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
-        IMsgNotify msgNotify = getMsgNotify();
-        return msgNotify.sendApplyReturnFeeMsg(communityId, userId, content);
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendApplyReturnFeeMsg(communityId, userId, content);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 申请退费 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
     }
 
     /**
@@ -50,8 +63,17 @@ public class MsgNotifyFactory {
      *                    }
      */
     public static ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content) {
-        IMsgNotify msgNotify = getMsgNotify();
-        return msgNotify.sendOweFeeMsg(communityId, userId, content);
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendOweFeeMsg(communityId, userId, content);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 发送欠费 账单信息 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
     }
 
     /**
@@ -68,25 +90,98 @@ public class MsgNotifyFactory {
      *                    }
      */
     public static ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
-        IMsgNotify msgNotify = getMsgNotify();
-        return msgNotify.sendPayFeeMsg(communityId, userId, content, role);
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendPayFeeMsg(communityId, userId, content, role);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 发送缴费成功提醒 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
     }
 
     /**
      * 业主报修时
+     *
      * @param communityId 小区
-     * @param userId 用户
-     * @param content {
-     *                repairTypeName,
-     *                repairObjName,
-     *                repairName,
-     *                url
-     * }
+     * @param userId      用户
+     * @param content     {
+     *                    repairTypeName,
+     *                    repairObjName,
+     *                    repairName,
+     *                    url
+     *                    }
      * @return
      */
-    public static ResultVo sendAddOwnerRepairMsg(String communityId,String userId,JSONObject content){
-        IMsgNotify msgNotify = getMsgNotify();
-        return msgNotify.sendAddOwnerRepairMsg(communityId, userId, content);
+    public static ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendAddOwnerRepairMsg(communityId, userId, content);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 业主报修时 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
+    }
+
+    /**
+     * 派单给维修师傅
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    repairName,
+     *                    tel,
+     *                    time,
+     *                    address
+     *                    }
+     * @return
+     */
+    public static ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendDistributeRepairStaffMsg(communityId, userId, content);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 派单给维修师傅 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
+    }
+
+    /**
+     * 派单给业主通知
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    name,
+     *                    tel,
+     *                    time,
+     *                    url
+     *                    }
+     * @return
+     */
+    public static ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
+        ResultVo resultVo = null;
+        try {
+            IMsgNotify msgNotify = getMsgNotify();
+            resultVo = msgNotify.sendDistributeRepairOwnerMsg(communityId, userId, content);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("通知 派单给维修师傅 消息", e);
+            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
+
+        return resultVo;
     }
 
     /**

+ 10 - 0
service-job/src/main/java/com/java110/job/msgNotify/ali/AliMsgNotifyImpl.java

@@ -26,4 +26,14 @@ public class AliMsgNotifyImpl implements IMsgNotify {
     public ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
         return null;
     }
+
+    @Override
+    public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
+        return null;
+    }
+
+    @Override
+    public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
+        return null;
+    }
 }

+ 10 - 0
service-job/src/main/java/com/java110/job/msgNotify/tencent/TencentMsgNotifyImpl.java

@@ -26,4 +26,14 @@ public class TencentMsgNotifyImpl implements IMsgNotify {
     public ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
         return null;
     }
+
+    @Override
+    public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
+        return null;
+    }
+
+    @Override
+    public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
+        return null;
+    }
 }

+ 128 - 20
service-job/src/main/java/com/java110/job/msgNotify/wechat/WechatMsgNotifyImpl.java

@@ -57,10 +57,12 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
     private static final Map<String, String[]> templateKeys = new HashMap<>();
 
     static {
-        templateKeys.put(SPEC_CD_OWE_FEE_TEMPLATE, new String[]{"缴费类型","房号","总金额","缴费周期"});
+        templateKeys.put(SPEC_CD_OWE_FEE_TEMPLATE, new String[]{"缴费类型", "房号", "总金额", "缴费周期"});
         templateKeys.put(SPEC_CD_WECHAT_PROCESS_TEMPLATE, new String[]{"流程名称", "发起时间", "发起人"});
         templateKeys.put(SPEC_CD_WECHAT_SUCCESS_TEMPLATE, new String[]{"缴费房间", "费用类型", "缴费时间", "缴费金额"});
-        templateKeys.put(SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE, new String[]{"报修类型","报修地址","报修问题"});
+        templateKeys.put(SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE, new String[]{"报修类型", "报修地址", "报修问题"});
+        templateKeys.put(SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE, new String[]{"联系人", "手机号", "报修时间", "维修地址"});
+        templateKeys.put(SPEC_CD_WECHAT_SCHEDULE_TEMPLATE, new String[]{"平台受理人", "联系电话", "受理时间"});
 
     }
 
@@ -127,15 +129,16 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
 
     /**
      * 欠费通知
+     *
      * @param communityId 小区
-     * @param userId 用户
-     * @param content {
+     * @param userId      用户
+     * @param content     {
      *                    "feeTypeName",
-     *                     "payerObjName",
-     *                     "billAmountOwed",
-     *                     "date",
-     *                url
-     * }
+     *                    "payerObjName",
+     *                    "billAmountOwed",
+     *                    "date",
+     *                    url
+     *                    }
      * @return
      */
     @Override
@@ -180,7 +183,7 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
     }
 
     @Override
-    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content,String role) {
+    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
 
         String accessToken = wechatTemplateImpl.getAccessToken(communityId);
         String url = sendMsgUrl + accessToken;
@@ -191,7 +194,7 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
         }
         String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_SUCCESS_TEMPLATE));
         String openId = "";
-        if(MsgNotifyFactory.ROLE_OWNER.equals(role)){
+        if (MsgNotifyFactory.ROLE_OWNER.equals(role)) {
             OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
             ownerAppUserDto.setCommunityId(communityId);
             ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
@@ -200,8 +203,8 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
             if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
                 throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
             }
-            openId= ownerAppUserDtos.get(0).getOpenId();
-        }else{
+            openId = ownerAppUserDtos.get(0).getOpenId();
+        } else {
             StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
             staffAppAuthDto.setStaffId(userId);
             staffAppAuthDto.setAppType("WECHAT");
@@ -233,14 +236,15 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
 
     /**
      * 业主报修时
+     *
      * @param communityId 小区
-     * @param userId 用户
-     * @param content {
-     *                repairTypeName,
-     *                repairObjName,
-     *                repairName,
-     *                url
-     * }
+     * @param userId      用户
+     * @param content     {
+     *                    repairTypeName,
+     *                    repairObjName,
+     *                    repairName,
+     *                    url
+     *                    }
      * @return
      */
     @Override
@@ -280,4 +284,108 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
         JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
         return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
     }
+
+    /**
+     * 派单给维修师傅
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    repairName,
+     *                    tel,
+     *                    time,
+     *                    address
+     *                    }
+     * @return
+     */
+    @Override
+    public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
+        String accessToken = wechatTemplateImpl.getAccessToken(communityId);
+
+        StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
+        staffAppAuthDto.setStaffId(userId);
+        staffAppAuthDto.setAppType("WECHAT");
+        List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
+        if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
+            throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
+        }
+        String openId = staffAppAuthDtos.get(0).getOpenId();
+
+        Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
+
+        if (mapping == null) {
+            throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
+        }
+        String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE));
+
+        String url = sendMsgUrl + accessToken;
+        Data data = new Data();
+        PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
+        templateMessage.setTemplate_id(templateId);
+        templateMessage.setTouser(openId);
+        data.setKeyword1(new Content(content.getString("repairName")));
+        data.setKeyword2(new Content(content.getString("tel")));
+        data.setKeyword3(new Content(content.getString("time")));
+        data.setKeyword4(new Content(content.getString("address")));
+        templateMessage.setData(data);
+        templateMessage.setUrl(content.getString("url"));
+        logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+        logger.info("微信模板返回内容:{}", responseEntity);
+
+        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
+        return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
+    }
+
+    /**
+     * 派单给业主通知
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    name,
+     *                    tel,
+     *                    time,
+     *                    url
+     *                    }
+     * @return
+     */
+    @Override
+    public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
+        String accessToken = wechatTemplateImpl.getAccessToken(communityId);
+        String url = sendMsgUrl + accessToken;
+        Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
+
+        if (mapping == null) {
+            throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
+        }
+        String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_SCHEDULE_TEMPLATE));
+        String openId = "";
+
+        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+        ownerAppUserDto.setCommunityId(communityId);
+        ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
+        ownerAppUserDto.setUserId(userId);
+        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+        if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+            throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
+        }
+        openId = ownerAppUserDtos.get(0).getOpenId();
+
+        Data data = new Data();
+        PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
+        templateMessage.setTemplate_id(templateId);
+        templateMessage.setTouser(openId);
+        data.setKeyword1(new Content(content.getString("name")));
+        data.setKeyword2(new Content(content.getString("tel")));
+        data.setKeyword3(new Content(content.getString("time")));
+        templateMessage.setData(data);
+        templateMessage.setUrl(content.getString("url"));
+        logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+        logger.info("微信模板返回内容:{}", responseEntity);
+
+        JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
+        return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
+    }
 }

+ 22 - 22
service-store/src/main/java/com/java110/store/cmd/smallWechat/SaveSmallWechatCmd.java

@@ -199,29 +199,29 @@ public class SaveSmallWechatCmd extends Cmd {
 //            throw new CmdException("保存数据失败");
 //        }
         //报修工单派单和转单提醒给维修师傅 通知--模板ID
-        smallWechatAttrPo = new SmallWechatAttrPo();
-        smallWechatAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
-        smallWechatAttrPo.setCommunityId(reqJson.getString("objId"));
-        smallWechatAttrPo.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
-        smallWechatAttrPo.setValue("这里请填写报修工单派单和转单通知模板ID");
-        smallWechatAttrPo.setWechatId(wechatId);
-        flag = smallWechatAttrV1InnerServiceSMOImpl.saveSmallWechatAttr(smallWechatAttrPo);
-
-        if (flag < 1) {
-            throw new CmdException("保存数据失败");
-        }
+//        smallWechatAttrPo = new SmallWechatAttrPo();
+//        smallWechatAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+//        smallWechatAttrPo.setCommunityId(reqJson.getString("objId"));
+//        smallWechatAttrPo.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
+//        smallWechatAttrPo.setValue("这里请填写报修工单派单和转单通知模板ID");
+//        smallWechatAttrPo.setWechatId(wechatId);
+//        flag = smallWechatAttrV1InnerServiceSMOImpl.saveSmallWechatAttr(smallWechatAttrPo);
+//
+//        if (flag < 1) {
+//            throw new CmdException("保存数据失败");
+//        }
         //报修工单派单和抢单提醒给业主,安排师傅维修(进度提醒) 通知--模板ID
-        smallWechatAttrPo = new SmallWechatAttrPo();
-        smallWechatAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
-        smallWechatAttrPo.setCommunityId(reqJson.getString("objId"));
-        smallWechatAttrPo.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
-        smallWechatAttrPo.setValue("这里请填写报修工单派单和抢单提醒给业主,安排师傅维修(进度提醒)通知模板ID");
-        smallWechatAttrPo.setWechatId(wechatId);
-        flag = smallWechatAttrV1InnerServiceSMOImpl.saveSmallWechatAttr(smallWechatAttrPo);
-
-        if (flag < 1) {
-            throw new CmdException("保存数据失败");
-        }
+//        smallWechatAttrPo = new SmallWechatAttrPo();
+//        smallWechatAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+//        smallWechatAttrPo.setCommunityId(reqJson.getString("objId"));
+//        smallWechatAttrPo.setSpecCd(SmallWechatAttrDto.SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
+//        smallWechatAttrPo.setValue("这里请填写报修工单派单和抢单提醒给业主,安排师傅维修(进度提醒)通知模板ID");
+//        smallWechatAttrPo.setWechatId(wechatId);
+//        flag = smallWechatAttrV1InnerServiceSMOImpl.saveSmallWechatAttr(smallWechatAttrPo);
+//
+//        if (flag < 1) {
+//            throw new CmdException("保存数据失败");
+//        }
         //报修工单维修完成提醒给业主 通知--模板ID
         smallWechatAttrPo = new SmallWechatAttrPo();
         smallWechatAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));