Просмотр исходного кода

优化完成催缴短信方式

java110 лет назад: 2
Родитель
Сommit
cb921ad901

+ 3 - 2
service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java

@@ -297,13 +297,14 @@ public class MachineReturnRepairAdapt extends DatabusAdaptImpl {
         Assert.listOnlyOne(ownerRoomRelDtos, "当前房屋没有所属业主");
         //获取业主id
         String ownerId = ownerRoomRelDtos.get(0).getOwnerId();
+        String userId = "";
         //查询绑定业主
         OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
         ownerAppUserDto.setMemberId(ownerId);
         ownerAppUserDto.setAppType("WECHAT");
         List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMO.queryOwnerAppUsers(ownerAppUserDto);
         if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
-            return;
+            userId = ownerAppUserDtos.get(0).getUserId();
         }
         JSONObject content = new JSONObject();
         content.put("feeTypeName", "维修费");
@@ -317,7 +318,7 @@ public class MachineReturnRepairAdapt extends DatabusAdaptImpl {
             wechatUrl += ("?wAppId=" + smallWeChatDtos.get(0).getAppId());
         }
         content.put("url", wechatUrl);
-        MsgNotifyFactory.sendOweFeeMsg(communityDto.getCommunityId(), ownerAppUserDtos.get(0).getUserId(), content);
+        MsgNotifyFactory.sendOweFeeMsg(communityDto.getCommunityId(), userId, ownerId, content);
 
     }
 }

+ 4 - 9
service-job/src/main/java/com/java110/job/adapt/fee/OweFeeCallableAdapt.java

