Explorar el Código

add:纷享销客接口对接

caozixuan hace 1 año
padre
commit
233a6bdc68

+ 66 - 0
sop-api/src/main/java/com/qmth/sop/server/api/FxxkAsyncController.java

@@ -0,0 +1,66 @@
+package com.qmth.sop.server.api;
+
+import com.qmth.boot.api.annotation.Aac;
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.sync.FxxkApiUtils;
+import com.qmth.sop.business.sync.been.FxxkAppAuthInfo;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+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.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * @Description: 分享逍客同步控制器
+ * @Author: CaoZixuan
+ * @Date: 2023-10-28
+ */
+@Api(tags = "纷享销客数据同步 Controller")
+@RestController
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_FXXK)
+public class FxxkAsyncController {
+    @Resource
+    FxxkApiUtils fxxkApiUtils;
+
+    @ApiOperation(value = "纷享销客数据推送接口(接收)")
+    @ApiResponses({@ApiResponse(code = 200, message = "数据推送接口", response = Object.class)})
+    @RequestMapping(value = "/data/push", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
+    @Aac(auth = false)
+    public Result crmCallBack(@RequestBody String arg) {
+        System.out.println(arg);
+        return ResultUtil.ok();
+    }
+
+    @ApiOperation(value = "纷享销客-获取应用级授权信息")
+    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = FxxkAppAuthInfo.class)})
+    @RequestMapping(value = "/app/auth/info", method = RequestMethod.POST)
+    @Aac(auth = false)
+    public Result findFxxkAppAuthInfo() {
+        return ResultUtil.ok(fxxkApiUtils.findFxxkAppAuthInfo());
+    }
+
+    @ApiOperation(value = "纷享销客-根据手机号获取openUserId")
+    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = String.class)})
+    @RequestMapping(value = "/find/open_user_id", method = RequestMethod.POST)
+    @Aac(auth = false)
+    public Result findCurrentOpenUserId() {
+        return ResultUtil.ok(fxxkApiUtils.findCurrentOpenUserId());
+    }
+
+    @ApiOperation(value = "纷享销客-查询自定义对象列表")
+    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = Result.class)})
+    @RequestMapping(value = "/find/custom_list", method = RequestMethod.POST)
+    @Aac(auth = false)
+    public Result findCustomList() {
+        fxxkApiUtils.findCustomList();
+        return ResultUtil.ok();
+    }
+}

+ 2 - 2
sop-business/src/main/java/com/qmth/sop/business/sync/FaceApiUtils.java

@@ -8,7 +8,7 @@ import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.ExceptionResultEnum;
 import com.qmth.sop.common.util.FileUtil;
 import com.qmth.sop.common.util.HttpUtil;
-import org.springframework.stereotype.Service;
+import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.File;
@@ -23,7 +23,7 @@ import java.util.List;
  * @Author: CaoZixuan
  * @Date: 2023-09-14
  */
