Ver código fonte

加入巡检 模板消息提醒功能

wuxw 3 anos atrás
pai
commit
9fa4f824a1

+ 14 - 0
java110-bean/src/main/java/com/java110/dto/inspectionPlan/InspectionTaskDetailDto.java

@@ -15,6 +15,10 @@ import java.util.Date;
  **/
 public class InspectionTaskDetailDto extends PageDto implements Serializable {
 
+    public static final String SEND_FLAG_Y = "Y";//已经推送
+    public static final String SEND_FLAG_N = "N";//未推送数据
+
+
     private String inspectionId;
     private String inspectionName;
     private String state;
@@ -69,6 +73,8 @@ public class InspectionTaskDetailDto extends PageDto implements Serializable {
     private String statusCd = "0";
     private String itemId;
 
+    private String sendFlag;
+
     public String getInspectionId() {
         return inspectionId;
     }
@@ -380,4 +386,12 @@ public class InspectionTaskDetailDto extends PageDto implements Serializable {
     public void setQrCodeTime(String qrCodeTime) {
         this.qrCodeTime = qrCodeTime;
     }
+
+    public String getSendFlag() {
+        return sendFlag;
+    }
+
+    public void setSendFlag(String sendFlag) {
+        this.sendFlag = sendFlag;
+    }
 }

+ 2 - 0
java110-bean/src/main/java/com/java110/dto/inspectionPlan/InspectionTaskDto.java

@@ -15,6 +15,8 @@ import java.util.Date;
  **/
 public class InspectionTaskDto extends PageDto implements Serializable {
 
+    public static final String STATE_NO_START = "20200405";
+
     private String planUserId;
     private String actInsTime;
     private String planInsTime;

+ 10 - 0
java110-bean/src/main/java/com/java110/po/inspection/InspectionTaskDetailPo.java

@@ -40,6 +40,8 @@ public class InspectionTaskDetailPo implements Serializable {
     private String actUserId;
     private String actUserName;
 
+    private String sendFlag;
+
     public String getTaskDetailId() {
         return taskDetailId;
     }
@@ -175,4 +177,12 @@ public class InspectionTaskDetailPo implements Serializable {
     public void setActUserName(String actUserName) {
         this.actUserName = actUserName;
     }
+
+    public String getSendFlag() {
+        return sendFlag;
+    }
+
+    public void setSendFlag(String sendFlag) {
+        this.sendFlag = sendFlag;
+    }
 }

+ 13 - 3
java110-db/src/main/resources/mapper/community/InspectionTaskDetailServiceDaoImplMapper.xml

@@ -21,7 +21,8 @@
         taskId,t.task_detail_id,t.task_detail_id taskDetailId,t.patrol_type,t.description,t.patrol_type patrolType,
         t.longitude,t.latitude,t.inspection_time,t.inspection_time inspectionTime,t.inspection_state,
         t.inspection_state inspectionState,t.point_start_time,t.point_start_time
-        pointStartTime,t.point_end_time,t.point_end_time pointEndTime,t.sort_number,t.sort_number sortNumber,t.act_user_id,t.act_user_id actUserId,t.act_user_name,t.act_user_name actUserName
+        pointStartTime,t.point_end_time,t.point_end_time pointEndTime,t.sort_number,t.sort_number sortNumber,t.act_user_id,
+        t.act_user_id actUserId,t.act_user_name,t.act_user_name actUserName,t.send_flag sendFlag
         from business_inspection_task_detail t
         where 1 =1
         <if test="inspectionId !=null and inspectionId != ''">
@@ -120,8 +121,8 @@
         t.inspection_time inspectionTime,t.inspection_state,t.inspection_state inspectionState,td3.name
         inspectionStateName,
         ipl.inspection_plan_name,ipl.inspection_plan_name inspectionPlanName,ir.route_name,ir.route_name routeName,
-        it.plan_user_name,it.plan_user_name planUserName,it.act_user_name,it.act_user_name actUserName,td4.name,td4.name
-        signTypeName,td5.name taskStateName,ip.item_id itemId
+        it.plan_user_name,it.plan_user_name planUserName,it.plan_user_id,it.plan_user_id planUserId,it.act_user_name,it.act_user_name actUserName,td4.name,td4.name
+        signTypeName,td5.name taskStateName,ip.item_id itemId,t.send_flag sendFlag
         from inspection_task_detail t
         LEFT JOIN inspection_point ip on t.inspection_id = ip.inspection_id and ip.status_cd = '0'
         left join t_dict td1 on t.state = td1.status_cd and td1.table_name = 'inspection_task_detail' and
@@ -219,6 +220,9 @@
         <if test="inspectionEndTime !=null and inspectionEndTime != ''">
             and t.inspection_time &lt;= #{inspectionEndTime}
         </if>
+        <if test="sendFlag !=null and sendFlag != ''">
+            and t.send_flag = #{sendFlag}
+        </if>
         order by t.sort_number desc
         <if test="page != -1 and page != null ">
             limit #{page}, #{row}
@@ -270,6 +274,9 @@
         <if test="actUserName !=null and actUserName != ''">
             , t.act_user_name= #{actUserName}
         </if>
+        <if test="sendFlag !=null and sendFlag != ''">
+            , t.send_flag = #{sendFlag}
+        </if>
         where 1=1
         <if test="bId !=null and bId != ''">
             and t.b_id= #{bId}
@@ -366,5 +373,8 @@
         <if test="inspectionEndTime !=null and inspectionEndTime != ''">
             and t.inspection_time &lt;= #{inspectionEndTime}
         </if>
+        <if test="sendFlag !=null and sendFlag != ''">
+            and t.send_flag = #{sendFlag}
+        </if>
     </select>
 </mapper>

+ 197 - 0
service-job/src/main/java/com/java110/job/task/inspection/PublishStaffInspectionTaskTemplate.java

@@ -0,0 +1,197 @@
+package com.java110.job.task.inspection;
+
+import com.alibaba.fastjson.JSON;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.factory.WechatFactory;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.inspectionPlan.*;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
+import com.java110.dto.staffAppAuth.StaffAppAuthDto;
+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.intf.community.*;
+import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
+import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
+import com.java110.intf.user.IStaffAppAuthInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
+import com.java110.job.quartz.TaskSystemQuartz;
+import com.java110.po.inspection.InspectionTaskDetailPo;
+import com.java110.po.inspection.InspectionTaskPo;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
+import com.java110.vo.api.inspectionPoint.ApiInspectionPointDataVo;
+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.ParseException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class PublishStaffInspectionTaskTemplate extends TaskSystemQuartz {
+
+    @Autowired
+    private IInspectionPlanInnerServiceSMO inspectionPlanInnerServiceSMOImpl;
+
+    @Autowired
+    private IInspectionPlanStaffInnerServiceSMO inspectionPlanStaffInnerServiceSMOImpl;
+
+    @Autowired
+    private IInspectionRoutePointRelInnerServiceSMO inspectionRoutePointRelInnerServiceSMOImpl;
+
+
+    @Autowired
+    private IInspectionTaskInnerServiceSMO inspectionTaskInnerServiceSMOImpl;
+
+    @Autowired
+    private IInspectionTaskDetailInnerServiceSMO inspectionTaskDetailInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWechatAttrInnerServiceSMO smallWechatAttrInnerServiceSMOImpl;
+
+    @Autowired
+    private IStaffAppAuthInnerServiceSMO staffAppAuthInnerServiceSMO;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMO;
+
+
+    //模板信息推送地址
+    private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
+
+    @Override
+    protected void process(TaskDto taskDto) throws Exception {
+        logger.debug("开始执行微信模板信息推送" + taskDto.toString());
+
+        // 获取小区
+        List<CommunityDto> communityDtos = getAllCommunity();
+
+        for (CommunityDto communityDto : communityDtos) {
+            try {
+                publishStaffInspectionTask(taskDto, communityDto);
+            } catch (Exception e) {
+                logger.error("推送消息失败", e);
+            }
+        }
+    }
+
+    /**
+     * 巡检任务
+     *
+     * @param taskDto
+     * @param communityDto
+     */
+    private void publishStaffInspectionTask(TaskDto taskDto, CommunityDto communityDto) {
+        InspectionTaskDetailDto inspectionTaskDetailDto = new InspectionTaskDetailDto();
+        inspectionTaskDetailDto.setCommunityId(communityDto.getCommunityId());
+        inspectionTaskDetailDto.setState(InspectionTaskDto.STATE_NO_START);
+        inspectionTaskDetailDto.setQrCodeTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
+        inspectionTaskDetailDto.setSendFlag(InspectionTaskDetailDto.SEND_FLAG_N);
+        List<InspectionTaskDetailDto> inspectionTaskDetailDtos = inspectionTaskDetailInnerServiceSMOImpl.queryInspectionTaskDetails(inspectionTaskDetailDto);
+
+        for (InspectionTaskDetailDto inspectionTaskDetailDto1 : inspectionTaskDetailDtos) {
+            dealInspectionTaskDetail(inspectionTaskDetailDto1, taskDto, communityDto);
+        }
+    }
+
+    /**
+     * 处理巡检计划
+     *
+     * @param inspectionTaskDetailDto
+     * @param taskDto
+     * @param communityDto
+     */
+    private void dealInspectionTaskDetail(InspectionTaskDetailDto inspectionTaskDetailDto, TaskDto taskDto, CommunityDto communityDto) {
+
+        String startTime = inspectionTaskDetailDto.getPointStartTime();
+
+        startTime = DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B) + " " + startTime + ":00";
+        Date startDate = null;
+        try {
+            startDate = DateUtil.getDateFromString(startTime, DateUtil.DATE_FORMATE_STRING_A);
+        } catch (ParseException e) {
+            e.printStackTrace();
+            startDate = new Date();
+        }
+
+        //还没有到时间
+        if (startDate.getTime() > DateUtil.getCurrentDate().getTime()) {
+            return;
+        }
+        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_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(inspectionTaskDetailDto.getPlanUserId());
+        staffAppAuthDto.setAppType("WECHAT");
+        List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMO.queryStaffAppAuths(staffAppAuthDto);
+        if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
+            return;
+        }
+        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(inspectionTaskDetailDto.getInspectionName()));
+        data.setKeyword2(new Content(inspectionTaskDetailDto.getPlanInsTime()));
+        data.setKeyword3(new Content(inspectionTaskDetailDto.getInspectionName() + "未巡检,请及时巡检"));
+        data.setRemark(new Content("如有疑问请联系管理员"));
+
+        templateMessage.setData(data);
+
+        String staffWechatUrl = MappingCache.getValue("STAFF_WECHAT_URL");
+        staffWechatUrl =  staffWechatUrl
+                    + "pages/excuteOneQrCodeInspection/excuteOneQrCodeInspection?inspectionId="
+                    + inspectionTaskDetailDto.getInspectionId()
+                    + "&inspectionName=" + inspectionTaskDetailDto.getInspectionName()
+                    + "&itemId=" + inspectionTaskDetailDto.getItemId();
+
+
+        templateMessage.setUrl(staffWechatUrl);
+        logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
+        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
+        logger.info("微信模板返回内容:{}", responseEntity);
+
+    }
+
+}

+ 168 - 0
service-report/src/main/java/com/java110/report/bmo/customReport/InspectionData.java

@@ -0,0 +1,168 @@
+package com.java110.report.bmo.customReport;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.db.dao.IQueryServiceDAO;
+import com.java110.utils.util.DateUtil;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.*;
+
+
+/**
+ * select t.inspection_name '巡检点',t.point_obj_name '位置',ips.staff_name '员工',
+ (select count(1) from inspection_task it
+ INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'
+ where it.inspection_plan_id = ip.inspection_plan_id
+ and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id
+ and itd.act_user_id is not null
+ ) '已巡检',
+ (select count(1) from inspection_task it
+ INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'
+ where it.inspection_plan_id = ip.inspection_plan_id
+ and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id
+ and itd.act_user_id is null
+ ) '未巡检',
+ (select itd.description from inspection_task it
+ INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'
+ where it.inspection_plan_id = ip.inspection_plan_id
+ and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id
+ and itd.act_user_id is not null
+ limit 1
+ ) '状态'
+ from inspection_point t
+ left join inspection_route_point_rel irpr on t.inspection_id = irpr.inspection_id and irpr.status_cd = '0'
+ left join inspection_plan ip on ip.inspection_route_id = irpr.inspection_route_id and ip.status_cd = '0'
+ left join inspection_plan_staff ips on ip.inspection_plan_id = ips.inspection_plan_id and ips.status_cd = '0'
+
+ where ips.staff_name is not null
+ and t.community_id = #communityId#
+ and t.status_cd = '0'
+ <if test="startTime != null and startTime != ''">
+ and ip.create_time &gt; #startTime#
+ </if>
+ <if test="endTime != null and endTime != ''">
+ and ip.create_time &lt; #endTime#
+ </if>
+
+ group by t.inspection_name,t.point_obj_name,ips.staff_name
+ order by t.inspection_name
+ */
+
+public class InspectionData implements ReportExecute {
+
+    public JSONObject hasInTd(JSONArray tds, Map dataObj) {
+
+        if (tds == null || tds.size() < 1) {
+            return null;
+        }
+
+        for (int tdIndex = 0; tdIndex < tds.size(); tdIndex++) {
+            if (tds.getJSONObject(tdIndex).getString("巡检点").equals(dataObj.get("巡检点"))) {
+                return tds.getJSONObject(tdIndex);
+            }
+        }
+
+
+        return null;
+
+    }
+
+    public String execute(JSONObject params, IQueryServiceDAO queryServiceDAOImpl) {
+        JSONObject paramOut = new JSONObject();
+
+        List sqlParams = new ArrayList();
+        String sql = "select t.inspection_name '巡检点',t.point_obj_name '位置',ips.staff_name '员工',\n" +
+                "(select count(1) from inspection_task it \n" +
+                "INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'\n" +
+                "where it.inspection_plan_id = ip.inspection_plan_id\n" +
+                "and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id\n" +
+                "and itd.act_user_id is not null\n" +
+                "and it.create_time > ?\n" +
+                "and it.create_time < ?\n" +
+                ") '已巡检',\n" +
+                "(select count(1) from inspection_task it \n" +
+                "INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'\n" +
+                "where it.inspection_plan_id = ip.inspection_plan_id\n" +
+                "and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id\n" +
+                "and itd.act_user_id is null\n" +
+                "and it.create_time > ?\n" +
+                "and it.create_time < ?\n" +
+                ") '未巡检',\n" +
+                "(select itd.description from inspection_task it \n" +
+                "INNER JOIN inspection_task_detail itd on it.task_id = itd.task_id and itd.status_cd = '0'\n" +
+                "where it.inspection_plan_id = ip.inspection_plan_id\n" +
+                "and itd.inspection_id = t.inspection_id and it.plan_user_id = ips.staff_id\n" +
+                "and itd.act_user_id is not null\n" +
+                "and it.create_time > ?\n" +
+                "and it.create_time < ?\n" +
+                "limit 1\n" +
+                ") '状态'\n" +
+                " from inspection_point t \n" +
+                "left join inspection_route_point_rel irpr on t.inspection_id = irpr.inspection_id and irpr.status_cd = '0'\n" +
+                "left join inspection_plan ip on ip.inspection_route_id = irpr.inspection_route_id and ip.status_cd = '0'\n" +
+                "left join inspection_plan_staff ips on ip.inspection_plan_id = ips.inspection_plan_id and ips.status_cd = '0'\n" +
+                "\n" +
+                "where ips.staff_name is not null\n" +
+                "and t.status_cd = '0'\n" ;
+        if (params.containsKey("startTime") && !StringUtils.isEmpty(params.getString("startTime"))) {
+            sqlParams.add(params.get("startTime"));
+            sqlParams.add(params.get("endTime"));
+            sqlParams.add(params.get("startTime"));
+            sqlParams.add(params.get("endTime"));
+            sqlParams.add(params.get("startTime"));
+            sqlParams.add(params.get("endTime"));
+        } else {
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.DAY_OF_YEAR, 1);
+            String tomorrow = DateUtil.getFormatTimeString(calendar.getTime(), DateUtil.DATE_FORMATE_STRING_B);
+            sqlParams.add(DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_B));
+            sqlParams.add(tomorrow);
+            sqlParams.add(DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_B));
+            sqlParams.add(tomorrow);
+            sqlParams.add(DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_B));
+            sqlParams.add(tomorrow);
+        }
+        if (params.containsKey("communityId") && !StringUtils.isEmpty(params.getString("communityId"))) {
+            sql += "and t.`community_id` = ? ";
+            sqlParams.add(params.get("communityId"));
+        }
+
+        sql += "group by t.inspection_name,t.point_obj_name,ips.staff_name\n" +
+                "order by t.inspection_name";
+
+
+        List datas = queryServiceDAOImpl.executeSql(sql, sqlParams.toArray());
+
+        System.out.println("datas="+datas);
+
+        if (datas == null || datas.size() < 1) {
+            paramOut.put("toatl",1);
+            paramOut.put("data",new JSONArray());
+            return paramOut.toJSONString();
+        }
+
+        JSONArray tds = new JSONArray();
+        JSONObject td = null;
+        for (int dataIndex = 0; dataIndex < datas.size(); dataIndex++) {
+            Map dataObj = (Map) datas.get(dataIndex);
+            td = hasInTd(tds, dataObj);
+
+            if (td == null) {
+                td = new JSONObject(true);
+                td.put("巡检点", dataObj.get("巡检点"));
+                tds.add(td);
+            }
+
+            td.put(dataObj.get("员工").toString(), dataObj.get("已巡检") + "/" + dataObj.get("未巡检"));
+            td.put(dataObj.get("员工").toString()+"巡检状态", dataObj.get("状态"));
+        }
+
+        paramOut.put("total",params.get("row"));
+        paramOut.put("data",tds);
+
+        return paramOut.toJSONString();
+    }
+
+
+}

+ 1 - 1
service-report/src/main/java/com/java110/report/bmo/customReport/InspectionStaffData.java

@@ -111,7 +111,7 @@ public class InspectionStaffData implements ReportExecute {
             }
 
             td.put(dataObj.get("巡检点").toString(), dataObj.get("已巡检") + "/" + dataObj.get("未巡检"));
-            td.put("状态", dataObj.get("状态"));
+            td.put(dataObj.get("巡检点").toString()+"状态", dataObj.get("状态"));
         }
 
         paramOut.put("total",params.get("row"));