Browse Source

新增报修通知,优化优惠折扣最大缴费时间问题

xiaogang 5 years ago
parent
commit
bfcf3f83c0

+ 8 - 0
java110-bean/src/main/java/com/java110/dto/repair/RepairDto.java

@@ -58,6 +58,7 @@ public class RepairDto extends PageDto implements Serializable {
     private String[] roomIds;
     private String repairTypeName;
     private String repairWay;
+    private String bId;
 
     private String staffId;
 
@@ -323,4 +324,11 @@ public class RepairDto extends PageDto implements Serializable {
     public void setPreRuId(String preRuId) {
         this.preRuId = preRuId;
     }
+    public String getbId() {
+        return bId;
+    }
+
+    public void setbId(String bId) {
+        this.bId = bId;
+    }
 }

+ 13 - 6
java110-bean/src/main/java/com/java110/dto/repair/RepairUserDto.java

@@ -22,12 +22,11 @@ public class RepairUserDto extends PageDto implements Serializable {
 
     public static final String REPAIR_EVENT_PAY_USER = "payUser";
 
-    public  static final String STATE_DOING = "10001";// 处理中
-    public  static final String STATE_CLOSE = "10002";// 结单
-    public  static final String STATE_BACK = "10003";// 退单
-    public  static final String STATE_TRANSFER = "10004";// 转单
-    public  static final String STATE_SUBMIT = "10005";// 提交
-
+    public static final String STATE_DOING = "10001";// 处理中
+    public static final String STATE_CLOSE = "10002";// 结单
+    public static final String STATE_BACK = "10003";// 退单
+    public static final String STATE_TRANSFER = "10004";// 转单
+    public static final String STATE_SUBMIT = "10005";// 提交
 
 
     private String context;
@@ -40,6 +39,7 @@ public class RepairUserDto extends PageDto implements Serializable {
     private String communityId;
     private String userId;
     private String userName;
+    private String bId;
 
     private String staffId;
     private String staffName;
@@ -224,4 +224,11 @@ public class RepairUserDto extends PageDto implements Serializable {
     public void setPreRuId(String preRuId) {
         this.preRuId = preRuId;
     }
+    public String getbId() {
+        return bId;
+    }
+
+    public void setbId(String bId) {
+        this.bId = bId;
+    }
 }

+ 32 - 20
java110-bean/src/main/java/com/java110/po/payFeeConfigDiscount/PayFeeConfigDiscountPo.java

@@ -13,39 +13,51 @@ public class PayFeeConfigDiscountPo implements Serializable {
     private String startTime;
     private String endTime;
     private String payMaxEndTime;
+
     public String getConfigDiscountId() {
-            return configDiscountId;
-        }
+        return configDiscountId;
+    }
+
     public void setConfigDiscountId(String configDiscountId) {
-            this.configDiscountId = configDiscountId;
-        }
+        this.configDiscountId = configDiscountId;
+    }
+
     public String getConfigId() {
-            return configId;
-        }
+        return configId;
+    }
+
     public void setConfigId(String configId) {
-            this.configId = configId;
-        }
+        this.configId = configId;
+    }
+
     public String getStatusCd() {
-            return statusCd;
-        }
+        return statusCd;
+    }
+
     public void setStatusCd(String statusCd) {
-            this.statusCd = statusCd;
-        }
+        this.statusCd = statusCd;
+    }
+
     public String getDiscountId() {
-            return discountId;
-        }
+        return discountId;
+    }
+
     public void setDiscountId(String discountId) {
-            this.discountId = discountId;
-        }
+        this.discountId = discountId;
+    }
+
     public String getCommunityId() {
-            return communityId;
-        }
+        return communityId;
+    }
+
     public void setCommunityId(String communityId) {
-            this.communityId = communityId;
-        }
+        this.communityId = communityId;
+    }
+
     public String getStartTime() {
         return startTime;
     }
+
     public void setStartTime(String startTime) {
         this.startTime = startTime;
     }

+ 6 - 27
java110-db/src/main/resources/mapper/community/RepairServiceDaoImplMapper.xml

@@ -14,13 +14,13 @@
         )
     </insert>
 
-
     <!-- 查询报修信息信息(Business) add by wuxw 2018-07-03 -->
     <select id="getBusinessRepairInfo" parameterType="Map" resultType="Map">
         select t.operate,t.repair_name,t.repair_name repairName,t.appointment_time,t.appointment_time
         appointmentTime,t.repair_type,t.repair_type repairType,t.context,t.repair_id,t.repair_id
         repairId,t.tel,t.state,t.community_id,t.community_id communityId,t.b_id,t.b_id bId,
-        t.repair_obj_type,t.repair_obj_id,t.repair_obj_name,t.repair_obj_type repairObjType,t.repair_obj_id repairObjId,t.repair_obj_name repairObjName
+        t.repair_obj_type,t.repair_obj_id,t.repair_obj_name,t.repair_obj_type repairObjType,t.repair_obj_id
+        repairObjId,t.repair_obj_name repairObjName
         from business_repair_pool t
         where 1 =1
         <if test="operate !=null and operate != ''">
@@ -53,11 +53,8 @@
         <if test="bId !=null and bId != ''">
             and t.b_id= #{bId}
         </if>
-
-
     </select>
 
