|
@@ -0,0 +1,105 @@
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.manage.common.DictUtil;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.entity.SysUser;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.httpClient.client.OpenApiClient;
|
|
|
+import com.fdkankan.manage.httpClient.param.OpenApiAddParam;
|
|
|
+import com.fdkankan.manage.httpClient.param.OpenApiPageParam;
|
|
|
+import com.fdkankan.manage.httpClient.param.OpenApiUpdateParam;
|
|
|
+import com.fdkankan.manage.httpClient.vo.FdkkResponse;
|
|
|
+import com.fdkankan.manage.service.ISysUserService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class OpenApiService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OpenApiClient openApiClient;
|
|
|
+ @Autowired
|
|
|
+ ISysUserService sysUserService;
|
|
|
+
|
|
|
+
|
|
|
+ public Object pageList(OpenApiPageParam param){
|
|
|
+ try {
|
|
|
+ List<SysUser> sysUserList = sysUserService.list();
|
|
|
+ HashMap<Long,SysUser> map = new HashMap<>();
|
|
|
+ sysUserList.forEach( e -> map.put(e.getId(),e));
|
|
|
+
|
|
|
+ FdkkResponse response = openApiClient.page(param);
|
|
|
+ if(response.getCode() == 0 && response.getData() != null){
|
|
|
+ JSONObject data = response.getData();
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
+ for (Object object : list) {
|
|
|
+ JSONObject jsonObject = (JSONObject) object;
|
|
|
+ Integer useType = jsonObject.getInteger("useType");
|
|
|
+ if(useType != null){
|
|
|
+ jsonObject.put("useTypeStr",DictUtil.toStringUseType(useType));
|
|
|
+ }
|
|
|
+ Integer customerType = jsonObject.getInteger("customerType");
|
|
|
+ if(customerType != null){
|
|
|
+ jsonObject.put("customerTypeStr",DictUtil.toStringCustomerType(customerType));
|
|
|
+ }
|
|
|
+ Long createrId = jsonObject.getLong("createrId");
|
|
|
+ if(createrId != null){
|
|
|
+ SysUser sysUser = map.get(createrId);
|
|
|
+ jsonObject.put("createrName",sysUser != null ?sysUser.getNickName():"");
|
|
|
+ }
|
|
|
+ Long updaterId = jsonObject.getLong("updaterId");
|
|
|
+ if(updaterId != null){
|
|
|
+ SysUser sysUser = map.get(updaterId);
|
|
|
+ jsonObject.put("updaterName",sysUser != null ?sysUser.getNickName():"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("访问openApi接口出错:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.VISIT_OPENAPI_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object add(OpenApiAddParam param){
|
|
|
+ try {
|
|
|
+ param.setUpdaterId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ param.setCreaterId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ FdkkResponse response = openApiClient.add(param);
|
|
|
+ return response;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("访问openApi接口出错:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.VISIT_OPENAPI_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object updateStatus(OpenApiUpdateParam param){
|
|
|
+ try {
|
|
|
+ param.setUpdaterId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ FdkkResponse response = openApiClient.updateStatus(param);
|
|
|
+ return response;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("访问openApi接口出错:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.VISIT_OPENAPI_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object delete(OpenApiUpdateParam param){
|
|
|
+ try {
|
|
|
+ param.setUpdaterId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ FdkkResponse response = openApiClient.delete(param);
|
|
|
+ return response;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("访问openApi接口出错:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.VISIT_OPENAPI_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|