|
|
|
@ -7,6 +7,7 @@ import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
|
|
|
import au.com.royalpay.payment.manage.openim.beans.OpenimUserVO;
|
|
|
|
|
import au.com.royalpay.payment.manage.openim.core.CustomerServiceService;
|
|
|
|
|
import au.com.royalpay.payment.manage.openim.core.OpenimApi;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
@ -16,15 +17,17 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.data.redis.core.BoundListOperations;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
@ -47,10 +50,14 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
private SysCustomerServiceMapper sysCustomerServiceMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private MpWechatApiProvider mpWechatApiProvider;
|
|
|
|
|
private final Map<String,Long> unReadMap = new HashMap<>();
|
|
|
|
|
@Resource
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
private final String REDIS_UNREADMSG_PREFIX = "REDIS_UNREADMSG_PREFIX";
|
|
|
|
|
private final String REDIS_UNREADMSG_SEND_PREFIX = "REDIS_UNREADMSG_SEND_PREFIX";
|
|
|
|
|
|
|
|
|
|
@Value("${im.openim.appkey}")
|
|
|
|
|
private String appkey;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject checkAndSave(JSONObject account) {
|
|
|
|
|
JSONObject client = null;
|
|
|
|
@ -67,7 +74,7 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
account = managerMapper.findDetail(account.getString("manager_id"));
|
|
|
|
|
isPartner = false;
|
|
|
|
|
}
|
|
|
|
|
String uid = account.getString("username") + (isPartner ? "_"+ client.getString("client_moniker"): "");
|
|
|
|
|
String uid = account.getString("username") + (isPartner ? "_" + client.getString("client_moniker") : "");
|
|
|
|
|
JSONObject saveRecord = new JSONObject();
|
|
|
|
|
saveRecord.put("nick", account.getString("display_name"));
|
|
|
|
|
saveRecord.put("password", DigestUtils.md5Hex("uid"));
|
|
|
|
@ -78,7 +85,7 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
saveRecord.put("user_id", uid);
|
|
|
|
|
}
|
|
|
|
|
openimApi.addUser(saveRecord);
|
|
|
|
|
saveRecord.put("appkey",appkey);
|
|
|
|
|
saveRecord.put("appkey", appkey);
|
|
|
|
|
return saveRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,57 +139,74 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
@Override
|
|
|
|
|
public void onoff(JSONObject manager, boolean onoff) {
|
|
|
|
|
JSONObject record = new JSONObject();
|
|
|
|
|
record.put("manager_id",manager.getString("manager_id"));
|
|
|
|
|
record.put("onoff",onoff);
|
|
|
|
|
record.put("manager_id", manager.getString("manager_id"));
|
|
|
|
|
record.put("onoff", onoff);
|
|
|
|
|
udpateOrSave(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addUnreadMsg(JSONObject params) {
|
|
|
|
|
String key = params.getString("uid");
|
|
|
|
|
if(unReadMap.containsKey(key)) {
|
|
|
|
|
unReadMap.put(key, unReadMap.get(key) + 1);
|
|
|
|
|
}else {
|
|
|
|
|
unReadMap.put(key,1L);
|
|
|
|
|
String uid = params.getString("uid");
|
|
|
|
|
String tuid = params.getString("tuid");
|
|
|
|
|
if (StringUtils.isEmpty(uid) || StringUtils.isEmpty(tuid)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("REDIS_UNREADMSG_PREFIX" + tuid);
|
|
|
|
|
for (int i = 0; i < ops.size(); i++) {
|
|
|
|
|
String jStr = ops.index(i);
|
|
|
|
|
if (jStr.contains(uid)) {
|
|
|
|
|
JSONObject record = JSONObject.parseObject(jStr);
|
|
|
|
|
record.put("unreadMsg", record.getIntValue("unreadMsg") + 1);
|
|
|
|
|
ops.set(i, record.toJSONString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
params.put("unreadMsg", 1);
|
|
|
|
|
ops.rightPush(params.toJSONString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sendUnreadWxMsg() {
|
|
|
|
|
unReadMap.entrySet().parallelStream().forEach(p->{
|
|
|
|
|
JSONObject account = clientAccountMapper.findByUsername(p.getKey());
|
|
|
|
|
if(StringUtils.isNotEmpty(account.getString("wx_openid"))){
|
|
|
|
|
// TemplateMessage msg = initAccountMsg(tradeInfo, client.getString("short_name"), time, String.valueOf(counts), openId, paymentApi.getTemplateId("transaction-daily"));
|
|
|
|
|
// MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
|
|
|
|
|
// paymentApi.sendTemplateMessage(msg);
|
|
|
|
|
List<JSONObject> servants = sysCustomerServiceMapper.findAllWithDetail();
|
|
|
|
|
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
|
|
|
|
|
servants.parallelStream().forEach(p -> {
|
|
|
|
|
p.getString("user_id");
|
|
|
|
|
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("REDIS_UNREADMSG_PREFIX" + p.getString("user_id"));
|
|
|
|
|
if (ops.size() < 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
p.getKey();
|
|
|
|
|
int clients = 0;
|
|
|
|
|
int unreadMsg = 0;
|
|
|
|
|
for (int i = 0; i < ops.size(); i++) {
|
|
|
|
|
clients++;
|
|
|
|
|
unreadMsg += JSONObject.parseObject(ops.index(i)).getIntValue("unreadMsg");
|
|
|
|
|
}
|
|
|
|
|
TemplateMessage msg = initUnreadMsg(unreadMsg, clients, p.getString("wx_openid"), paymentApi.getTemplateId("commission"));
|
|
|
|
|
paymentApi.sendTemplateMessage(msg);
|
|
|
|
|
stringRedisTemplate.delete("REDIS_UNREADMSG_PREFIX" + p.getString("user_id"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TemplateMessage initAccountMsg(JSONObject tradeInfo, String short_name, String time, String clientCounts, String openId, String templateId) {
|
|
|
|
|
|
|
|
|
|
private TemplateMessage initUnreadMsg(int unreadMsg, int clients, String openId, String templateId) {
|
|
|
|
|
TemplateMessage msg = new TemplateMessage(openId, templateId, null);
|
|
|
|
|
String detail = "收款总额:" + tradeInfo.getBigDecimal("total") + "$, 收款笔数:" + tradeInfo.getString("orders") + ", 付款人数:" + tradeInfo.getString("customers");
|
|
|
|
|
msg.put("first", "每日交易汇总数据(" + tradeInfo.getString("trade_date") + ")", "#000000");
|
|
|
|
|
msg.put("keyword1", short_name, "#000000");
|
|
|
|
|
msg.put("keyword2", time, "#000000");
|
|
|
|
|
msg.put("keyword3", clientCounts + "家", "#000000");
|
|
|
|
|
msg.put("keyword4", detail, "#0000ff");
|
|
|
|
|
msg.put("remark", "详情请查看商户后台、APP或皇家支付小程序", "#000000");
|
|
|
|
|
msg.setMiniprogram("wx54445a7c56432d57", "/pages/welcome/welcome");
|
|
|
|
|
msg.put("first", "你好,你有" + unreadMsg + "个未读消息", "#000000");
|
|
|
|
|
msg.put("keyword1", "商户", "#000000");
|
|
|
|
|
msg.put("keyword2", "问题咨询", "#000000");
|
|
|
|
|
msg.put("keyword3", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"), "#000000");
|
|
|
|
|
msg.put("keyword4", "你有" + clients + "个商户咨询待处理", "#0000ff");
|
|
|
|
|
msg.put("remark", "", "#000000");
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void udpateOrSave(JSONObject servant){
|
|
|
|
|
private void udpateOrSave(JSONObject servant) {
|
|
|
|
|
JSONObject record = sysCustomerServiceMapper.findByManagerId(servant.getString("manager_id"));
|
|
|
|
|
if(record==null){
|
|
|
|
|
if (record == null) {
|
|
|
|
|
JSONObject manager = managerMapper.findDetail(servant.getString("manager_id"));
|
|
|
|
|
servant.put("manager_id",manager.getString("manager_id"));
|
|
|
|
|
servant.put("user_id",manager.getString("username"));
|
|
|
|
|
servant.put("manager_id", manager.getString("manager_id"));
|
|
|
|
|
servant.put("user_id", manager.getString("username"));
|
|
|
|
|
sysCustomerServiceMapper.save(servant);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
sysCustomerServiceMapper.update(servant);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|