-
     <!-- 保存报修信息信息至 instance表中 add by wuxw 2018-07-03 -->
     <insert id="saveRepairInfoInstance" parameterType="Map">
         insert into r_repair_pool(
@@ -95,11 +92,8 @@
         <if test="bId !=null and bId != ''">
             and t.b_id= #{bId}
         </if>
-
-
     </insert>
 
-
     <!-- 查询报修信息信息 add by wuxw 2018-07-03 -->
     <select id="getRepairInfo" parameterType="Map" resultType="Map">
         select t.repair_name,t.repair_name repairName,t.appointment_time,t.appointment_time
@@ -136,7 +130,7 @@
             and rs.return_visit_flag in ('001','002')
         </if>
         <if test="repairName !=null and repairName != ''">
-            and t.repair_name= #{repairName}
+            and t.repair_name like '%${repairName}%'
         </if>
         <if test="appointmentTime !=null ">
             and t.appointment_time= #{appointmentTime}
@@ -177,15 +171,12 @@
         <if test="repairObjId !=null and repairObjId != ''">
             and t.repair_obj_id= #{repairObjId}
         </if>
-
         order by t.create_time desc
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
         </if>
-
     </select>
 
-
     <!-- 修改报修信息信息 add by wuxw 2018-07-03 -->
     <update id="updateRepairInfoInstance" parameterType="Map">
         update r_repair_pool t set t.status_cd = #{statusCd}
@@ -229,7 +220,6 @@
         <if test="bId !=null and bId != ''">
             and t.b_id= #{bId}
         </if>
-
     </update>
 
     <!-- 查询报修信息数量 add by wuxw 2018-07-03 -->
@@ -250,7 +240,7 @@
             AND td.`status_cd` = rru.state
         </if>
         <if test="repairName !=null and repairName != ''">
-            and t.repair_name= #{repairName}
+            and t.repair_name like '%${repairName}%'
         </if>
         <if test="appointmentTime !=null ">
             and t.appointment_time= #{appointmentTime}
@@ -273,7 +263,6 @@
         <if test="state !=null and state != ''">
             and t.state= #{state}
         </if>
-
         <if test="statess !=null">
             and t.state in
             <foreach collection="statess" item="item" open="(" close=")" separator=",">
@@ -295,8 +284,6 @@
         <if test="repairObjId !=null and repairObjId != ''">
             and t.repair_obj_id= #{repairObjId}
         </if>
-
-
     </select>
 
     <!-- 查询报修信息信息 add by wuxw 2018-07-03 -->
@@ -358,7 +345,6 @@
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
         </if>
-
     </select>
 
     <!-- 查询报修信息数量 add by wuxw 2018-07-03 -->
@@ -408,12 +394,8 @@
         <if test="repairObjId !=null and repairObjId != ''">
             and t.repair_obj_id= #{repairObjId}
         </if>
-
-
     </select>
 
-
-
     <!-- 查询报修信息信息 add by wuxw 2018-07-03 -->
     <select id="getStaffFinishRepairInfo" parameterType="Map" resultType="Map">
         select distinct t.repair_name,t.repair_name repairName,t.appointment_time,t.appointment_time
@@ -422,7 +404,8 @@
         bId,
         d.name stateName,
         rs.repair_type_name repairTypeName,rs.repair_way repairWay,
-        t.repair_obj_type,t.repair_obj_id,t.repair_obj_name,t.repair_obj_type repairObjType,t.repair_obj_id repairObjId,t.repair_obj_name repairObjName
+        t.repair_obj_type,t.repair_obj_id,t.repair_obj_name,t.repair_obj_type repairObjType,t.repair_obj_id
+        repairObjId,t.repair_obj_name repairObjName
         from r_repair_pool t
         left join t_dict d on t.state = d.status_cd and d.table_name = 'r_repair_pool' and d.table_columns = 'state'
         left join r_repair_setting rs on rs.repair_type = t.repair_type and rs.status_cd = '0'
@@ -476,7 +459,6 @@
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
         </if>
-
     </select>
 
     <!-- 查询报修信息数量 add by wuxw 2018-07-03 -->
@@ -533,8 +515,5 @@
             and t.repair_obj_id= #{repairObjId}
         </if>
         group by ru.staff_id
-
-
     </select>
-
 </mapper>

+ 16 - 20
java110-db/src/main/resources/mapper/community/RepairSettingServiceDaoImplMapper.xml

@@ -13,12 +13,12 @@
         )
     </insert>
 
-
     <!-- 查询报修设置信息(Business) add by wuxw 2018-07-03 -->
     <select id="getBusinessRepairSettingInfo" parameterType="Map" resultType="Map">
         select t.operate,t.repair_type_name,t.repair_type_name repairTypeName,t.repair_type,t.repair_type
         repairType,t.remark,t.b_id,t.b_id bId,t.community_id,t.community_id communityId,t.repair_way,t.repair_way
-        repairWay,t.setting_id,t.setting_id settingId,t.public_area,t.public_area publicArea,t.pay_fee_flag,t.pay_fee_flag payFeeFlag
+        repairWay,t.setting_id,t.setting_id settingId,t.public_area,t.public_area
+        publicArea,t.pay_fee_flag,t.pay_fee_flag payFeeFlag
         ,t.price_scope,t.price_scope priceScope,t.return_visit_flag,t.return_visit_flag returnVisitFlag
         from business_repair_setting t
         where 1 =1
