Procházet zdrojové kódy

Merge branch 'master' of https://github.com/java110/MicroCommunity

java110 před 5 roky
rodič
revize
4e211ac3a5

+ 9 - 0
java110-bean/src/main/java/com/java110/dto/fee/BillOweFeeDto.java

@@ -28,6 +28,7 @@ public class BillOweFeeDto extends PageDto implements Serializable {
     private String communityId;
     private String state;
     private String createTime;
+    private String[] ownerIds;
 
 
     public String getOweId() {
@@ -141,4 +142,12 @@ public class BillOweFeeDto extends PageDto implements Serializable {
     public void setCreateTime(String createTime) {
         this.createTime = createTime;
     }
+
+    public String[] getOwnerIds() {
+        return ownerIds;
+    }
+
+    public void setOwnerIds(String[] ownerIds) {
+        this.ownerIds = ownerIds;
+    }
 }

+ 31 - 0
java110-bean/src/main/java/com/java110/entity/wechat/Content.java

@@ -0,0 +1,31 @@
+package com.java110.entity.wechat;
+
+/**
+ * @description: 消息内容字体颜色
+ * @author: zcc
+ * @create: 2020-06-16 09:46
+ **/
+public class Content {
+    private String value;//消息内容
+    private String color = "#173177"; //消息字体颜色
+
+    public Content( String value) {
+       this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+}

+ 65 - 0
java110-bean/src/main/java/com/java110/entity/wechat/Data.java

@@ -0,0 +1,65 @@
+package com.java110.entity.wechat;
+
+/**
+ * @description: 物业费消息模板data
+ * @author: zcc
+ * @create: 2020-06-16 09:43
+ *
+ *
+ * 标题物业缴费通知
+ * 行业IT科技 - 互联网|电子商务
+ * 详细内容{{first.DATA}}
+ * 用户地址:{{keyword1.DATA}}
+ * 物业费月份:{{keyword2.DATA}}
+ * 物业费金额:{{keyword3.DATA}}
+ * {{remark.DATA}}
+ *
+ *
+ **/
+public class Data {
+    private  Content first;
+    private  Content keyword1;
+    private  Content keyword2;
+    private  Content keyword3;
+    private  Content remark;
+
+    public Content getFirst() {
+        return first;
+    }
+
+    public void setFirst(Content first) {
+        this.first = first;
+    }
+
+    public Content getKeyword1() {
+        return keyword1;
+    }
+
+    public void setKeyword1(Content keyword1) {
+        this.keyword1 = keyword1;
+    }
+
+    public Content getKeyword2() {
+        return keyword2;
+    }
+
+    public void setKeyword2(Content keyword2) {
+        this.keyword2 = keyword2;
+    }
+
+    public Content getKeyword3() {
+        return keyword3;
+    }
+
+    public void setKeyword3(Content keyword3) {
+        this.keyword3 = keyword3;
+    }
+
+    public Content getRemark() {
+        return remark;
+    }
+
+    public void setRemark(Content remark) {
+        this.remark = remark;
+    }
+}

+ 49 - 0
java110-bean/src/main/java/com/java110/entity/wechat/PropertyFeeTemplateMessage.java

@@ -0,0 +1,49 @@
+package com.java110.entity.wechat;
+
+/**
+ * @program: MicroCommunity
+ * @description: 微信公众号发送物业费信息模板
+ * @author: zcc
+ * @create: 2020-06-16 09:41
+ **/
+public class PropertyFeeTemplateMessage {
+    private String touser;//接收者openid
+    private String template_id;//模板ID
+    private String url;//模板跳转链接(海外帐号没有跳转能力)
+//    private String color;//模板内容字体颜色,不填默认为黑色
+    private Data data;//模板数据
+
+    public String getTouser() {
+        return touser;
+    }
+
+    public void setTouser(String touser) {
+        this.touser = touser;
+    }
+
+    public String getTemplate_id() {
+        return template_id;
+    }
+
+    public void setTemplate_id(String template_id) {
+        this.template_id = template_id;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+
+
+    public Data getData() {
+        return data;
+    }
+
+    public void setData(Data data) {
+        this.data = data;
+    }
+}

+ 7 - 0
java110-db/src/main/resources/mapper/fee/FeeServiceDaoImplMapper.xml

@@ -472,6 +472,13 @@
         <if test="ownerId != null and ownerId != ''">
             and t.owner_id = #{ownerId}
         </if>
+        <if test="ownerIds !=null">
+            and t.owner_id in
+            <foreach collection="ownerIds" open="(" close=")"
+                     separator=","  item="item">
+                #{item}
+            </foreach>
+        </if>
         <if test="ownerName != null and ownerName != ''">
             and t.owner_name = #{ownerName}
         </if>

+ 10 - 0
service-front/src/main/java/com/java110/front/properties/WechatAuthProperties.java

@@ -32,6 +32,8 @@ public class WechatAuthProperties {
     private String wechatAppId;//微信公众号ID
     private String wechatAppSecret;//微信公众号秘钥
 
+    private String sendMsgUrl;//微信公众号推送模板信息链接
+
     public String getSessionHost() {
         return sessionHost;
     }
@@ -111,4 +113,12 @@ public class WechatAuthProperties {
     public void setWechatAppSecret(String wechatAppSecret) {
         this.wechatAppSecret = wechatAppSecret;
     }
+
+    public String getSendMsgUrl() {
+        return sendMsgUrl;
+    }
+
+    public void setSendMsgUrl(String sendMsgUrl) {
+        this.sendMsgUrl = sendMsgUrl;
+    }
 }

+ 124 - 0
service-job/src/main/java/com/java110/job/task/wechat/PublicWeChatPushMessageTemplate.java

@@ -0,0 +1,124 @@
+package com.java110.job.task.wechat;
+
+import com.alibaba.fastjson.JSON;
+import com.java110.core.factory.WechatFactory;
+import com.java110.core.smo.fee.IFeeInnerServiceSMO;
+import com.java110.core.smo.store.ISmallWeChatInnerServiceSMO;
+import com.java110.core.smo.user.IOwnerAppUserInnerServiceSMO;
+import com.java110.dto.fee.BillOweFeeDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.task.TaskDto;
+import com.java110.entity.wechat.Content;
+import com.java110.entity.wechat.Data;
+import com.java110.entity.wechat.PropertyFeeTemplateMessage;
+import com.java110.job.quartz.TaskSystemQuartz;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @program: MicroCommunity
+ * @description: 微信公众号主动推送信息
+ * @author: zcc
+ * @create: 2020-06-15 13:35
+ **/
+@Component
+public class PublicWeChatPushMessageTemplate extends TaskSystemQuartz{
+
+    private static Logger logger = LoggerFactory.getLogger(PublicWeChatPushMessageTemplate.class);
+
+    @Autowired
+    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    //模板信息推送地址
+    private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
+
+    //模板id
+    private static String templateId = "ZF4j_ug2XW-UGwW1F-Gi4M1-51lpiu-PM89Oa6oZv6w";
+
+
+
+    @Override
+    protected void process(TaskDto taskDto) throws Exception {
+        logger.debug("开始执行微信模板信息推送" + taskDto.toString());
+
+        //查询公众号配置
+        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
+        smallWeChatDto.setWeChatType("1100");
+        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
+
+        if(smallWeChatDtos.size() <=0 || smallWeChatDto == null){
+            logger.info("未配置微信公众号信息,定时任务执行结束");
+            return;
+        }
+
+        SmallWeChatDto weChatDto = smallWeChatDtos.get(0);
+        String accessToken =  WechatFactory.getAccessToken(weChatDto.getAppId(),weChatDto.getAppSecret());
+
+        if(accessToken == null || accessToken == ""){
+            logger.info("推送微信模板,获取accessToken失败:{}",accessToken);
+            return;
+        }
+
+        //根据小区id查询业主与公众号绑定信息
+        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+        ownerAppUserDto.setCommunityId(weChatDto.getObjId());
+        ownerAppUserDto.setAppType("WECHAT");
+        List<OwnerAppUserDto>  ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+
+        if(ownerAppUserDtos.size() <=0 || ownerAppUserDtos == null){
+            logger.info("未查询到业主与微信公众号绑定关系");
+            return;
+        }
+
+        List<String> memberIds = new ArrayList<>(ownerAppUserDtos.size());
+        for(OwnerAppUserDto appUserDto :ownerAppUserDtos ){
+            memberIds.add(appUserDto.getMemberId());
+        }
+
+        //查询欠费信息
+        BillOweFeeDto billOweFeeDto = new BillOweFeeDto();
+        billOweFeeDto.setCommunityId(weChatDto.getObjId());
+        billOweFeeDto.setOwnerIds((String[]) memberIds.toArray());
+        billOweFeeDto.setState("1000");
+        List<BillOweFeeDto> billOweFeeDtos = feeInnerServiceSMOImpl.queryBillOweFees(billOweFeeDto);
+
+        String url = sendMsgUrl + accessToken;
+        for( BillOweFeeDto fee : billOweFeeDtos){
+            for(OwnerAppUserDto appUserDto :ownerAppUserDtos ){
+                if(fee.getOwnerId().equals(appUserDto.getMemberId())){
+                    Data data = new Data();
+                    PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
+                    templateMessage.setTemplate_id(templateId);
+                    templateMessage.setTouser(appUserDto.getOpenId());
+                    data.setFirst(new Content("物业费缴费提醒"));
+                    data.setKeyword1(new Content(fee.getPayerObjName()));
+                    data.setKeyword2(new Content(fee.getFeeEndTime()));
+                    data.setKeyword3(new Content(fee.getAmountOwed()));
+                    data.setKeyword3(new Content("请您及时缴费,如有疑问请联系相关物业人员"));
+                    templateMessage.setData(data);
+                    logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+                    ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+                    logger.info("微信模板返回内容:{}",responseEntity);
+                }
+            }
+
+        }
+    }
+}

+ 6 - 6
service-job/src/main/resources/dataSource.yml

@@ -1,9 +1,9 @@
 dataSources:
   ds0: !!com.alibaba.druid.pool.DruidDataSource
     driverClassName: com.mysql.jdbc.Driver
-    url: jdbc:mysql://xx:3306/hc_community?useUnicode=true&characterEncoding=utf-8
-    username: xx
-    password: xx
+    url: jdbc:mysql://dev.db.java110.com:3306/hc_community?useUnicode=true&characterEncoding=utf-8
+    username: hc_community
+    password: hc_community@12345678
     minIdle: 5
     validationQuery: SELECT 1 FROM DUAL
     initialSize: 5
@@ -22,9 +22,9 @@ dataSources:
 #    maintenanceIntervalMilliseconds: 30000
   ds1: !!com.alibaba.druid.pool.DruidDataSource
     driverClassName: com.mysql.jdbc.Driver
-    url: jdbc:mysql://xx:3306/TT?useUnicode=true&characterEncoding=utf-8
-    username: xx
-    password: xx
+    url: jdbc:mysql://dev.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8
+    username: TT
+    password: TT@12345678
     minIdle: 5
     validationQuery: SELECT 1 FROM DUAL
     initialSize: 5