bocloud.sms/bocloud.sms.service/src/main/java/com/bocloud/sms/service/IndexServiceImpl.java

163 lines
6.3 KiB
Java
Raw Normal View History

2024-08-25 08:42:26 +00:00
package com.bocloud.sms.service;
2024-08-26 12:30:26 +00:00
import com.alibaba.fastjson.JSON;
2024-08-25 08:42:26 +00:00
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.sms.entity.User;
import com.bocloud.sms.enums.YkInfo;
import com.bocloud.sms.interfaces.IndexService;
import com.bocloud.sms.repository.UserRepository;
2024-08-26 02:00:17 +00:00
import com.bocloud.sms.utils.YkUtil;
2024-08-25 08:42:26 +00:00
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.Pager;
import com.megatron.common.model.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
2024-08-26 08:49:29 +00:00
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2024-08-26 12:07:53 +00:00
import java.util.stream.Collectors;
2024-08-26 08:49:29 +00:00
2024-08-25 08:42:26 +00:00
@Service("IndexService")
@Slf4j
public class IndexServiceImpl implements IndexService {
@Autowired
2024-08-26 02:00:17 +00:00
private YkUtil ykUtil;
2024-08-25 08:42:26 +00:00
@Autowired
private UserRepository userRepository;
@Override
public GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext) {
try {
JSONObject param = new JSONObject();
User user = userRepository.query(requestContext.getTarget());
2024-08-26 08:49:29 +00:00
param.put("userId", "1111");
param.put("page", pager.getPage());
param.put("limit", pager.getRows());
2024-08-26 02:00:17 +00:00
String result = ykUtil.call(YkInfo.getTaskList, param, JSONArray.class);
2024-08-26 08:49:29 +00:00
JSONObject jsonObject = JSONArray.parseObject(result, JSONObject.class);
return new GeneralResult(true, jsonObject, "查询成功");
} catch (Exception e) {
log.info("查询失败", e);
return new GeneralResult(false, "查询失败");
}
}
@Override
public GeneralResult workOrderStatic(RequestContext requestContext) {
try {
2024-08-25 08:42:26 +00:00
2024-08-26 12:14:42 +00:00
JSONObject jsonObject = getTaskList(requestContext);
2024-08-26 08:49:29 +00:00
Integer total = jsonObject.getInteger("total");
2024-08-26 09:04:37 +00:00
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("orderTotal", total);
2024-08-26 08:49:29 +00:00
List<JSONObject> data = JSONObject.parseObject(jsonObject.getString("data"), List.class);
Integer waitDoneTotal = 0;
Integer doneTotal = 0;
for (JSONObject obj : data) {
2024-08-26 09:04:37 +00:00
if ("0".equals(obj.getString("approve_status"))) {
2024-08-26 08:49:29 +00:00
waitDoneTotal++;
2024-08-26 09:04:37 +00:00
} else {
2024-08-26 08:49:29 +00:00
doneTotal++;
}
}
2024-08-26 09:04:37 +00:00
resultMap.put("waitDoneTotal", waitDoneTotal);
resultMap.put("doneTotal", doneTotal);
2024-08-26 08:49:29 +00:00
2024-08-26 09:04:37 +00:00
return new GeneralResult(true, resultMap, "查询成功");
} catch (Exception e) {
log.info("查询失败", e);
return new GeneralResult(false, "查询失败");
}
}
2024-08-26 12:14:42 +00:00
private JSONObject getTaskList(RequestContext requestContext) throws Exception {
JSONObject param = new JSONObject();
User user = userRepository.query(requestContext.getTarget());
param.put("userId", "1111");
param.put("page", 1);
param.put("limit", Integer.MAX_VALUE);
String result = ykUtil.call(YkInfo.getTaskList, param, JSONArray.class);
JSONObject jsonObject = JSONArray.parseObject(result, JSONObject.class);
return jsonObject;
}
2024-08-26 09:04:37 +00:00
@Override
public GeneralResult userDataStatic(RequestContext requestContext) {
try {
2024-08-26 11:25:16 +00:00
Map<String, Object> resultMap = new HashMap<>();
2024-08-26 09:04:37 +00:00
//查询当前用户授权应用
2024-08-26 11:25:16 +00:00
List<JSONObject> userAppList = getUserAppList(requestContext);
resultMap.put("userAppCount", userAppList.size());
2024-08-26 09:04:37 +00:00
2024-08-26 12:14:42 +00:00
//获取运维任务申请表
JSONObject taskJson = getTaskList(requestContext);
Integer total = taskJson.getInteger("total");
resultMap.put("taskCount", total);
//获取用户数据权限申请数量
2024-08-26 09:04:37 +00:00
JSONObject userParam = new JSONObject();
2024-08-26 09:31:45 +00:00
userParam.put("userId", "1111");
2024-08-26 12:19:25 +00:00
String userDataAuthStr = ykUtil.call(YkInfo.getUserDataAuth, userParam, JSONArray.class);
List<JSONObject> userDataJAuthJson = JSONObject.parseObject(userDataAuthStr, List.class);
List<JSONObject> authResList = JSONObject.parseObject(userDataJAuthJson.get(0).getString("authRes"),List.class);
2024-08-26 09:04:37 +00:00
2024-08-26 12:19:25 +00:00
resultMap.put("userAuthList", authResList.size());
2024-08-26 12:30:26 +00:00
log.info("resultMap:{}", JSON.toJSONString(resultMap));
2024-08-26 09:04:37 +00:00
2024-08-26 11:25:16 +00:00
return new GeneralResult(true, resultMap, "查询成功");
2024-08-25 08:42:26 +00:00
} catch (Exception e) {
2024-08-26 08:49:29 +00:00
log.info("查询失败", e);
2024-08-25 08:42:26 +00:00
return new GeneralResult(false, "查询失败");
}
}
2024-08-26 11:25:16 +00:00
@Override
public GeneralResult userAppList(RequestContext requestContext) {
try {
2024-08-26 12:04:38 +00:00
//获取所有的appList
//查询当前用户授权应用
JSONObject param = new JSONObject();
param.put("type", "user");
2024-08-26 12:07:53 +00:00
param.put("page", 1);
param.put("limit", Integer.MAX_VALUE);
2024-08-26 12:04:38 +00:00
String result = ykUtil.call(YkInfo.getAllAppList, param, JSONArray.class);
2024-08-26 12:10:42 +00:00
JSONObject allAppJson = JSONObject.parseObject(result, JSONObject.class);
List<JSONObject> allAppList = JSONObject.parseObject(allAppJson.getString("list"), List.class);
2024-08-26 11:25:16 +00:00
List<JSONObject> userAppList = getUserAppList(requestContext);
2024-08-26 12:07:53 +00:00
List<String> appIdList = userAppList.stream().map(jsonObject -> jsonObject.getString("appId")).collect(Collectors.toList());
2024-08-26 12:10:42 +00:00
for (JSONObject data : allAppList) {
2024-08-26 12:07:53 +00:00
if(appIdList.contains(data.getString("appId"))){
data.put("enable", "1");
2024-08-26 12:14:42 +00:00
}else{
data.put("enable", "0");
2024-08-26 12:07:53 +00:00
}
}
2024-08-26 12:10:42 +00:00
return new GeneralResult(true, allAppList, "查询成功");
2024-08-26 11:25:16 +00:00
} catch (Exception e) {
log.info("查询失败", e);
return new GeneralResult(false, "查询失败");
}
}
private List<JSONObject> getUserAppList(RequestContext requestContext) throws Exception {
//查询当前用户授权应用
JSONObject param = new JSONObject();
param.put("userId", "1111");
param.put("type", "user");
String result = ykUtil.call(YkInfo.getUserAppList, param, JSONArray.class);
return JSONObject.parseObject(result, List.class);
}
2024-08-25 08:42:26 +00:00
}