165 lines
6.1 KiB
Java
165 lines
6.1 KiB
Java
package com.bocloud.sms.service;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.bocloud.sms.entity.User;
|
|
import com.bocloud.sms.enums.WarnInfo;
|
|
import com.bocloud.sms.enums.YkInfo;
|
|
import com.bocloud.sms.interfaces.IndexService;
|
|
import com.bocloud.sms.repository.UserRepository;
|
|
import com.bocloud.sms.utils.WarnUtil;
|
|
import com.bocloud.sms.utils.YkUtil;
|
|
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;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Service("IndexService")
|
|
@Slf4j
|
|
public class IndexServiceImpl implements IndexService {
|
|
|
|
@Autowired
|
|
private YkUtil ykUtil;
|
|
@Autowired
|
|
private UserRepository userRepository;
|
|
@Autowired
|
|
private WarnUtil warnUtil;
|
|
|
|
@Override
|
|
public GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext) {
|
|
try {
|
|
JSONObject param = new JSONObject();
|
|
User user = userRepository.query(requestContext.getTarget());
|
|
param.put("userId", "1111");
|
|
param.put("page", pager.getPage());
|
|
param.put("limit", pager.getRows());
|
|
String result = ykUtil.call(YkInfo.getTaskList, param, JSONArray.class);
|
|
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 {
|
|
|
|
JSONObject jsonObject = getTaskList(requestContext);
|
|
Integer total = jsonObject.getInteger("total");
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
resultMap.put("orderTotal", total);
|
|
|
|
List<JSONObject> data = JSONObject.parseObject(jsonObject.getString("data"), List.class);
|
|
Integer waitDoneTotal = 0;
|
|
Integer doneTotal = 0;
|
|
for (JSONObject obj : data) {
|
|
if ("0".equals(obj.getString("approve_status"))) {
|
|
waitDoneTotal++;
|
|
} else {
|
|
doneTotal++;
|
|
}
|
|
}
|
|
|
|
resultMap.put("waitDoneTotal", waitDoneTotal);
|
|
resultMap.put("doneTotal", doneTotal);
|
|
|
|
return new GeneralResult(true, resultMap, "查询成功");
|
|
} catch (Exception e) {
|
|
log.info("查询失败", e);
|
|
return new GeneralResult(false, "查询失败");
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public GeneralResult userDataStatic(RequestContext requestContext) {
|
|
try {
|
|
//获取用户数据权限申请数量
|
|
JSONObject userParam = new JSONObject();
|
|
userParam.put("userId", "1111");
|
|
String data = ykUtil.call(YkInfo.getCountTaskByUser, userParam, JSONArray.class);
|
|
List<JSONObject> list = JSONObject.parseObject(data, List.class);
|
|
|
|
|
|
return new GeneralResult(true, list, "查询成功");
|
|
} catch (Exception e) {
|
|
log.info("查询失败", e);
|
|
return new GeneralResult(false, "查询失败");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public GeneralResult userAppList(RequestContext requestContext) {
|
|
|
|
try {
|
|
//获取所有的appList
|
|
//查询当前用户授权应用
|
|
JSONObject param = new JSONObject();
|
|
param.put("type", "user");
|
|
param.put("page", 1);
|
|
param.put("limit", Integer.MAX_VALUE);
|
|
String result = ykUtil.call(YkInfo.getAllAppList, param, JSONArray.class);
|
|
JSONObject allAppJson = JSONObject.parseObject(result, JSONObject.class);
|
|
List<JSONObject> allAppList = JSONObject.parseObject(allAppJson.getString("list"), List.class);
|
|
|
|
List<JSONObject> userAppList = getUserAppList(requestContext);
|
|
List<String> appIdList = userAppList.stream().map(jsonObject -> jsonObject.getString("appId")).collect(Collectors.toList());
|
|
for (JSONObject data : allAppList) {
|
|
if (appIdList.contains(data.getString("appId"))) {
|
|
data.put("enable", "1");
|
|
} else {
|
|
|
|
data.put("enable", "0");
|
|
}
|
|
}
|
|
return new GeneralResult(true, allAppList, "查询成功");
|
|
} catch (Exception e) {
|
|
log.info("查询失败", e);
|
|
return new GeneralResult(false, "查询失败");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public GeneralResult sevenDayWarnTrend(RequestContext requestContext) {
|
|
|
|
try {
|
|
String result = warnUtil.call(WarnInfo.get7DayWarnTrend.getUrl(), "GET");
|
|
log.info("result:"+result);
|
|
return new GeneralResult(true, "查询成功");
|
|
} 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);
|
|
}
|
|
}
|