@@ -92,6 +92,7 @@ public class OweFeeCallableAdapt extends DatabusAdaptImpl {
         String oweUrl = "";
         OweFeeCallablePo updateOweFeeCallablePo = null;
         OwnerAppUserDto ownerAppUserDto = null;
+        String userId = "";
         for (OweFeeCallablePo oweFeeCallablePo : oweFeeCallablePos) {
 
             if (StringUtil.isEmpty(oweFeeCallablePo.getOwnerId()) || oweFeeCallablePo.getOwnerId().startsWith("-")) {
@@ -108,14 +109,8 @@ public class OweFeeCallableAdapt extends DatabusAdaptImpl {
             ownerAppUserDto.setCommunityId(oweFeeCallablePo.getCommunityId());
             ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
             List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
-            if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
-                updateOweFeeCallablePo = new OweFeeCallablePo();
-                updateOweFeeCallablePo.setOfcId(oweFeeCallablePo.getOfcId());
-                updateOweFeeCallablePo.setCommunityId(oweFeeCallablePo.getCommunityId());
-                updateOweFeeCallablePo.setState(OweFeeCallableDto.STATE_FAIL);
-                updateOweFeeCallablePo.setRemark(oweFeeCallablePo.getRemark() + "-业主未绑定");
-                oweFeeCallableV1InnerServiceSMOImpl.updateOweFeeCallable(updateOweFeeCallablePo);
-                continue;
+            if (ownerAppUserDtos != null && ownerAppUserDtos.size() > 0) {
+                userId = ownerAppUserDtos.get(0).getUserId();
             }
 
             oweUrl = FeeDto.PAYER_OBJ_TYPE_ROOM.equals(oweFeeCallablePo.getPayerObjType()) ? oweRoomUrl : oweCarUrl;
@@ -129,7 +124,7 @@ public class OweFeeCallableAdapt extends DatabusAdaptImpl {
             if (OweFeeCallableDto.CALLABLE_WAY_SMS.equals(oweFeeCallablePo.getCallableWay())) {
                 notifyWay = MsgNotifyFactory.NOTIFY_WAY_ALI;
             }
-            ResultVo resultVo = MsgNotifyFactory.sendOweFeeMsg(data.getString("communityId"), ownerAppUserDtos.get(0).getUserId(), content, notifyWay);
+            ResultVo resultVo = MsgNotifyFactory.sendOweFeeMsg(data.getString("communityId"), userId, oweFeeCallablePo.getOwnerId(), content, notifyWay);
             updateOweFeeCallablePo = new OweFeeCallablePo();
             updateOweFeeCallablePo.setOfcId(oweFeeCallablePo.getOfcId());
             updateOweFeeCallablePo.setCommunityId(oweFeeCallablePo.getCommunityId());

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

@@ -31,7 +31,7 @@ public interface IMsgNotify {
      * }
      * @return
      */
-    ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content);
+    ResultVo sendOweFeeMsg(String communityId, String userId,String ownerId, JSONObject content);
 
     /**
      * 发送缴费成功提醒

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

@@ -62,11 +62,11 @@ public class MsgNotifyFactory {
      *                    url
      *                    }
      */
-    public static ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content,String notifyWay) {
+    public static ResultVo sendOweFeeMsg(String communityId, String userId,String ownerId, JSONObject content,String notifyWay) {
         ResultVo resultVo = null;
         try {
             IMsgNotify msgNotify = getMsgNotify(notifyWay);
-            resultVo = msgNotify.sendOweFeeMsg(communityId, userId, content);
+            resultVo = msgNotify.sendOweFeeMsg(communityId, userId,ownerId, content);
         } catch (Exception e) {
             e.printStackTrace();
             logger.error("通知 发送欠费 账单信息 消息", e);
@@ -89,8 +89,8 @@ public class MsgNotifyFactory {
      *                    url
      *                    }
      */
-    public static ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content) {
-        return sendOweFeeMsg(communityId,userId,content,null);
+    public static ResultVo sendOweFeeMsg(String communityId, String userId,String ownerId, JSONObject content) {
+        return sendOweFeeMsg(communityId,userId, ownerId,content,null);
     }
 
     /**

+ 101 - 3
service-job/src/main/java/com/java110/job/msgNotify/ali/AliMsgNotifyImpl.java

@@ -1,24 +1,122 @@
 package com.java110.job.msgNotify.ali;
 
 import com.alibaba.fastjson.JSONObject;
+import com.aliyuncs.CommonRequest;
+import com.aliyuncs.CommonResponse;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.profile.DefaultProfile;
+import com.java110.core.factory.AliSendMessageFactory;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.factory.LogFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.owner.OwnerDto;
+import com.java110.intf.user.IOwnerV1InnerServiceSMO;
+import com.java110.intf.user.IUserV1InnerServiceSMO;
 import com.java110.job.msgNotify.IMsgNotify;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service("aliMsgNotifyImpl")
 public class AliMsgNotifyImpl implements IMsgNotify {
+    private final static Logger logger = LoggerFactory.getLogger(AliMsgNotifyImpl.class);
+    @Autowired
+    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
+
     @Override
-    public ResultVo sendApplyReturnFeeMsg(String communityId,String userId, JSONObject content) {
+    public ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
         return null;
     }
 
+
+    /**
+     * 发送欠费 账单信息
+     *
+     * 需要在阿里云 申请短信模板为
+     * 尊敬的业主,您${house}的${feeType},账单日期${date}至${date2},缴费金额:${mount}元,请及时缴费
+     *
+     * @param communityId 小区
+     * @param userId      用户
+     * @param content     {
+     *                    "feeTypeName",
+     *                    "payerObjName",
+     *                    "billAmountOwed",
+     *                    "date",
+     *                    url
+     *                    }
+     * @return
+     */
     @Override
-    public ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content) {
+    public ResultVo sendOweFeeMsg(String communityId, String userId, String ownerId, JSONObject content) {
+
+
+        if (StringUtil.isEmpty(ownerId) || ownerId.startsWith("-")) {
+            throw new IllegalArgumentException("业主不存在,ownerId = " + ownerId);
+        }
+
+
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setMemberId(ownerId);
+        ownerDto.setCommunityId(communityId);
+        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
+
+        Assert.listOnlyOne(ownerDtos, "业主不存在,ownerId = " + ownerId);
+
+        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
+        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
+        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
+        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
+        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_OWE_TEMPLATE_CODE");
+        DefaultProfile profile = DefaultProfile.getProfile(region,
+                accessKeyId,
+                accessSecret);
+        IAcsClient client = new DefaultAcsClient(profile);
+
+        CommonRequest request = new CommonRequest();
+        request.setSysMethod(MethodType.POST);
+        request.setSysDomain("dysmsapi.aliyuncs.com");
+        request.setSysVersion("2017-05-25");
+        request.setSysAction("SendSms");
+        request.putQueryParameter("RegionId", region);
+        request.putQueryParameter("PhoneNumbers", ownerDtos.get(0).getLink());
+        request.putQueryParameter("SignName", signName);
+        request.putQueryParameter("TemplateCode", templateCode);
+
+        JSONObject param = new JSONObject();
+        param.put("house", content.getString("payerObjName"));
+        param.put("feeType", content.getString("feeTypeName"));
+        param.put("date", content.getString("date").split("~")[0]);
+        param.put("date2", content.getString("date").split("~")[1]);
+        param.put("mount", content.getString("billAmountOwed"));
+        request.putQueryParameter("TemplateParam", param.toString());
+
+        try {
+            CommonResponse response = client.getCommonResponse(request);
+            logger.debug("发送验证码信息:{}", response.getData());
+            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(response.getData(), HttpStatus.OK));
+        } catch (ServerException e) {
+            e.printStackTrace();
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
         return null;
     }
 
     @Override
-    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content,String role) {
+    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
         return null;
     }
 

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

@@ -1,59 +0,0 @@
-package com.java110.job.msgNotify.tencent;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.job.msgNotify.IMsgNotify;
-import com.java110.vo.ResultVo;
-import org.springframework.stereotype.Service;
-
-@Service("tencentMsgNotifyImpl")
-public class TencentMsgNotifyImpl implements IMsgNotify {
-    @Override
-    public ResultVo sendApplyReturnFeeMsg(String communityId,String userId, JSONObject content) {
-        return null;
-    }
-
-    @Override
-    public ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content) {
-        return null;
-    }
-
-    @Override
-    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content,String role) {
-        return null;
-    }
-
-    @Override
-    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;
-    }
-
-    @Override
-    public ResultVo sendFinishRepairOwnerMsg(String communityId, String userId, JSONObject content) {
-        return null;
-    }
-
-    @Override
-    public ResultVo sendReturnRepairMsg(String communityId, String userId, JSONObject content) {
-        return null;
-    }
-
-    @Override
-    public ResultVo sendOaDistributeMsg(String communityId, String userId, JSONObject content) {
-        return null;
-    }
-
-    @Override
-    public ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content) {
-        return null;
-    }
-}

+ 6 - 1
service-job/src/main/java/com/java110/job/msgNotify/wechat/WechatMsgNotifyImpl.java

@@ -18,6 +18,7 @@ import com.java110.job.msgNotify.MsgNotifyFactory;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -147,7 +148,11 @@ public class WechatMsgNotifyImpl implements IMsgNotify {
      * @return
      */
     @Override
-    public ResultVo sendOweFeeMsg(String communityId, String userId, JSONObject content) {
+    public ResultVo sendOweFeeMsg(String communityId, String userId,String ownerId, JSONObject content) {
+
+        if(StringUtil.isEmpty(userId) || userId.startsWith("-")){
+            throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
+        }
 
         String accessToken = wechatTemplateImpl.getAccessToken(communityId);
 

+ 17 - 15
service-job/src/main/java/com/java110/job/task/wechat/PublicWeChatPushMessageTemplate.java

@@ -163,6 +163,9 @@ public class PublicWeChatPushMessageTemplate extends TaskSystemQuartz {
 
         OweFeeCallablePo updateOweFeeCallablePo = null;
         OwnerAppUserDto ownerAppUserDto = null;
+
+        ResultVo resultVo = null;
+        String userId = "";
         for (OweFeeCallablePo tmpOweFeeCallablePo : oweFeeCallablePos) {
             if (StringUtil.isEmpty(tmpOweFeeCallablePo.getOwnerId()) || tmpOweFeeCallablePo.getOwnerId().startsWith("-")) {
                 updateOweFeeCallablePo = new OweFeeCallablePo();
@@ -173,20 +176,6 @@ public class PublicWeChatPushMessageTemplate extends TaskSystemQuartz {
                 oweFeeCallableV1InnerServiceSMOImpl.updateOweFeeCallable(updateOweFeeCallablePo);
                 continue;
             }
-            ownerAppUserDto = new OwnerAppUserDto();
-            ownerAppUserDto.setMemberId(tmpOweFeeCallablePo.getOwnerId());
-            ownerAppUserDto.setCommunityId(tmpOweFeeCallablePo.getCommunityId());
-            ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
-            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
-            if(ownerAppUserDtos == null || ownerAppUserDtos.size() < 1){
-                updateOweFeeCallablePo = new OweFeeCallablePo();
-                updateOweFeeCallablePo.setOfcId(tmpOweFeeCallablePo.getOfcId());
-                updateOweFeeCallablePo.setCommunityId(tmpOweFeeCallablePo.getCommunityId());
-                updateOweFeeCallablePo.setState(OweFeeCallableDto.STATE_FAIL);
-                updateOweFeeCallablePo.setRemark(tmpOweFeeCallablePo.getRemark() + "-业主未绑定");
-                oweFeeCallableV1InnerServiceSMOImpl.updateOweFeeCallable(updateOweFeeCallablePo);
-                continue;
-            }
 
             oweUrl = FeeDto.PAYER_OBJ_TYPE_ROOM.equals(tmpOweFeeCallablePo.getPayerObjType()) ? oweRoomUrl : oweCarUrl;
             content = new JSONObject();
@@ -195,7 +184,20 @@ public class PublicWeChatPushMessageTemplate extends TaskSystemQuartz {
             content.put("billAmountOwed", tmpOweFeeCallablePo.getAmountdOwed());
             content.put("date", DateUtil.dateTimeToDate(tmpOweFeeCallablePo.getStartTime()) + "~" + DateUtil.dateTimeToDate(tmpOweFeeCallablePo.getEndTime()));
             content.put("url", oweUrl);
-            ResultVo resultVo = MsgNotifyFactory.sendOweFeeMsg(communityDto.getCommunityId(), ownerAppUserDtos.get(0).getUserId(), content);
+
+            ownerAppUserDto = new OwnerAppUserDto();
+            ownerAppUserDto.setMemberId(tmpOweFeeCallablePo.getOwnerId());
+            ownerAppUserDto.setCommunityId(tmpOweFeeCallablePo.getCommunityId());
+            ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
+            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+            if (ownerAppUserDtos != null && ownerAppUserDtos.size() > 0) {
+                userId = ownerAppUserDtos.get(0).getUserId();
+            }
+
+            //todo 发送推送消息
+            resultVo = MsgNotifyFactory.sendOweFeeMsg(communityDto.getCommunityId(), userId, tmpOweFeeCallablePo.getOwnerId(), content);
+
+
             updateOweFeeCallablePo = new OweFeeCallablePo();
             updateOweFeeCallablePo.setOfcId(tmpOweFeeCallablePo.getOfcId());
             updateOweFeeCallablePo.setCommunityId(tmpOweFeeCallablePo.getCommunityId());