@@ -46,15 +46,14 @@
         <if test="settingId !=null and settingId != ''">
             and t.setting_id= #{settingId}
         </if>
-
     </select>
 
-
     <!-- 保存报修设置信息至 instance表中 add by wuxw 2018-07-03 -->
     <insert id="saveRepairSettingInfoInstance" parameterType="Map">
         insert into r_repair_setting(
         repair_type_name,repair_type,remark,status_cd,b_id,community_id,repair_way,setting_id,public_area,pay_fee_flag,price_scope,return_visit_flag
-        ) select t.repair_type_name,t.repair_type,t.remark,'0',t.b_id,t.community_id,t.repair_way,t.setting_id ,t.public_area,t.pay_fee_flag,t.price_scope,t.return_visit_flag
+        ) select t.repair_type_name,t.repair_type,t.remark,'0',t.b_id,t.community_id,t.repair_way,t.setting_id
+        ,t.public_area,t.pay_fee_flag,t.price_scope,t.return_visit_flag
         from
         business_repair_setting t where 1=1
         and t.operate= 'ADD'
@@ -79,23 +78,25 @@
         <if test="settingId !=null and settingId != ''">
             and t.setting_id= #{settingId}
         </if>
-
     </insert>
 
-
     <!-- 查询报修设置信息 add by wuxw 2018-07-03 -->
     <select id="getRepairSettingInfo" parameterType="Map" resultType="Map">
         select t.repair_type_name,t.repair_type_name repairTypeName,t.repair_type,t.repair_type
         repairType,t.remark,t.status_cd,t.status_cd statusCd,t.b_id,t.b_id bId,t.community_id,t.community_id
-        communityId,t.repair_way,t.repair_way repairWay,t.setting_id,t.setting_id settingId,t.create_time createTime,d.name repairWayName,
+        communityId,t.repair_way,t.repair_way repairWay,t.setting_id,t.setting_id settingId,t.create_time
+        createTime,d.name repairWayName,
         t.public_area,t.public_area publicArea,t.pay_fee_flag,t.pay_fee_flag payFeeFlag
-        ,t.price_scope,t.price_scope priceScope,t.return_visit_flag,t.return_visit_flag returnVisitFlag,d1.name returnVisitFlagName
+        ,t.price_scope,t.price_scope priceScope,t.return_visit_flag,t.return_visit_flag returnVisitFlag,d1.name
+        returnVisitFlagName
         from r_repair_setting t
-        left join t_dict d on t.repair_way = d.status_cd and d.table_name = 'r_repair_setting' and d.table_columns = 'repair_way'
-        left join t_dict d1 on t.return_visit_flag = d1.status_cd and d1.table_name = 'r_repair_setting' and d1.table_columns = 'return_visit_flag'
+        left join t_dict d on t.repair_way = d.status_cd and d.table_name = 'r_repair_setting' and d.table_columns =
+        'repair_way'
+        left join t_dict d1 on t.return_visit_flag = d1.status_cd and d1.table_name = 'r_repair_setting' and
+        d1.table_columns = 'return_visit_flag'
         where 1 =1
         <if test="repairTypeName !=null and repairTypeName != ''">
-            and t.repair_type_name= #{repairTypeName}
+            and t.repair_type_name like '%${repairTypeName}%'
         </if>
         <if test="repairType !=null and repairType != ''">
             and t.repair_type= #{repairType}
@@ -131,10 +132,8 @@
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
         </if>
-
     </select>
 
-
     <!-- 修改报修设置信息 add by wuxw 2018-07-03 -->
     <update id="updateRepairSettingInfoInstance" parameterType="Map">
         update r_repair_setting t set t.status_cd = #{statusCd}
@@ -175,17 +174,17 @@
         <if test="settingId !=null and settingId != ''">
             and t.setting_id= #{settingId}
         </if>
-
     </update>
 
     <!-- 查询报修设置数量 add by wuxw 2018-07-03 -->
     <select id="queryRepairSettingsCount" parameterType="Map" resultType="Map">
         select count(1) count
         from r_repair_setting t
-        left join t_dict d on t.repair_way = d.status_cd and d.table_name = 'r_repair_setting' and d.table_columns = 'repair_way'
+        left join t_dict d on t.repair_way = d.status_cd and d.table_name = 'r_repair_setting' and d.table_columns =
+        'repair_way'
         where 1 =1
         <if test="repairTypeName !=null and repairTypeName != ''">
-            and t.repair_type_name= #{repairTypeName}
+            and t.repair_type_name like '%${repairTypeName}%'
         </if>
         <if test="repairType !=null and repairType != ''">
             and t.repair_type= #{repairType}
@@ -218,8 +217,5 @@
         <if test="returnVisitFlag !=null and returnVisitFlag != ''">
             and t.return_visit_flag= #{returnVisitFlag}
         </if>
-
-
     </select>
-
 </mapper>

+ 1 - 3
java110-db/src/main/resources/mapper/community/RepairUserServiceDaoImplMapper.xml

