From 954b9b6fd2ad17f99273147bf437813c114e9dca Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 12 Jul 2018 10:22:42 +0800 Subject: [PATCH] tmp --- .../appclient/core/RetailAppService.java | 2 + .../core/impls/RetailAppServiceImp.java | 9 ++ .../appclient/web/RetailAppController.java | 63 ++++++----- .../manage/mappers/openim/OpenimMapper.java | 26 +++++ .../manage/openim/OpenimController.java | 34 ++++++ .../openim/core/CustomerServiceService.java | 12 ++ .../payment/manage/openim/core/OpenimApi.java | 12 ++ .../manage/openim/core/OpenimClient.java | 105 ++++++++---------- .../core/impl/CustomerServiceServiceImpl.java | 53 +++++++++ .../openim/core/impl/OpenimApiImpl.java | 54 +++++++++ .../resources/templates/customer_service.html | 25 +++++ src/main/ui/manage.html | 4 +- 12 files changed, 307 insertions(+), 92 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java create mode 100644 src/main/resources/templates/customer_service.html diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index c3cfc669f..0ff5470dc 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -149,4 +149,6 @@ public interface RetailAppService { void applyToCompliance(JSONObject device); JSONObject sendVerifyEmail(JSONObject device); + + void openimCheck(JSONObject device); } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index 57dadf95b..c09e8246b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -30,6 +30,7 @@ import au.com.royalpay.payment.manage.merchants.entity.impls.SwitchPermissionMod import au.com.royalpay.payment.manage.notice.beans.NoticeInfo; import au.com.royalpay.payment.manage.notice.core.NoticeManage; import au.com.royalpay.payment.manage.notice.core.NoticePartner; +import au.com.royalpay.payment.manage.openim.core.CustomerServiceService; import au.com.royalpay.payment.manage.pushMessage.APNSMessageHelper; import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; @@ -166,6 +167,8 @@ public class RetailAppServiceImp implements RetailAppService { private ClientModifySupport clientModifySupport; @Resource private ClearingLogMapper clearingLogMapper; + @Resource + private CustomerServiceService customerServiceService; private Map senderMap = new HashMap<>(); private final String fileName[] = { "client_bank_file", "client_id_file", "client_company_file" }; @@ -410,6 +413,12 @@ public class RetailAppServiceImp implements RetailAppService { return result; } + @Override + public void openimCheck(JSONObject device) { + JSONObject account = clientAccountMapper.findById(device.getString("account_id")); + customerServiceService.checkAndSave(account); + } + @Override public void updateClient(JSONObject device, AppClientBean appClientBean) { String clientType = device.getString("client_type"); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 9caa888d2..e22449561 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -1,34 +1,5 @@ package au.com.royalpay.payment.manage.appclient.web; -import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE; - -import java.math.BigDecimal; -import java.text.ParseException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; - -import org.apache.commons.lang3.time.DateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; - import au.com.royalpay.payment.core.exceptions.ParamInvalidException; import au.com.royalpay.payment.manage.activities.app_index.core.AppActService; import au.com.royalpay.payment.manage.activities.monsettledelay.core.ActMonDelaySettleService; @@ -55,6 +26,35 @@ import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; import au.com.royalpay.payment.tools.merchants.beans.UpdateSurchargeDTO; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import org.apache.commons.lang3.time.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE; + /** * Created by yishuqian on 28/03/2017. */ @@ -540,4 +540,9 @@ public class RetailAppController { return attachmentClient.uploadFile(file,false); } + @RequestMapping(value = "/openim/check",method = RequestMethod.POST) + public void openimCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device) { + retailAppService.openimCheck(device); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java new file mode 100644 index 000000000..16fc11adf --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java @@ -0,0 +1,26 @@ +package au.com.royalpay.payment.manage.mappers.openim; + +import com.alibaba.fastjson.JSONObject; + +import org.apache.ibatis.annotations.Param; + +import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; +import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; +import cn.yixblog.support.mybatis.autosql.annotations.SqlType; + +/** + * Created by yixian on 2016-10-27. + */ +@AutoMapper(tablename = "sys_openim", pkName = "id") +public interface OpenimMapper { + @AutoSql(type = SqlType.SELECT) + JSONObject findOne(@Param("user_id") String user_id); + @AutoSql(type = SqlType.SELECT) + JSONObject findByAccountId(@Param("account_id") String account_id,@Param("account_type") String account_type); + + @AutoSql(type = SqlType.UPDATE) + void update(JSONObject member); + + @AutoSql(type = SqlType.INSERT) + void save(JSONObject member); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java b/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java new file mode 100644 index 000000000..ae3331c78 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java @@ -0,0 +1,34 @@ +package au.com.royalpay.payment.manage.openim; + +import au.com.royalpay.payment.manage.openim.core.CustomerServiceService; +import au.com.royalpay.payment.manage.permission.manager.RequireManager; +import au.com.royalpay.payment.tools.CommonConsts; + +import com.alibaba.fastjson.JSONObject; + +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/7/11 + */ +@RestController +@RequestMapping("/sys/openim") +public class OpenimController { + + @Resource + private CustomerServiceService customerServiceService; + + + @RequestMapping(value = "/check",method = RequestMethod.POST) + @RequireManager + public void sendMsg(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + customerServiceService.checkAndSave(manager); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java new file mode 100644 index 000000000..ef6dd0c88 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java @@ -0,0 +1,12 @@ +package au.com.royalpay.payment.manage.openim.core; + +import com.alibaba.fastjson.JSONObject; + +/** + * @author kira + * @date 2018/7/11 + */ +public interface CustomerServiceService { + + void checkAndSave(JSONObject account); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java index 3f01c1a35..fb380b84f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java @@ -1,8 +1,20 @@ package au.com.royalpay.payment.manage.openim.core; +import com.alibaba.fastjson.JSONObject; + /** * @author kira * @date 2018/7/11 */ public interface OpenimApi { + + void addUser(JSONObject record); + + void updateUser(); + + void pushMsh(); + + JSONObject getUserInfo(String userId); + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index 03677f43a..d1a126eef 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -6,12 +6,15 @@ import com.alibaba.fastjson.JSONObject; import com.taobao.api.ApiException; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; +import com.taobao.api.domain.OpenImUser; import com.taobao.api.domain.Userinfos; import com.taobao.api.request.OpenimCustmsgPushRequest; +import com.taobao.api.request.OpenimRelationsGetRequest; import com.taobao.api.request.OpenimUsersAddRequest; import com.taobao.api.request.OpenimUsersGetRequest; import com.taobao.api.request.OpenimUsersUpdateRequest; import com.taobao.api.response.OpenimCustmsgPushResponse; +import com.taobao.api.response.OpenimRelationsGetResponse; import com.taobao.api.response.OpenimUsersAddResponse; import com.taobao.api.response.OpenimUsersGetResponse; import com.taobao.api.response.OpenimUsersUpdateResponse; @@ -29,14 +32,16 @@ import java.util.List; @Service public class OpenimClient { Logger logger = LoggerFactory.getLogger(getClass()); - private final String appkey = "24960261"; - private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; +// private final String appkey = "24960261"; +// private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; + private final String appkey = "24962653"; + private final String secret = "1c1a1320c4e6f24df24e3fe41c3fc00a"; private final String url = "https://eco.taobao.com/router/rest"; - public JSONObject getUser(String userId){ + public JSONObject getUser(String userId) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersGetRequest req = new OpenimUsersGetRequest(); - // 批量为userid逗号分隔字符串 + // 批量为userid逗号分隔字符串 req.setUserids(userId); OpenimUsersGetResponse rsp = null; try { @@ -47,8 +52,6 @@ public class OpenimClient { return JSONObject.parseObject(rsp.getBody()); } - - public void addUser(List users) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); @@ -59,9 +62,10 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim add user fail", e); } - JSONObject result =JSONObject.parseObject(rsp.getBody()); - if(result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").size()>1){ - logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if (result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").size() > 0) { + logger.info("openim add user fail reason:" + + result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); throw new ServerErrorException("System error"); } } @@ -76,14 +80,15 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim update user fail", e); } - JSONObject result = JSONObject.parseObject(rsp.getBody()); - if(result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").size()>1){ - logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if (result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").size() > 0) { + logger.info("openim update user fail reason:" + + result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); throw new ServerErrorException("System error"); } } - public JSONObject pushMsg(OpenimCustmsgPushRequest.CustMsg msg){ + public void pushMsg(OpenimCustmsgPushRequest.CustMsg msg) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimCustmsgPushRequest req = new OpenimCustmsgPushRequest(); req.setCustmsg(msg); @@ -93,55 +98,33 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim push msg fail", e); } - return JSONObject.parseObject(rsp.getBody()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if (result.getJSONObject("openim_custmsg_push_response").getJSONObject("fail_msg").size() > 0) { + logger.info("openim push message fail reason:" + + result.getJSONObject("openim_custmsg_push_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + throw new ServerErrorException("System error"); + } } -// public JSONObject test(){ -// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); -// OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); -// List list2 = new ArrayList(); -// Userinfos obj3 = new Userinfos(); -// list2.add(obj3); -// obj3.setNick("king"); -// obj3.setIconUrl("http://xxx.com/xxx"); -// obj3.setEmail("uid@taobao.com"); -// obj3.setMobile("18600000000"); -// obj3.setTaobaoid("tbnick123"); -// obj3.setUserid("imuserkcbknefe123"); -// obj3.setPassword("xxxxxx"); -// obj3.setRemark("demo"); -// obj3.setExtra("{}"); -// obj3.setCareer("demo"); -// obj3.setVip("{}"); -// obj3.setAddress("demo"); -// obj3.setName("demo"); -// obj3.setAge(123L); -// obj3.setGender("M"); -// obj3.setWechat("demo"); -// obj3.setQq("demo"); -// obj3.setWeibo("demo"); -// req.setUserinfos(list2); -// OpenimUsersUpdateResponse rsp = null; -// try { -// rsp = client.execute(req); -// } catch (ApiException e) { -// e.printStackTrace(); -// } -// System.out.println(rsp.getBody()); -// return JSONObject.parseObject(rsp.getBody()); -// -// } -// public static void main(String[] args) { -// OpenimClient asd = new OpenimClient(); -// JSONObject zxc = asd.test(); -// System.out.println(zxc); -// System.out.println(zxc); -// System.out.println(zxc); -// JSONObject qwe = JSONObject.parseObject("{\"openim_users_add_response\":{\"uid_fail\":{\"string\":[\"imuser123asdasdasd\"]},\"uid_succ\":{},\"fail_msg\":{\"string\":[\"data exist\"]}}}"); -// -// System.out.println(qwe.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); -// System.out.println(qwe); -// System.out.println(qwe); -// } + public static void main(String[] args) { + String appkey = "24960261"; + String secret = "7639427973bd671be15c9d0c1e9c90b4"; + String url = "https://eco.taobao.com/router/rest"; + TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); + OpenimRelationsGetRequest req = new OpenimRelationsGetRequest(); + req.setBegDate("20180701"); + req.setEndDate("20180711"); + OpenImUser obj1 = new OpenImUser(); + obj1.setUid("imuser123"); + obj1.setTaobaoAccount(false); + req.setUser(obj1); + OpenimRelationsGetResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + e.printStackTrace(); + } + System.out.println(rsp.getBody()); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java new file mode 100644 index 000000000..2179dc562 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java @@ -0,0 +1,53 @@ +package au.com.royalpay.payment.manage.openim.core.impl; + +import au.com.royalpay.payment.manage.mappers.openim.OpenimMapper; +import au.com.royalpay.payment.manage.openim.core.CustomerServiceService; +import au.com.royalpay.payment.manage.openim.core.OpenimApi; + +import com.alibaba.fastjson.JSONObject; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/7/11 + */ +@Service +public class CustomerServiceServiceImpl implements CustomerServiceService { + + @Resource + private OpenimMapper openimMapper; + @Resource + private OpenimApi openimApi; + + + @Override + public void checkAndSave(JSONObject account) { + boolean isPartner = true; + if (StringUtils.isNotEmpty(account.getString("account_id"))) { + isPartner = true; + } + if (StringUtils.isNotEmpty(account.getString("manager_id"))) { + isPartner = false; + } + String uid = account.getString("username")+ (isPartner ? "_partner": "_manager"); + JSONObject record = openimMapper.findOne(uid); + if(record==null){ + JSONObject saveRecord = new JSONObject(); + saveRecord.put("nick",account.getString("display_name")); + if(isPartner){ + saveRecord.put("user_id",account.getString("username")+"_partner"); + saveRecord.put("account_type","partner"); + saveRecord.put("account_id",account.getString("account_id")); + }else { + saveRecord.put("user_id",account.getString("username")+"_manager"); + saveRecord.put("account_type","manager"); + saveRecord.put("account_id",account.getString("manager_id")); + } + openimApi.addUser(saveRecord); + } + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java index fdfdf014b..8e97ed004 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java @@ -1,10 +1,64 @@ package au.com.royalpay.payment.manage.openim.core.impl; +import au.com.royalpay.payment.manage.mappers.openim.OpenimMapper; import au.com.royalpay.payment.manage.openim.core.OpenimApi; +import au.com.royalpay.payment.manage.openim.core.OpenimClient; +import au.com.royalpay.payment.tools.utils.id.IdUtil; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.api.domain.Userinfos; + +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; /** * @author kira * @date 2018/7/11 */ +@Service public class OpenimApiImpl implements OpenimApi { + + @Resource + private OpenimClient openimClient; + @Resource + private OpenimMapper openimMapper; + + @Override + public void addUser(JSONObject user) { + List saveList = new ArrayList<>(); + Userinfos record = new Userinfos(); + record.setUserid(user.getString("user_id")); + record.setNick(user.getString("nick")); + record.setPassword("XXXXXX"); + saveList.add(record); + openimClient.addUser(saveList); + + JSONObject openim = new JSONObject(); + openim.put("id", IdUtil.getId()); + openim.put("user_id", record.getUserid()); + openim.put("password_aes", record.getPassword()); + openim.put("account_id", user.getString("account_id")); + openim.put("account_type", user.getString("account_type")); + openimMapper.save(openim); + + } + + @Override + public void updateUser() { + + } + + @Override + public void pushMsh() { + + } + + @Override + public JSONObject getUserInfo(String userId) { + return openimClient.getUser(userId); + } } diff --git a/src/main/resources/templates/customer_service.html b/src/main/resources/templates/customer_service.html new file mode 100644 index 000000000..6a28a917e --- /dev/null +++ b/src/main/resources/templates/customer_service.html @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/src/main/ui/manage.html b/src/main/ui/manage.html index a5e3f5bdb..b7e61091f 100644 --- a/src/main/ui/manage.html +++ b/src/main/ui/manage.html @@ -307,13 +307,13 @@ margin-bottom: 10%;"/> -