-@Service
+@Component
 public class FaceApiUtils {
     @Resource
     private SysConfigService sysConfigService;

+ 186 - 0
sop-business/src/main/java/com/qmth/sop/business/sync/FxxkApiUtils.java

@@ -0,0 +1,186 @@
+package com.qmth.sop.business.sync;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.sop.business.service.SysConfigService;
+import com.qmth.sop.business.sync.been.FxxkAppAuthInfo;
+import com.qmth.sop.business.sync.been.FxxkAppAuthResult;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.util.HttpUtil;
+import com.qmth.sop.common.util.JacksonUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * @Description: 纷享销客开放接口工具类
+ * @Author: CaoZixuan
+ * @Date: 2023-10-10
+ */
+@Component
+public class FxxkApiUtils {
+    @Resource
+    private SysConfigService sysConfigService;
+
+    private static final Logger log = LoggerFactory.getLogger(FxxkApiUtils.class);
+
+    /**
+     * 查询纷享销客应用级授权
+     *
+     * @return 应用级授权信息
+     */
+    public FxxkAppAuthInfo findFxxkAppAuthInfo() {
+        String appId = sysConfigService.findByConfigKey(SystemConstant.FXXK_APP_ID).getConfigValue();
+        String appSecret = sysConfigService.findByConfigKey(SystemConstant.FXXK_APP_SECRET).getConfigValue();
+        String permanentCode = sysConfigService.findByConfigKey(SystemConstant.FXXK_PERMANENT_CODE).getConfigValue();
+        String postUrl = sysConfigService.findByConfigKey(SystemConstant.FXXK_APP_AUTH_URL).getConfigValue();
+        try {
+            Map<String, Object> map = new HashMap<>();
+            map.put("appId", validParam(appId, null, true, "纷享销客AppID"));
+            map.put("appSecret", validParam(appSecret, null, true, "纷享销客APPSecret"));
+            map.put("permanentCode", validParam(permanentCode, null, true, "纷享销客永久授权码"));
+            String requestJson = JacksonUtil.parseJson(map);
+
+            String result = HttpUtil.postJson(postUrl, requestJson, null, null, false);
+            FxxkAppAuthResult fxxkAppAuthResult = JSONObject.parseObject(result, FxxkAppAuthResult.class);
+            if (Objects.isNull(fxxkAppAuthResult) || fxxkAppAuthResult.getErrorCode() != 0) {
+                throw ExceptionResultEnum.ERROR.exception("获取纷享销客应用级授权信息失败 : " + fxxkAppAuthResult.getErrorMessage());
+            }
+            FxxkAppAuthInfo fxxkAppAuthInfo = new FxxkAppAuthInfo();
+            fxxkAppAuthInfo.setCorpId(fxxkAppAuthResult.getCorpId());
+            fxxkAppAuthInfo.setCorpAccessToken(fxxkAppAuthResult.getCorpAccessToken());
+            fxxkAppAuthInfo.setExpiresIn(fxxkAppAuthResult.getExpiresIn());
+            return fxxkAppAuthInfo;
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
+
+    /**
+     * 获取当前登录人openUserId
+     *
+     * @return currentOpenUserId
+     */
+    public String findCurrentOpenUserId() {
+        final String mobile = "18903719928";
+        String postUrl = sysConfigService.findByConfigKey(SystemConstant.FXXK_USER_BY_MOBILE_URL).getConfigValue();
+
+        try {
+            FxxkAppAuthInfo fxxkAppAuthInfo = this.findFxxkAppAuthInfo();
+            String corpAccessToken = fxxkAppAuthInfo.getCorpAccessToken();
+            String corpId = fxxkAppAuthInfo.getCorpId();
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("corpAccessToken", validParam(corpAccessToken, null, true, "企业应用访问公司合法性凭证"));
+            map.put("corpId", validParam(corpId, null, true, "开放平台公司帐号"));
+            map.put("mobile", validParam(mobile, null, true, "员工手机号"));
+            String requestJson = JacksonUtil.parseJson(map);
+
+            String result = HttpUtil.postJson(postUrl, requestJson, null, null, false);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            Long errorCode = jsonObject.getLong("errorCode");
+            String errorMessage = jsonObject.getString("errorMessage");
+            if (errorCode != 0) {
+                throw ExceptionResultEnum.ERROR.exception("获取员工信息失败 : " + errorMessage);
+            }
+            JSONArray empList = jsonObject.getJSONArray("empList");
+            JSONObject emp = empList.getJSONObject(0);
+            return emp.getString("openUserId");
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
+
+    /**
+     * 查询自定义对象列表
+     */
+    public void findCustomList() {
+        String currentOpenUserId = sysConfigService.findByConfigKey(SystemConstant.FXXK_CURRENT_OPEN_USER_ID).getConfigValue();
+        String postUrl = sysConfigService.findByConfigKey(SystemConstant.FXXK_CUSTOM_QUERY_URL).getConfigValue();
+        try {
+            FxxkAppAuthInfo fxxkAppAuthInfo = this.findFxxkAppAuthInfo();
+            String corpAccessToken = fxxkAppAuthInfo.getCorpAccessToken();
+            String corpId = fxxkAppAuthInfo.getCorpId();
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("corpAccessToken", validParam(corpAccessToken, null, true, "企业应用访问公司合法性凭证"));
+            map.put("corpId", validParam(corpId, null, true, "开放平台公司帐号"));
+            map.put("currentOpenUserId", validParam(currentOpenUserId, null, true, "当前操作人OpenUserID"));
+
+            Map<String, Object> dataMap = new HashMap<>();
+            dataMap.put("dataObjectApiName", sysConfigService.findByConfigKey(SystemConstant.FXXK_API_NAME_CRM).getConfigValue());
+
+            Map<String, Object> queryMap = new HashMap<>();
+            queryMap.put("offset", 0.0);
+            queryMap.put("limit", 2.0);
+            queryMap.put("filters", new ArrayList<>());
+
+            dataMap.put("search_query_info", queryMap);
+            map.put("data", dataMap);
+
+            String requestJson = JacksonUtil.parseJson(map);
+
+            String result = HttpUtil.postJson(postUrl, requestJson, null, null, false);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            Long errorCode = jsonObject.getLong("errorCode");
+            String errorMessage = jsonObject.getString("errorMessage");
+            if (errorCode != 0) {
+                throw ExceptionResultEnum.ERROR.exception("获取自定义对象列表失败 : " + errorMessage);
+            }
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
+
+
+    /**
+     * 校验参数值并返回(字符型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填(true:是,false:否)
+     * @param name         参数名称
+     */
+    private String validParam(String value, String defaultValue, boolean require, String name) {
+        if (require && StringUtils.isAllBlank(value, defaultValue)) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return StringUtils.isBlank(value) ? defaultValue : value;
+
+    }
+
+    /**
+     * 校验参数值并返回(Long型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填(true:是,false:否)
+     * @param name         参数名称
+     */
+    private Long validParam(Long value, Long defaultValue, boolean require, String name) {
+        if (require && Objects.isNull(value) && Objects.isNull(defaultValue)) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return Objects.isNull(value) ? defaultValue : value;
+    }
+
+    /**
+     * 校验参数值并返回 (布尔型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填
+     * @param name         描述
+     */
+    private Boolean validParam(Boolean value, Boolean defaultValue, Boolean require, String name) {
+        if (require && value == null && defaultValue == null) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return value == null ? defaultValue : value;
+    }
+}

+ 44 - 0
sop-business/src/main/java/com/qmth/sop/business/sync/been/FxxkAppAuthInfo.java

@@ -0,0 +1,44 @@
+package com.qmth.sop.business.sync.been;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 纷享销客应用级授权信息
+ * @Author: CaoZixuan
+ * @Date: 2023-10-10
+ */
+public class FxxkAppAuthInfo {
+    @ApiModelProperty("企业应用访问公司合法性凭证")
+    private String corpAccessToken;
+
+    @ApiModelProperty("开放平台派发的公司帐号")
+    private String corpId;
+
+    // 企业应用访问公司合法性凭证的过期时间,单位为秒,取值在0~7200之间,在过期时间在0-6600之间请求该接口会返回相同的corpAccessToken,在6600-7200之间请求该接口会返回新的token,如果要续期token,则需要在该时刻进行请求。
+    @ApiModelProperty("过期时间")
+    private Long expiresIn;
+
+    public String getCorpAccessToken() {
+        return corpAccessToken;
+    }
+
+    public void setCorpAccessToken(String corpAccessToken) {
+        this.corpAccessToken = corpAccessToken;
+    }
+
+    public String getCorpId() {
+        return corpId;
+    }
+
+    public void setCorpId(String corpId) {
+        this.corpId = corpId;
+    }
+
+    public Long getExpiresIn() {
+        return expiresIn;
+    }
+
+    public void setExpiresIn(Long expiresIn) {
+        this.expiresIn = expiresIn;
+    }
+}

+ 32 - 0
sop-business/src/main/java/com/qmth/sop/business/sync/been/FxxkAppAuthResult.java

@@ -0,0 +1,32 @@
+package com.qmth.sop.business.sync.been;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 纷享销客应用级授权信息查询结果
+ * @Author: CaoZixuan
+ * @Date: 2023-10-10
+ */
+public class FxxkAppAuthResult extends FxxkAppAuthInfo{
+    @ApiModelProperty("返回码")
+    private Long errorCode;
+
+    @ApiModelProperty("对返回码的文本描述内容")
+    private String errorMessage;
+
+    public Long getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(Long errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+}

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/sync/been/FxxkCustomQuery.java

@@ -0,0 +1,12 @@
+package com.qmth.sop.business.sync.been;
+
+/**
+ * @Description: 纷享销客自定义对象查询条件构造器
+ * @Author: CaoZixuan
+ * @Date: 2023-10-10
+ */
+public class FxxkCustomQuery {
+    private Integer limit;
+    private Integer offer;
+
+}

+ 11 - 0
sop-business/src/main/resources/db/log/caozixuan_update_log.sql

@@ -330,3 +330,14 @@ ALTER TABLE t_b_user_archives
 
 INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('2051', '人员档案管理-作废', '/api/admin/user/archives/cancel', 'URL', '33', '7', 'AUTH', '1', '1', '0');
 UPDATE sys_privilege SET related = '2051' WHERE (id = '159');
+
+-- 2023-10-10
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('39', 'fxxk.app.id', '纷享销客AppID', 'FSAID_131c93b', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('40', 'fxxk.app.secrete', '纷享销客APPSecret', '5d590b10cca24ce5a51fc716564aac9f', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('41', 'fxxk.permanent.code', '纷享销客永久授权码', '4EFBD3FCF655B4D934C163EA5ECE638D', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('42', 'fxxk.curren.open.user.id', '纷享销客当前操作人OpenUserID', 'FSUID_AE9192D544DCF7924E88E9EA800641C7', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('43', 'fxxk.api.name.crm', '纷享销客项目派单apiName', 'object_zS8me__c', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('44', 'fxxk.api.name.crm.detail', '纷享销客项目派单明细apiName', 'object_bs553__c', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('45', 'fxxk.app.auth.url', '纷享销客应用级授权接口', 'https://open.fxiaoke.com/cgi/corpAccessToken/get/V2', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('46', 'fxxk.user.by.mobile.url', '纷享销客根据手机号查询员工接口', 'https://open.fxiaoke.com/cgi/user/getByMobile', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('47', 'fxxk.custom.query.url', '纷享销客查询自定义对象接口', 'https://openfxiaokecom/cgi/crm/custom/v2/data/query', '1', '1', '1');

+ 10 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -205,6 +205,16 @@ public class SystemConstant {
     public static final String FACE_VERIFY_BAIDU_LOCAL_URL_PREFIX = "face.verify.baiduLocalUrlPrefix";
     public static final String BAIDU_FACE_COMPARE_URL = "baidu.face.compare.url";
     public static final String BAIDU_FACE_COMPARE_SCORE = "baidu.face.compare.score";
+    public static final String FXXK_APP_ID = "fxxk.app.id";
+    public static final String FXXK_APP_SECRET = "fxxk.app.secret";
+    public static final String FXXK_PERMANENT_CODE = "fxxk.permanent.code";
+    public static final String FXXK_CURRENT_OPEN_USER_ID = "fxxk.curren.open.user.id";
+    public static final String FXXK_API_NAME_CRM = "fxxk.api.name.crm";
+    public static final String FXXK_API_NAME_CRM_DETAIL = "fxxk.api.name.crm.detail";
+    public static final String FXXK_APP_AUTH_URL = "fxxk.app.auth.url";
+    public static final String FXXK_USER_BY_MOBILE_URL = "fxxk.user.by.mobile.url";
+    public static final String FXXK_CUSTOM_QUERY_URL = "fxxk.custom.query.url";
+
 
     /**
      * api前缀