@@ -93,7 +93,7 @@
         t.b_id bId,t.staff_id,t.staff_id staffId,t.staff_name,t.staff_name staffName,
         t.pre_staff_id,t.pre_staff_id preStaffId,t.pre_staff_name,t.pre_staff_name preStaffName,
         t.start_time,t.start_time startTime,t.end_time,t.end_time endTime,d.name stateName,
-        t.repair_event,t.repair_event repairEvent, t.pre_ru_id,t.pre_ru_id preRuId
+        t.repair_event,t.repair_event repairEvent, t.pre_ru_id,t.pre_ru_id preRuId,t.create_time createTime
         from r_repair_user t
         left join t_dict d on t.state = d.status_cd and d.table_name = 'r_repair_user' and d.table_columns = 'state'
         where 1 =1
@@ -118,7 +118,6 @@
         <if test="state !=null and state != ''">
             and t.state= #{state}
         </if>
-
         <if test="states !=null ">
             and t.state in
             <foreach collection="states" item="item" open="(" close=")" separator=",">
@@ -147,7 +146,6 @@
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
         </if>
-
     </select>
 
 

+ 2 - 2
java110-db/src/main/resources/mapper/user/OwnerRoomRelServiceDaoImplMapper.xml

@@ -108,8 +108,8 @@
         <if test="relId !=null and relId != ''">
             and t.rel_id= #{relId}
         </if>
-        <if test="relId !=null and relId != ''">
-            and t.rel_id= #{relId}
+        <if test="roomId !=null and roomId != ''">
+            and t.room_id= #{roomId}
         </if>
         <if test="statusCd !=null and statusCd != ''">
             and t.status_cd= #{statusCd}

+ 8 - 1
service-api/src/main/java/com/java110/api/bmo/fee/impl/FeeBMOImpl.java

@@ -423,7 +423,14 @@ public class FeeBMOImpl extends ApiBaseBMO implements IFeeBMO {
                 BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
                 BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDtos.get(0).getBuiltUpArea()));
                 BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
-                feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                //获取支付方式
+                String primeRate = paramInJson.getString("primeRate");
+                //判断是否是线上支付
+                if (primeRate.equals("5") || primeRate.equals("6")) {
+                    feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount);
+                } else {
+                    feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                }
             } else if ("2002".equals(computingFormula)) { // 固定费用
                 //feePrice = Double.parseDouble(feeDto.getAdditionalAmount());
                 BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));

+ 1 - 1
service-api/src/main/java/com/java110/api/listener/fee/PayFeePreListener.java

@@ -150,7 +150,7 @@ public class PayFeePreListener extends AbstractServiceApiDataFlowListener {
         for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
             discountPrice = discountPrice.add(new BigDecimal(computeDiscountDto.getDiscountPrice()));
         }
-        paramObj.put("discountPrice", discountPrice.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+        paramObj.put("discountPrice", discountPrice);
         paramObj.put("computeDiscountDtos", computeDiscountDtos);
     }
 

+ 1 - 1
service-api/src/main/java/com/java110/api/listener/ownerRepair/GrabbingRepairListener.java

@@ -75,7 +75,7 @@ public class GrabbingRepairListener extends AbstractServiceApiPlusListener {
         repairTypeUserDto.setStaffId(reqJson.getString("userId"));
         int count = repairTypeUserInnerServiceSMOImpl.queryRepairTypeUsersCount(repairTypeUserDto);
         if (count < 1) {
-            throw new IllegalArgumentException("您没有权限该类型报修单");
+            throw new IllegalArgumentException("您没有权限该类型报修单");
         }
 
     }

+ 5 - 1
service-fee/src/main/java/com/java110/fee/api/PayFeeConfigDiscountApi.java

@@ -9,6 +9,7 @@ import com.java110.fee.bmo.payFeeConfigDiscount.IUpdatePayFeeConfigDiscountBMO;
 import com.java110.po.payFeeConfigDiscount.PayFeeConfigDiscountPo;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
@@ -45,8 +46,11 @@ public class PayFeeConfigDiscountApi {
         Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
         Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
 
-
         PayFeeConfigDiscountPo payFeeConfigDiscountPo = BeanConvertUtil.covertBean(reqJson, PayFeeConfigDiscountPo.class);
+        String paymaxEndTime = reqJson.getString("payMaxEndTime");
+        if(StringUtil.isEmpty(paymaxEndTime)){
+            payFeeConfigDiscountPo.setPayMaxEndTime(null);
+        }
         return savePayFeeConfigDiscountBMOImpl.save(payFeeConfigDiscountPo);
     }
 

+ 16 - 3
service-fee/src/main/java/com/java110/fee/smo/impl/FeeDiscountInnerServiceSMOImpl.java

@@ -1,6 +1,5 @@
 package com.java110.fee.smo.impl;
 
-
 import com.java110.core.base.smo.BaseServiceSMO;
 import com.java110.dto.PageDto;
 import com.java110.dto.applyRoomDiscount.ApplyRoomDiscountDto;
