|
|
|
@ -12,10 +12,12 @@ 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;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -59,34 +61,42 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
private String appkey;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject checkAndSave(JSONObject account) {
|
|
|
|
|
JSONObject client = null;
|
|
|
|
|
boolean isPartner = true;
|
|
|
|
|
if (StringUtils.isNotEmpty(account.getString("account_id"))) {
|
|
|
|
|
client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
if (client == null) {
|
|
|
|
|
throw new BadRequestException("Merchant Not Found");
|
|
|
|
|
}
|
|
|
|
|
account = clientAccountMapper.findById(account.getString("account_id"));
|
|
|
|
|
isPartner = true;
|
|
|
|
|
public JSONObject checkAndSavePartner(JSONObject account) {
|
|
|
|
|
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
if (client == null) {
|
|
|
|
|
throw new BadRequestException("Merchant Not Found");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
|
|
|
|
|
account = managerMapper.findDetail(account.getString("manager_id"));
|
|
|
|
|
isPartner = false;
|
|
|
|
|
JSONObject userInfo = clientAccountMapper.findById(account.getString("account_id"));
|
|
|
|
|
JSONObject checkRecord = new JSONObject();
|
|
|
|
|
checkRecord.put("nick", userInfo.getString("username") + "_" + client.getString("client_moniker"));
|
|
|
|
|
checkRecord.put("user_id", userInfo.getString("username"));
|
|
|
|
|
checkRecord.put("password", DigestUtils.md5Hex("uid"));
|
|
|
|
|
openimApi.addUser(checkRecord);
|
|
|
|
|
checkRecord.put("servants", sysCustomerServiceMapper.findOnline());
|
|
|
|
|
checkRecord.put("appkey", appkey);
|
|
|
|
|
return checkRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject checkAndSaveManager(JSONObject manager) {
|
|
|
|
|
if (StringUtils.isEmpty(manager.getString("manager_id"))) {
|
|
|
|
|
throw new ServerErrorException("manager id is null");
|
|
|
|
|
}
|
|
|
|
|
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"));
|
|
|
|
|
if (isPartner) {
|
|
|
|
|
saveRecord.put("user_id", uid);
|
|
|
|
|
saveRecord.put("servants", sysCustomerServiceMapper.findOnline());
|
|
|
|
|
} else {
|
|
|
|
|
saveRecord.put("user_id", uid);
|
|
|
|
|
JSONObject result = sysCustomerServiceMapper.findByManagerId(manager.getString("manager_id"));
|
|
|
|
|
if (result == null) {
|
|
|
|
|
JSONObject managerDetail = managerMapper.findDetail(manager.getString("manager_id"));
|
|
|
|
|
JSONObject checkRecord = new JSONObject();
|
|
|
|
|
checkRecord.put("user_id", managerDetail.getString("username"));
|
|
|
|
|
int num = sysCustomerServiceMapper.countAll();
|
|
|
|
|
checkRecord.put("nick", "客服" + num);
|
|
|
|
|
checkRecord.put("password", RandomStringUtils.random(12, true, true).toLowerCase());
|
|
|
|
|
openimApi.addUser(checkRecord);
|
|
|
|
|
result = checkRecord;
|
|
|
|
|
}
|
|
|
|
|
openimApi.addUser(saveRecord);
|
|
|
|
|
saveRecord.put("appkey", appkey);
|
|
|
|
|
return saveRecord;
|
|
|
|
|
result.put("appkey", appkey);
|
|
|
|
|
result.remove("manager_id");
|
|
|
|
|
result.remove("onoff");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -120,10 +130,10 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(userNames)) {
|
|
|
|
|
List<String> userNams = Arrays.asList(userNames.split(","));
|
|
|
|
|
if(CollectionUtils.isEmpty(userNams)){
|
|
|
|
|
if (CollectionUtils.isEmpty(userNams)) {
|
|
|
|
|
return Collections.EMPTY_LIST;
|
|
|
|
|
}
|
|
|
|
|
queryParams.put("userNames",userNams );
|
|
|
|
|
queryParams.put("userNames", userNams);
|
|
|
|
|
}
|
|
|
|
|
if (queryParams.size() < 1) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
@ -145,7 +155,7 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
JSONObject record = new JSONObject();
|
|
|
|
|
record.put("manager_id", manager.getString("manager_id"));
|
|
|
|
|
record.put("onoff", manager.getBoolean("onoff"));
|
|
|
|
|
udpateOrSave(record);
|
|
|
|
|
saveOrUpdate(record,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -203,16 +213,24 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void udpateOrSave(JSONObject servant) {
|
|
|
|
|
JSONObject record = sysCustomerServiceMapper.findByManagerId(servant.getString("manager_id"));
|
|
|
|
|
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"));
|
|
|
|
|
private void saveOrUpdate(JSONObject servant, boolean updateOpenim) {
|
|
|
|
|
if (StringUtils.isEmpty(servant.getString("manager_id"))) {
|
|
|
|
|
throw new ServerErrorException("manager id is null");
|
|
|
|
|
}
|
|
|
|
|
JSONObject existCS = sysCustomerServiceMapper.findByManagerId(servant.getString("manager_id"));
|
|
|
|
|
if (existCS == null) {
|
|
|
|
|
JSONObject userInfo = checkAndSaveManager(servant);
|
|
|
|
|
servant.put("password", userInfo.getString("password"));
|
|
|
|
|
servant.put("nick", userInfo.getString("nick"));
|
|
|
|
|
servant.put("user_id", userInfo.getString("user_id"));
|
|
|
|
|
sysCustomerServiceMapper.save(servant);
|
|
|
|
|
} else {
|
|
|
|
|
sysCustomerServiceMapper.update(servant);
|
|
|
|
|
}
|
|
|
|
|
if (updateOpenim) {
|
|
|
|
|
servant.put("user_id", existCS.getString("user_id"));
|
|
|
|
|
openimApi.updateUser(servant);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|