package com.bocloud.sms.service; 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; 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; @Service("IndexService") @Slf4j public class IndexServiceImpl implements IndexService { @Autowired private YkUtil ykUtil; @Autowired private UserRepository userRepository; @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 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); Integer total = jsonObject.getInteger("total"); Map resultMap = new HashMap<>(); resultMap.put("orderTotal", total); List 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, "查询失败"); } } @Override public GeneralResult userDataStatic(RequestContext requestContext) { try { //查询当前用户授权应用 JSONObject param = new JSONObject(); param.put("userId", "1111"); param.put("type", "user"); String result = ykUtil.call(YkInfo.getUserAppList, param, JSONArray.class); //获取用户信息 JSONObject userParam = new JSONObject(); userParam.put("userId", "1111"); String userRolesStr = ykUtil.call(YkInfo.getUserRoles, userParam, JSONArray.class); return new GeneralResult(true, "查询成功"); } catch (Exception e) { log.info("查询失败", e); return new GeneralResult(false, "查询失败"); } } }