@@ -144,6 +143,7 @@ public class FeeDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IF
      */
     public List<ComputeDiscountDto> computeDiscount(@RequestBody FeeDetailDto feeDetailDto) {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
         List<ComputeDiscountDto> computeDiscountDtos = new ArrayList<>();
         FeeDto feeDto = new FeeDto();
         feeDto.setFeeId(feeDetailDto.getFeeId());
@@ -156,6 +156,7 @@ public class FeeDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IF
         payFeeConfigDiscountDto.setRow(feeDetailDto.getRow());
         payFeeConfigDiscountDto.setPage(feeDetailDto.getPage());
         payFeeConfigDiscountDto.setCommunityId(feeDetailDto.getCommunityId());
+        payFeeConfigDiscountDto.setStatusCd("0");
         Date currentTime = new Date();
         payFeeConfigDiscountDto.setCurrentTime(currentTime);
         //根据费用查询折扣
@@ -164,8 +165,21 @@ public class FeeDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IF
         if (payFeeConfigDiscountDtos == null || payFeeConfigDiscountDtos.size() < 1) {
             return computeDiscountDtos;
         }
+        c.setTime(feeDetailDto.getStartTime());
+        double mon = Double.parseDouble(feeDetailDto.getCycles());
+        c.add(Calendar.MONTH, (int) mon);
+        //获取缴费结束时间
+        Date finishTime = c.getTime();
         for (PayFeeConfigDiscountDto tmpPayFeeConfigDiscountDto : payFeeConfigDiscountDtos) {
-            doCompute(tmpPayFeeConfigDiscountDto, Double.parseDouble(feeDetailDto.getCycles()), computeDiscountDtos, feeDetailDto.getFeeId());
+            //获取缴费最大截止时间
+            Date payMaxEndTime = tmpPayFeeConfigDiscountDto.getPayMaxEndTime();
+            if (payMaxEndTime == null) {
+                doCompute(tmpPayFeeConfigDiscountDto, Double.parseDouble(feeDetailDto.getCycles()), computeDiscountDtos, feeDetailDto.getFeeId());
+            } else if (payMaxEndTime.getTime() >= finishTime.getTime()) {
+                doCompute(tmpPayFeeConfigDiscountDto, Double.parseDouble(feeDetailDto.getCycles()), computeDiscountDtos, feeDetailDto.getFeeId());
+            } else {
+                continue;
+            }
         }
         if (!StringUtil.isEmpty(feeDetailDto.getPayerObjType()) && feeDetailDto.getPayerObjType().equals("3333")) {
             //根据房屋ID,去折扣申请表查询是否有折扣
@@ -179,7 +193,6 @@ public class FeeDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IF
             //开始时间
             applyRoomDiscountDto.setStartTime(simpleDateFormat.format(feeDetailDto.getStartTime()));
             //结束时间
-            Calendar c = Calendar.getInstance();
             c.setTime(feeDetailDto.getStartTime());
             double month = Double.parseDouble(feeDetailDto.getCycles());
             c.add(Calendar.MONTH, (int) month);

+ 165 - 0
service-job/src/main/java/com/java110/job/adapt/Repair/MachineAddOwnerRepairAdapt.java

@@ -0,0 +1,165 @@
+package com.java110.job.adapt.Repair;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.factory.WechatFactory;
+import com.java110.dto.basePrivilege.BasePrivilegeDto;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.repair.RepairDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
+import com.java110.dto.staffAppAuth.StaffAppAuthDto;
+import com.java110.dto.user.UserDto;
+import com.java110.entity.order.Business;
+import com.java110.entity.wechat.Content;
+import com.java110.entity.wechat.Data;
+import com.java110.entity.wechat.PropertyFeeTemplateMessage;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.community.IRepairInnerServiceSMO;
+import com.java110.intf.order.IPrivilegeInnerServiceSMO;
+import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
+import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
+import com.java110.intf.user.IStaffAppAuthInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.StringUtil;
+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.List;
+
+/**
+ * 登记报修通知适配器
+ *
+ * @author fqz
+ * @date 2020-12-11  18:54
+ */
+@Component(value = "machineAddOwnerRepairAdapt")
+public class MachineAddOwnerRepairAdapt extends DatabusAdaptImpl {
+
+    private static Logger logger = LoggerFactory.getLogger(MachineAddOwnerRepairAdapt.class);
+
+    @Autowired
+    private IRepairInnerServiceSMO repairInnerServiceSMO;
+
+    @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) {
+        RepairDto repairDto = new RepairDto();
+        repairDto.setbId(business.getbId());
+        repairDto.setStatusCd("0");
+        List<RepairDto> repairDtos = repairInnerServiceSMO.queryRepairs(repairDto);
+        //获取报修类型
+        String repairTypeName = repairDtos.get(0).getRepairTypeName();
+        //获取小区id
+        String communityId = repairDtos.get(0).getCommunityId();
+        //获取位置信息
+        String repairObjName = repairDtos.get(0).getRepairObjName();
+        //获取报修内容
+        String context = repairDtos.get(0).getContext();
+        //获取业主姓名
+        String repairName = repairDtos.get(0).getRepairName();
+        //查询小区信息
+        CommunityDto communityDto = new CommunityDto();
+        communityDto.setCommunityId(communityId);
+        List<CommunityDto> communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto);
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("repairTypeName", repairTypeName);
+        paramIn.put("communityId", communityId);
+        paramIn.put("repairObjName", repairObjName);
+        paramIn.put("context", context);
+        paramIn.put("repairName", repairName);
+        sendMessage(paramIn, communityDtos.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_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;
+        }
+        // 根据特定权限查询 有该权限的 员工
+        BasePrivilegeDto basePrivilegeDto = new BasePrivilegeDto();
+        basePrivilegeDto.setResource("/wechatRepairRegistration");
+        List<UserDto> userDtos = privilegeInnerServiceSMO.queryPrivilegeUsers(basePrivilegeDto);
+        String url = sendMsgUrl + accessToken;
+        for (UserDto userDto : userDtos) {
+            //根据 userId 查询到openId
+            StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
+            staffAppAuthDto.setStaffId(userDto.getUserId());
+            staffAppAuthDto.setAppType("WECHAT");
+            List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
+            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("业主" + paramIn.getString("repairName") + "提交了新的报修工单,报修信息如下:"));
+            data.setKeyword1(new Content(paramIn.getString("repairTypeName")));
+            if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
+                data.setKeyword2(new Content(paramIn.getString("repairObjName")));
+            } else {
+                data.setKeyword2(new Content(communityDto.getName() + paramIn.getString("repairObjName")));
+            }
+            data.setKeyword3(new Content(paramIn.getString("context")));
+            data.setRemark(new Content("请您及时确认信息,并安排相关人员进行处理,感谢您的使用!"));
+            templateMessage.setData(data);
+            String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL");
+            templateMessage.setUrl(wechatUrl);
+            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+            logger.info("微信模板返回内容:{}", responseEntity);
+        }
+    }
+}

