java110-bean/src/main/java/com/java110/dto/data/DatabusDataDto.java
@@ -33,6 +33,9 @@ public static final String BUSINESS_TYPE_SEND_COMMUNITY_DATA_TO_IOT = "sendCommunityDataToIot"; public static final String BUSINESS_TYPE_SEND_COMPLAINT_NOTIFY_STAFF = "sendComplaintNotifyStaff"; // 发送投诉给员工 private String businessTypeCd; private JSONObject data; service-job/src/main/java/com/java110/job/adapt/complaint/SendComplaintNotifyStaffAdapt.java
New file @@ -0,0 +1,82 @@ package com.java110.job.adapt.complaint; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.java110.core.log.LoggerFactory; import com.java110.dto.complaint.ComplaintDto; import com.java110.dto.complaintTypeUser.ComplaintTypeUserDto; import com.java110.dto.system.Business; import com.java110.intf.store.IComplaintTypeUserV1InnerServiceSMO; import com.java110.intf.store.IComplaintV1InnerServiceSMO; import com.java110.job.adapt.DatabusAdaptImpl; import com.java110.job.adapt.Repair.MachineReturnRepairAdapt; import com.java110.job.msgNotify.MsgNotifyFactory; import com.java110.po.owner.RepairUserPo; import com.java110.utils.cache.MappingCache; import com.java110.utils.constant.MappingConstant; import com.java110.utils.util.ListUtil; import com.java110.utils.util.StringUtil; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; /** * 投诉单推送消息给员工 */ @Component(value = "sendComplaintNotifyStaffAdapt") public class SendComplaintNotifyStaffAdapt extends DatabusAdaptImpl { private static Logger logger = LoggerFactory.getLogger(SendComplaintNotifyStaffAdapt.class); @Autowired private IComplaintV1InnerServiceSMO complaintV1InnerServiceSMOImpl; @Autowired private IComplaintTypeUserV1InnerServiceSMO complaintTypeUserV1InnerServiceSMOImpl; @Override public void execute(Business business, List<Business> businesses) throws Exception { JSONObject data = business.getData(); String complaintId = data.getString("complaintId"); if (StringUtil.isEmpty(complaintId)) { return; } ComplaintDto complaintDto = new ComplaintDto(); complaintDto.setComplaintId(complaintId); List<ComplaintDto> complaintDtos = complaintV1InnerServiceSMOImpl.queryComplaints(complaintDto); if (ListUtil.isNull(complaintDtos)) { return; } ComplaintTypeUserDto complaintTypeUserDto = new ComplaintTypeUserDto(); complaintTypeUserDto.setTypeCd(complaintDtos.get(0).getTypeCd()); List<ComplaintTypeUserDto> complaintTypeUserDtos = complaintTypeUserV1InnerServiceSMOImpl.queryComplaintTypeUsers(complaintTypeUserDto); if (ListUtil.isNull(complaintTypeUserDtos)) { return; } JSONObject content = new JSONObject(); content.put("complaintName", complaintDtos.get(0).getComplaintName()); content.put("orderId", complaintId); String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL"); content.put("url", wechatUrl); for(ComplaintTypeUserDto tmpComplaintTypeUserDto:complaintTypeUserDtos) { MsgNotifyFactory.sendComplaintMsg(tmpComplaintTypeUserDto.getCommunityId(), tmpComplaintTypeUserDto.getStaffId(), content); } } } service-job/src/main/java/com/java110/job/msgNotify/IMsgNotify.java
@@ -154,4 +154,13 @@ * @return */ ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content); /** * 投诉通知 员工 * @param communityId * @param userId * @param content * @return */ ResultVo sendComplaintMsg(String communityId, String userId, JSONObject content); } service-job/src/main/java/com/java110/job/msgNotify/MsgNotifyFactory.java
@@ -355,4 +355,25 @@ return notify; } /** * 投诉通知消息 * @param communityId * @param staffId * @param content */ public static ResultVo sendComplaintMsg(String communityId, String staffId, JSONObject content) { ResultVo resultVo = null; try { IMsgNotify msgNotify = getMsgNotify(); resultVo = msgNotify.sendComplaintMsg(communityId, staffId, content); } catch (Exception e) { e.printStackTrace(); logger.error("通知 业主报修时 消息", e); resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage()); } return resultVo; } } service-job/src/main/java/com/java110/job/msgNotify/ali/AliMsgNotifyImpl.java
@@ -23,6 +23,7 @@ import com.java110.utils.cache.MappingCache; import com.java110.utils.util.Assert; import com.java110.utils.util.DateUtil; import com.java110.utils.util.ListUtil; import com.java110.utils.util.StringUtil; import com.java110.vo.ResultVo; import org.slf4j.Logger; @@ -449,7 +450,7 @@ UserDto userDto = new UserDto(); userDto.setUserId(userId); List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto); if (userDtos == null || userDtos.size() < 1) { if (ListUtil.isNull(userDtos)) { throw new IllegalArgumentException("员工不存在"); } @@ -493,4 +494,70 @@ } return new ResultVo(ResultVo.CODE_OK, "成功"); } /** * 投诉通知员工 * * @param communityId 小区 * @param userId 用户 * @param content { * complainName, * orderId * } * @return */ @Override public ResultVo sendComplaintMsg(String communityId, String userId, JSONObject content) { if (StringUtil.isEmpty(userId) || userId.startsWith("-")) { throw new IllegalArgumentException("员工不存在,userId = " + userId); } UserDto userDto = new UserDto(); userDto.setUserId(userId); List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto); if (ListUtil.isNull(userDtos)) { throw new IllegalArgumentException("员工不存在"); } String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID"); String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET"); String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION"); String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME"); String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_COMPLAINT_TEMPLATE_CODE"); DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessSecret); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("RegionId", region); request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel()); request.putQueryParameter("SignName", signName); request.putQueryParameter("TemplateCode", templateCode); JSONObject param = new JSONObject(); param.put("orderId", content.getString("orderId")); request.putQueryParameter("TemplateParam", param.toString()); String resParam = ""; try { CommonResponse response = client.getCommonResponse(request); logger.debug("发送验证码信息:{}", response.getData()); resParam = response.getData(); } catch (Exception e) { e.printStackTrace(); resParam = e.getMessage(); throw new IllegalArgumentException("短信工单失败" + e.getMessage()); } finally { LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK)); } return new ResultVo(ResultVo.CODE_OK, "成功"); } } service-job/src/main/java/com/java110/job/msgNotify/wechat/WechatMsgNotifyImpl.java
@@ -19,6 +19,7 @@ import com.java110.utils.cache.MappingCache; import com.java110.utils.constant.MappingConstant; import com.java110.utils.util.DateUtil; import com.java110.utils.util.ListUtil; import com.java110.utils.util.StringUtil; import com.java110.vo.ResultVo; import org.slf4j.Logger; @@ -612,4 +613,54 @@ JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody()); return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg")); } /** * 投诉通知员工 * * @param communityId 小区 * @param userId 用户 * @param content { * complainName * } * @return */ @Override public ResultVo sendComplaintMsg(String communityId, String userId, JSONObject content) { String accessToken = wechatTemplateImpl.getAccessToken(communityId); StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto(); staffAppAuthDto.setStaffId(userId); staffAppAuthDto.setAppType("WECHAT"); List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto); if (ListUtil.isNull(staffAppAuthDtos)) { throw new IllegalArgumentException("员工未认证,没有获取到微信openId"); } String openId = staffAppAuthDtos.get(0).getOpenId(); Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_PROCESS_TEMPLATE); if (mapping == null) { throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_PROCESS_TEMPLATE); } String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_PROCESS_TEMPLATE)); String url = sendMsgUrl + accessToken; JSONObject data = new JSONObject(); PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage(); templateMessage.setTemplate_id(templateId); templateMessage.setTouser(openId); data.put("thing2", new Content("投诉单处理流程")); data.put("time10", new Content(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B))); data.put("thing9", new Content(content.getString("complaintName"))); templateMessage.setData(data); //获取员工公众号地址 String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL"); templateMessage.setUrl(wechatUrl); logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage)); ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class); logger.info("微信模板返回内容:{}", responseEntity); JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody()); return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg")); } } service-store/src/main/java/com/java110/store/cmd/complaint/SaveComplaintCmd.java
@@ -28,6 +28,7 @@ import com.java110.dto.complaint.ComplaintDto; import com.java110.dto.complaintEvent.ComplaintEventDto; import com.java110.dto.complaintType.ComplaintTypeDto; import com.java110.dto.data.DatabusDataDto; import com.java110.dto.file.FileDto; import com.java110.dto.room.RoomDto; import com.java110.dto.user.UserDto; @@ -37,6 +38,7 @@ import com.java110.intf.community.ICommunityMemberV1InnerServiceSMO; import com.java110.intf.community.ICommunityV1InnerServiceSMO; import com.java110.intf.community.IRoomInnerServiceSMO; import com.java110.intf.job.IDataBusInnerServiceSMO; import com.java110.intf.store.IComplaintEventV1InnerServiceSMO; import com.java110.intf.store.IComplaintTypeV1InnerServiceSMO; import com.java110.intf.store.IComplaintV1InnerServiceSMO; @@ -96,6 +98,9 @@ @Autowired private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl; @Autowired private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl; @Override @@ -186,6 +191,8 @@ //todo 图片 savePhone(reqJson, complaintPo); //todo 发送消息给处理师傅 dataBusInnerServiceSMOImpl.databusData(new DatabusDataDto(DatabusDataDto.BUSINESS_TYPE_SEND_COMPLAINT_NOTIFY_STAFF,BeanConvertUtil.beanCovertJson(complaintPo))); cmdDataFlowContext.setResponseEntity(ResultVo.success()); }