From d33e2d4a6e82487532251e8ec6e32b06de442d9f Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期一, 07 八月 2023 21:57:27 +0800
Subject: [PATCH] 优化代码
---
service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java | 237 +++++++++++++++-------------------------------------------
1 files changed, 63 insertions(+), 174 deletions(-)
diff --git a/service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java b/service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java
index 336c808..751dea5 100755
--- a/service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java
+++ b/service-job/src/main/java/com/java110/job/adapt/Repair/MachineReturnRepairAdapt.java
@@ -10,13 +10,13 @@
import com.java110.dto.repair.RepairDto;
import com.java110.dto.repair.RepairSettingDto;
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.entity.order.Business;
-import com.java110.entity.wechat.Content;
-import com.java110.entity.wechat.Data;
-import com.java110.entity.wechat.PropertyFeeTemplateMessage;
+import com.java110.dto.wechat.SmallWeChatDto;
+import com.java110.dto.wechat.SmallWechatAttrDto;
+import com.java110.dto.user.StaffAppAuthDto;
+import com.java110.dto.system.Business;
+import com.java110.dto.wechat.Content;
+import com.java110.dto.wechat.Data;
+import com.java110.dto.wechat.PropertyFeeTemplateMessage;
import com.java110.intf.community.ICommunityInnerServiceSMO;
import com.java110.intf.community.IRepairInnerServiceSMO;
import com.java110.intf.community.IRepairSettingInnerServiceSMO;
@@ -25,11 +25,13 @@
import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
import com.java110.intf.user.*;
import com.java110.job.adapt.DatabusAdaptImpl;
-import com.java110.po.fee.PayFeePo;
+import com.java110.job.msgNotify.MsgNotifyFactory;
import com.java110.po.owner.RepairUserPo;
import com.java110.utils.cache.MappingCache;
+import com.java110.utils.cache.UrlCache;
+import com.java110.utils.constant.MappingConstant;
import com.java110.utils.util.Assert;
-import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
@@ -88,10 +90,9 @@
@Override
public void execute(Business business, List<Business> businesses) throws Exception {
-
JSONObject data = business.getData();
JSONArray businessRepairUsers = new JSONArray();
- System.out.println("鏀跺埌鏃ュ織锛�>>>>>>>>>>>>>"+data.toJSONString());
+ System.out.println("鏀跺埌鏃ュ織锛�>>>>>>>>>>>>>" + data.toJSONString());
if (data.containsKey(RepairUserPo.class.getSimpleName())) {
Object bObj = data.get(RepairUserPo.class.getSimpleName());
@@ -102,25 +103,19 @@
} else {
businessRepairUsers = (JSONArray) bObj;
}
-
} else {
if (data instanceof JSONObject) {
businessRepairUsers.add(data);
}
}
-
//JSONObject businessOwnerCar = data.getJSONObject("businessOwnerCar");
for (int bOwnerRepairIndex = 0; bOwnerRepairIndex < businessRepairUsers.size(); bOwnerRepairIndex++) {
JSONObject businessRepairUser = businessRepairUsers.getJSONObject(bOwnerRepairIndex);
doDealOwnerRepair(business, businessRepairUser);
}
-
-
}
private void doDealOwnerRepair(Business business, JSONObject businessRepairUser) {
-
-
RepairUserDto repairUserDto = new RepairUserDto();
repairUserDto.setRuId(businessRepairUser.getString("ruId"));
repairUserDto.setStatusCd("0");
@@ -156,7 +151,7 @@
List<RepairSettingDto> repairSettingDtos = repairSettingInnerServiceSMO.queryRepairSettings(repairSettingDto);
Assert.listOnlyOne(repairSettingDtos, "淇℃伅閿欒");
JSONObject paramIn = new JSONObject();
- if (state.equals("10003")) { //閫�鍗曠姸鎬�
+ if (RepairUserDto.STATE_BACK.equals(state)) { //閫�鍗曠姸鎬�
//閫�鍗曚汉
String staffName = repairUserDtos.get(0).getStaffName();
//閫�鍗曞娉�
@@ -172,8 +167,9 @@
paramIn.put("returnContext", returnContext);
paramIn.put("preStaffId", preStaffId);
paramIn.put("preStaffName", preStaffName);
+ paramIn.put("repairName", repairUserDtos.get(0).getRepairName());
sendReturnMessage(paramIn, communityDtos.get(0));
- } else if (state.equals("10002")) { //缁撳崟
+ } else if (RepairUserDto.STATE_CLOSE.equals(state)) { //缁撳崟
//鑾峰彇鐢ㄦ埛id
String preStaffId = repairUserDtos.get(0).getPreStaffId();
//鑾峰彇缁翠慨甯堝倕濮撳悕
@@ -186,17 +182,6 @@
String time = format.format(endTime);
//鑾峰彇浠锋牸
String price = "";
- //杩欓噷寤鸿鏌ヨ 鎶ヤ慨鎵�鍦ㄨ垂鐢ㄧ殑 鍥哄畾璐�
-
-// for (Business bus : businesses) {
-// if (bus.getBusinessTypeCd().equals("600100030001")) { //淇濆瓨璐圭敤淇℃伅
-// JSONObject data = bus.getData();
-// JSONArray jsonArray = data.getJSONArray("PayFeePo");
-// JSONObject jsonObject = jsonArray.getJSONObject(0);
-// PayFeePo payFeePo = BeanConvertUtil.covertBean(jsonObject, PayFeePo.class);
-// price = payFeePo.getAmount();
-// }
-// }
paramIn.put("repairName", repairName);
paramIn.put("repairObjName", repairObjName);
paramIn.put("context", context);
@@ -212,7 +197,7 @@
//鑾峰彇鎶ヤ慨鐢ㄦ埛id
String staffId = repairUserDtoList.get(0).getStaffId();
paramIn.put("userId", staffId);
- publishReturnMsg(paramIn, communityDtos.get(0));
+ sendFinishRepairOwnerMsg(paramIn, communityDtos.get(0));
if (!StringUtil.isEmpty(price)) {
paramIn.put("price", price);
paramIn.put("feeState", "鏈即璐�");
@@ -235,61 +220,20 @@
* @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;
+
+ JSONObject content = new JSONObject();
+ content.put("repairTypeName", paramIn.getString("repairTypeName"));
+ if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
+ content.put("repairObjName", paramIn.getString("repairObjName"));
+ } else {
+ content.put("repairObjName", communityDto.getName() + paramIn.getString("repairObjName"));
}
- 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;
- }
- String url = sendMsgUrl + accessToken;
- //鏍规嵁 userId 鏌ヨ鍒皁penId
- StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
- staffAppAuthDto.setStaffId(paramIn.getString("preStaffId"));
- 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(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("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);
- }
+ content.put("repairName", paramIn.getString("repairName"));
+ String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL");
+ content.put("url", wechatUrl);
+
+ MsgNotifyFactory.sendReturnRepairMsg(communityDto.getCommunityId(), paramIn.getString("preStaffId"), content);
+
}
/**
@@ -298,7 +242,7 @@
* @param paramIn
* @param communityDto
*/
- private void publishReturnMsg(JSONObject paramIn, CommunityDto communityDto) {
+ private void sendFinishRepairOwnerMsg(JSONObject paramIn, CommunityDto communityDto) {
//鏌ヨ鍏紬鍙烽厤缃�
SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
smallWeChatDto.setWeChatType("1100");
@@ -309,57 +253,22 @@
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;
+
+ JSONObject content = new JSONObject();
+ content.put("repairObjName", paramIn.getString("repairObjName"));
+ content.put("staffName", paramIn.getString("staffName"));
+ content.put("time", paramIn.getString("time"));
+ String wechatUrl = UrlCache.getOwnerUrl();
+ if (!StringUtil.isEmpty(wechatUrl) && wechatUrl.contains("?")) {
+ wechatUrl += ("&wAppId=" + smallWeChatDtos.get(0).getAppId());
+ } else {
+ wechatUrl += ("?wAppId=" + smallWeChatDtos.get(0).getAppId());
}
- 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 staffId = paramIn.getString("userId");
- if (!StringUtil.isEmpty(staffId)) {
- OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
- ownerAppUserDto.setUserId(staffId);
- ownerAppUserDto.setAppType("WECHAT");
- //鏌ヨ缁戝畾涓氫富
- List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMO.queryOwnerAppUsers(ownerAppUserDto);
- if (ownerAppUserDtos != null && 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("灏婃暚鐨�" + 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);
- }
- }
+ content.put("url", wechatUrl);
+
+ MsgNotifyFactory.sendFinishRepairOwnerMsg(communityDto.getCommunityId(), paramIn.getString("userId"), content);
+
+
}
/**
@@ -369,6 +278,7 @@
* @param communityDto
*/
private void sendMessage(JSONObject paramIn, CommunityDto communityDto) {
+
//鏌ヨ鍏紬鍙烽厤缃�
SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
smallWeChatDto.setWeChatType("1100");
@@ -379,22 +289,7 @@
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_REPAIR_CHARGE_SCENE_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;
- }
+
//鑾峰彇鎴垮眿鎵�灞炰笟涓�
OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
ownerRoomRelDto.setRoomId(paramIn.getString("roomId"));
@@ -407,28 +302,22 @@
ownerAppUserDto.setMemberId(ownerId);
ownerAppUserDto.setAppType("WECHAT");
List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMO.queryOwnerAppUsers(ownerAppUserDto);
- if (ownerAppUserDtos != null && 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(paramIn.getString("roomName") + "缂磋垂淇℃伅濡備笅锛�"));
- data.setKeyword1(new Content(paramIn.getString("roomName")));
- data.setKeyword2(new Content(paramIn.getString("repairName")));
- data.setKeyword3(new Content("缁翠慨璐�"));
- data.setKeyword4(new Content(paramIn.getString("feeState")));
- data.setKeyword5(new Content(paramIn.getString("price") + "鍏�"));
- 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);
+ if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+ return;
}
+ JSONObject content = new JSONObject();
+ content.put("feeTypeName", "缁翠慨璐�");
+ content.put("payerObjName", paramIn.getString("roomName"));
+ content.put("billAmountOwed", paramIn.getString("price") + "鍏�");
+ content.put("date", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
+ String wechatUrl = UrlCache.getOwnerUrl();
+ if (!StringUtil.isEmpty(wechatUrl) && wechatUrl.contains("?")) {
+ wechatUrl += ("&wAppId=" + smallWeChatDtos.get(0).getAppId());
+ } else {
+ wechatUrl += ("?wAppId=" + smallWeChatDtos.get(0).getAppId());
+ }
+ content.put("url", wechatUrl);
+ MsgNotifyFactory.sendOweFeeMsg(communityDto.getCommunityId(), ownerAppUserDtos.get(0).getUserId(), content);
+
}
}
--
Gitblit v1.8.0