+ 448 - 0
service-job/src/main/java/com/java110/job/adapt/Repair/MachineDistributeLeaflets.java

@@ -0,0 +1,448 @@
+package com.java110.job.adapt.Repair;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.factory.WechatFactory;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.repair.RepairDto;
+import com.java110.dto.repair.RepairUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
+import com.java110.dto.staffAppAuth.StaffAppAuthDto;
+import com.java110.dto.user.UserDto;
+import com.java110.entity.order.Business;
+import com.java110.entity.wechat.Content;
+import com.java110.entity.wechat.Data;
+import com.java110.entity.wechat.PropertyFeeTemplateMessage;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.community.IRepairInnerServiceSMO;
+import com.java110.intf.community.IRepairUserInnerServiceSMO;
+import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
+import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
+import com.java110.intf.user.*;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.StringUtil;
+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.text.SimpleDateFormat;
+import java.util.List;
+
+/**
+ * 派单(抢单、转单)通知适配器
+ *
+ * @author fqz
+ * @date 2021-01-13 13:55
+ */
+@Component(value = "machineDistributeLeaflets")
+public class MachineDistributeLeaflets extends DatabusAdaptImpl {
+
+    private static Logger logger = LoggerFactory.getLogger(MachineDistributeLeaflets.class);
+
+    @Autowired
+    private IRepairUserInnerServiceSMO repairUserInnerServiceSMO;
+
+    @Autowired
+    private IRepairInnerServiceSMO repairInnerServiceSMO;
+
+    @Autowired
+    private ICommunityInnerServiceSMO communityInnerServiceSMO;
+
+    @Autowired
+    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWechatAttrInnerServiceSMO smallWechatAttrInnerServiceSMOImpl;
+
+    @Autowired
+    private IStaffAppAuthInnerServiceSMO staffAppAuthInnerServiceSMO;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMO;
+
+    @Autowired
+    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMO;
+
+    //模板信息推送地址
+    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) {
+        RepairUserDto repairUserDto = new RepairUserDto();
+        repairUserDto.setbId(business.getbId());
+        repairUserDto.setStatusCd("0");
+        List<RepairUserDto> repairUserDtos = repairUserInnerServiceSMO.queryRepairUsers(repairUserDto);
+        //获取员工处理状态(10001 处理中;10002 结单;10003 退单;10004 转单;10005 提交)
+        String state = repairUserDtos.get(0).getState();
+        if (!state.equals("10005")) {
+            //获取报修id
+            String repairId = repairUserDtos.get(0).getRepairId();
+            RepairDto repairDto = new RepairDto();
+            repairDto.setRepairId(repairId);
+            repairDto.setStatusCd("0");
+            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);
+            //派单方式(100表示抢单;200表示指派;300表示轮训)
+            String repairWay = repairDtos.get(0).getRepairWay();
+            if (repairState.equals("1100") && repairWay.equals("200")) {
+                //获取维修员工的id
+                String staffId = repairUserDtos.get(1).getStaffId();
+                //获取用户id
+                String preStaffId = repairUserDtos.get(0).getPreStaffId();
+                JSONObject paramIn = new JSONObject();
+                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("staffId", staffId);
+                paramIn.put("repairObjId", repairObjId);
+                paramIn.put("preStaffId", preStaffId);
+                //给维修师傅推送信息
+                sendMsg(paramIn, communityDtos.get(0));
+                //派单成功给业主推送信息
+                publishMsg(paramIn, communityDtos.get(0));
+            } else if (repairState.equals("1100") && repairWay.equals("100")) {
+                String staffId = "";
+                if (repairUserDtos.size() > 1) {
+                    staffId = repairUserDtos.get(1).getStaffId();
+                } else {
+                    //获取维修员工的id
+                    staffId = repairUserDtos.get(0).getStaffId();
+                }
+                //获取用户id
+                String preStaffId = repairUserDtos.get(0).getPreStaffId();
+                JSONObject paramIn = new JSONObject();
+                paramIn.put("staffId", staffId);
+                paramIn.put("context", context);
+                paramIn.put("time", time);
+                paramIn.put("repairObjId", repairObjId);
+                paramIn.put("preStaffId", preStaffId);
+                paramIn.put("repairName", repairName);
+                paramIn.put("tel", tel);
+                paramIn.put("repairObjName", repairObjName);
+                //抢单成功给业主推送信息
+                publishMsg(paramIn, communityDtos.get(0));
+                if (repairUserDtos.size() > 1) {
+                    //给维修师傅推送信息
+                    sendMsg(paramIn, communityDtos.get(0));
+                }else {
+                    //抢单成功给维修师傅推送信息
+                    publishMessage(paramIn, communityDtos.get(0));
+                }
+            } else if (repairState.equals("1300")) {   //转单
+                //获取维修员工id
+                String staffId = repairUserDtos.get(0).getStaffId();
+                //获取上级用户姓名
+                String preStaffName = repairUserDtos.get(0).getPreStaffName();
+                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", staffId);
+                paramIn.put("preStaffName", preStaffName);
+                //给维修师傅推送信息
+                sendMessage(paramIn, communityDtos.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("OWNER_WECHAT_URL");
+            templateMessage.setUrl(wechatUrl);
+            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+            logger.info("微信模板返回内容:{}", responseEntity);
+        }
+    }
+
+    /**
+     * 派单给维修师傅推送信息
+     *
+     * @param paramIn
+     * @param communityDto
+     */
+    private void sendMsg(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");
+        }
+        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" + "报修位置:" + address));
+            data.setRemark(new Content("请及时登录公众号接单确认!"));
+            templateMessage.setData(data);
+            String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL");
+            templateMessage.setUrl(wechatUrl);
+            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+            logger.info("微信模板返回内容:{}", responseEntity);
+        }
+    }
+
+    /**
+     * 派单(抢单)成功后给业主推送信息
+     *
+     * @param paramIn
+     * @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("未配置微信公众号信息,定时任务执行结束");
+            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("未配置微信公众号消息模板");
+            return;
+        }
+        String templateId = smallWechatAttrDtos.get(0).getValue();
+        String accessToken = WechatFactory.getAccessToken(weChatDto.getAppId(), weChatDto.getAppSecret());
+        if (StringUtil.isEmpty(accessToken)) {
+            logger.info("推送微信模板,获取accessToken失败:{}", accessToken);
+            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 = MappingCache.getValue("OWNER_WECHAT_URL");
+                templateMessage.setUrl(wechatUrl);
+                logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+                ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+                logger.info("微信模板返回内容:{}", responseEntity);
+            }
+        }
+    }
+
+    /**
+     * 抢单成功后给维修师傅推送信息
+     *
+     * @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);
+        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("OWNER_WECHAT_URL");
+        templateMessage.setUrl(wechatUrl);
+        logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+        logger.info("微信模板返回内容:{}", responseEntity);
+    }
+}

+ 276 - 0
service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java

@@ -0,0 +1,276 @@
+package com.java110.job.adapt.Repair;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.factory.WechatFactory;
+import com.java110.dto.basePrivilege.BasePrivilegeDto;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.repair.RepairDto;
+import com.java110.dto.repair.RepairUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
+import com.java110.dto.staffAppAuth.StaffAppAuthDto;
+import com.java110.dto.user.UserDto;
+import com.java110.entity.order.Business;
+import com.java110.entity.wechat.Content;
+import com.java110.entity.wechat.Data;
+import com.java110.entity.wechat.PropertyFeeTemplateMessage;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.community.IRepairInnerServiceSMO;
+import com.java110.intf.community.IRepairUserInnerServiceSMO;
+import com.java110.intf.order.IPrivilegeInnerServiceSMO;
+import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
+import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
+import com.java110.intf.user.*;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.StringUtil;
+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.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 退单(结单)通知适配器
+ *
+ * @author fqz
+ * @date 2021-01-18 10:22
+ */
+@Component(value = "machineReturnRepairAdapt")
+public class MachineReturnRepairAdapt extends DatabusAdaptImpl {
+
+    private static Logger logger = LoggerFactory.getLogger(MachineReturnRepairAdapt.class);
+
+    @Autowired
+    private IRepairUserInnerServiceSMO repairUserInnerServiceSMO;
+
+    @Autowired
+    private IRepairInnerServiceSMO repairInnerServiceSMO;
+
+    @Autowired
+    private ICommunityInnerServiceSMO communityInnerServiceSMO;
+
+    @Autowired
+    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWechatAttrInnerServiceSMO smallWechatAttrInnerServiceSMOImpl;
+
+    @Autowired
+    private IStaffAppAuthInnerServiceSMO staffAppAuthInnerServiceSMO;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    @Autowired
+    private IPrivilegeInnerServiceSMO privilegeInnerServiceSMO;
+
+    @Autowired
+    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMO;
+
+    //模板信息推送地址
+    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) {
+        RepairUserDto repairUserDto = new RepairUserDto();
+        repairUserDto.setbId(business.getbId());
+        repairUserDto.setStatusCd("0");
+        List<RepairUserDto> repairUserDtos = repairUserInnerServiceSMO.queryRepairUsers(repairUserDto);
+        //获取状态
+        String state = repairUserDtos.get(0).getState();
+        //获取报修id
+        String repairId = repairUserDtos.get(0).getRepairId();
+        RepairDto repairDto = new RepairDto();
+        repairDto.setRepairId(repairId);
+        repairDto.setStatusCd("0");
+        List<RepairDto> repairDtos = repairInnerServiceSMO.queryRepairs(repairDto);
+        //获取报修人姓名
+        String repairName = repairDtos.get(0).getRepairName();
+        //获取报修内容
+        String context = repairDtos.get(0).getContext();
+        //获取报修类型名
+        String repairTypeName = repairDtos.get(0).getRepairTypeName();
+        //报修地址
+        String repairObjName = repairDtos.get(0).getRepairObjName();
+        //获取小区id
+        String communityId = repairUserDtos.get(0).getCommunityId();
+        //查询小区信息
+        CommunityDto communityDto = new CommunityDto();
+        communityDto.setCommunityId(communityId);
+        List<CommunityDto> communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto);
+        JSONObject paramIn = new JSONObject();
+        if (state.equals("10003")) {   //退单状态
+            //退单人
+            String staffName = repairUserDtos.get(0).getStaffName();
+            //退单备注
+            String returnContext = repairUserDtos.get(0).getContext();
+            paramIn.put("repairTypeName", repairTypeName);
+            paramIn.put("repairObjName", repairObjName);
+            paramIn.put("staffName", staffName);
+            paramIn.put("context", context);
+            paramIn.put("returnContext", returnContext);
+            sendReturnMessage(paramIn, communityDtos.get(0));
+        } else if (state.equals("10002")) {     //结单
+            //获取用户id
+            String preStaffId = repairUserDtos.get(0).getPreStaffId();
+            //获取维修师傅姓名
+            String staffName = repairUserDtos.get(0).getStaffName();
+            //获取报修对象id
+            String repairObjId = repairDtos.get(0).getRepairObjId();
+            //获取结单日期
+            Date endTime = repairUserDtos.get(0).getEndTime();
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String time = format.format(endTime);
+            paramIn.put("repairName", repairName);
+            paramIn.put("repairObjName", repairObjName);
+            paramIn.put("context", context);
+            paramIn.put("staffName", staffName);
+            paramIn.put("time", time);
+            paramIn.put("repairObjId", repairObjId);
+            paramIn.put("preStaffId", preStaffId);
+            publishReturnMsg(paramIn, communityDtos.get(0));
+        }
+    }
+
+    /**
+     * 退单给管理员推送信息
+     *
+     * @param paramIn
+     * @param communityDto
+     */
+    private void sendReturnMessage(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;
+        }
+        // 根据特定权限查询 有该权限的 员工
+        BasePrivilegeDto basePrivilegeDto = new BasePrivilegeDto();
+        basePrivilegeDto.setResource("/wechatRepairRegistration");
+        List<UserDto> userDtos = privilegeInnerServiceSMO.queryPrivilegeUsers(basePrivilegeDto);
+        String url = sendMsgUrl + accessToken;
+        for (UserDto userDto : userDtos) {
+            //根据 userId 查询到openId
+            StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
+            staffAppAuthDto.setStaffId(userDto.getUserId());
+            staffAppAuthDto.setAppType("WECHAT");
+            List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
+            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(paramIn.getString("staffName") + "进行维修工单退单操作,请及时处理,信息如下:"));
+            data.setKeyword1(new Content(paramIn.getString("repairTypeName")));
+            if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
+                data.setKeyword2(new Content(paramIn.getString("repairObjName")));
+            } else {
+                data.setKeyword2(new Content(communityDto.getName() + paramIn.getString("repairObjName")));
+            }
+            data.setKeyword3(new Content(paramIn.getString("context")));
+            data.setRemark(new Content(paramIn.getString("returnContext")));
+            templateMessage.setData(data);
+            String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL");
+            templateMessage.setUrl(wechatUrl);
+            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+            logger.info("微信模板返回内容:{}", responseEntity);
+        }
+    }
+
+    /**
+     * 结单给管理员推送信息
+     *
+     * @param paramIn
+     * @param communityDto
+     */
+    private void publishReturnMsg(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_END_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;
+        }
+        //获取用户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);
+            //获取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("尊敬的" + paramIn.getString("repairName") + "先生/女士,您的报修问题,已经为您处理完毕。"));
+            if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
+                data.setKeyword1(new Content(paramIn.getString("repairObjName")));
+            } else {
+                data.setKeyword1(new Content(communityDto.getName() + paramIn.getString("repairObjName")));
+            }
+            data.setKeyword2(new Content(paramIn.getString("context")));
+            data.setKeyword3(new Content(paramIn.getString("staffName")));
+            data.setKeyword4(new Content(paramIn.getString("time")));
+            data.setRemark(new Content("请点击查看详情,对我们的工作进行评价,以便提供更优质的服务,感谢您的配合和使用,祝您生活愉快,阖家欢乐!"));
+            templateMessage.setData(data);
+            String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL");
+            templateMessage.setUrl(wechatUrl);
+            logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+            ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+            logger.info("微信模板返回内容:{}", responseEntity);
+        }
+    }
+}