master
kira 6 years ago
parent 5c19193c78
commit 1a73f48808

@ -419,7 +419,7 @@ public class RetailAppServiceImp implements RetailAppService {
@Override
public JSONObject openimCheck(JSONObject device) {
JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
return customerServiceService.checkAndSave(account);
return customerServiceService.checkAndSavePartner(account);
}
//暂不使用

@ -30,5 +30,8 @@ public interface SysCustomerServiceMapper {
@AutoSql(type = SqlType.SELECT)
List<JSONObject> findAllWithDetail();
@AutoSql(type = SqlType.COUNT)
int countAll();
}

@ -41,7 +41,7 @@ public class OpenimController {
@RequestMapping(value = "/check", method = RequestMethod.PUT)
@RequireManager
public JSONObject sendMsg(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return customerServiceService.checkAndSave(manager);
return customerServiceService.checkAndSaveManager(manager);
}
@RequestMapping(value = "/signin", method = RequestMethod.POST)

@ -12,7 +12,9 @@ import java.util.List;
*/
public interface CustomerServiceService {
JSONObject checkAndSave(JSONObject account);
JSONObject checkAndSavePartner(JSONObject account);
JSONObject checkAndSaveManager(JSONObject manager);
OpenimUserVO findOne(int clientId,String userName);
@ -24,4 +26,5 @@ public interface CustomerServiceService {
void sendUnreadWxMsg();
}

@ -10,7 +10,7 @@ public interface OpenimApi {
void addUser(JSONObject record);
void updateUser();
void updateUser(JSONObject record);
void pushMsh();

@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -118,21 +117,19 @@ public class OpenimClient {
String url = "https://eco.taobao.com/router/rest";
TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
OpenimUsersAddRequest req = new OpenimUsersAddRequest();
List<Userinfos> list2 = new ArrayList<Userinfos>();
Userinfos obj3 = new Userinfos();
list2.add(obj3);
obj3.setNick("king");
obj3.setIconUrl("https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1948403834,955109320&fm=85&s=0D06E5134AD145F30C8D6D680300303A");
obj3.setUserid("kira3_PINE");
obj3.setPassword("xxxxxx");
req.setUserinfos(list2);
OpenimUsersAddResponse rsp = null;
OpenimUsersGetRequest req = new OpenimUsersGetRequest();
// 批量为userid逗号分隔字符串
req.setUserids("kiraservant");
OpenimUsersGetResponse rsp = null;
try {
rsp = client.execute(req);
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println(rsp.getBody());
JSONObject openInfo = JSONObject.parseObject(rsp.getBody());
System.out.println(openInfo.toJSONString());
System.out.println(openInfo.toJSONString());
System.out.println(openInfo.toJSONString());
}
}

@ -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);
}
}
}
}

@ -39,8 +39,13 @@ public class OpenimApiImpl implements OpenimApi {
}
@Override
public void updateUser() {
public void updateUser(JSONObject user) {
List<Userinfos> updateList = new ArrayList<>();
Userinfos record = new Userinfos();
record.setUserid(user.getString("user_id"));
record.setNick(user.getString("nick"));
updateList.add(record);
openimClient.updateUser(updateList);
}
@Override

@ -97,9 +97,9 @@
<select id="listServants" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT display_name,manager_id
FROM sys_managers
WHERE role & #{mask} >0 AND (org_id IS NULL or org_id=1) AND is_valid = 1
SELECT m.display_name display_name,m.manager_id manager_id, cs.nick nick
FROM sys_managers m left join sys_customer_service cs on m.manager_id = cs.manager_id
WHERE m.role & #{mask} >0 AND (m.org_id IS NULL or m.org_id=1) AND m.is_valid = 1
]]>
</select>

Loading…
Cancel
Save