运控接口
							parent
							
								
									c9409b33cd
								
							
						
					
					
						commit
						4debf2a8a1
					
				| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.booter.controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.bocloud.sms.entity.Department;
 | 
				
			||||||
 | 
					import com.bocloud.sms.interfaces.IndexService;
 | 
				
			||||||
 | 
					import com.megatron.common.model.GeneralResult;
 | 
				
			||||||
 | 
					import com.megatron.common.model.Pager;
 | 
				
			||||||
 | 
					import com.megatron.common.model.RequestContext;
 | 
				
			||||||
 | 
					import com.megatron.common.utils.Common;
 | 
				
			||||||
 | 
					import io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
 | 
					import io.swagger.v3.oas.annotations.tags.Tag;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Value;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.GetMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestParam;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RestController;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 首页
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author tyl
 | 
				
			||||||
 | 
					 * @since 2021/03/25
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@RestController
 | 
				
			||||||
 | 
					@RequestMapping("/v1/index")
 | 
				
			||||||
 | 
					@Tag(name = "首页")
 | 
				
			||||||
 | 
					public class IndexController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private IndexService indexService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @GetMapping("/doneWorkOrder")
 | 
				
			||||||
 | 
					    @Operation(summary = "待办工单列表")
 | 
				
			||||||
 | 
					    public GeneralResult list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext requestContext) {
 | 
				
			||||||
 | 
					        return indexService.doneWorkOrder(pager, requestContext);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.interfaces;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.bocloud.sms.entity.Department;
 | 
				
			||||||
 | 
					import com.megatron.common.model.GeneralResult;
 | 
				
			||||||
 | 
					import com.megatron.common.model.Pager;
 | 
				
			||||||
 | 
					import com.megatron.common.model.RequestContext;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface IndexService {
 | 
				
			||||||
 | 
					    GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,50 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONArray;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONObject;
 | 
				
			||||||
 | 
					import com.bocloud.cmp.boot.controller.IndexController;
 | 
				
			||||||
 | 
					import com.bocloud.sms.entity.Department;
 | 
				
			||||||
 | 
					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.YkUtils;
 | 
				
			||||||
 | 
					import com.megatron.common.model.GeneralResult;
 | 
				
			||||||
 | 
					import com.megatron.common.model.Pager;
 | 
				
			||||||
 | 
					import com.megatron.common.model.RequestContext;
 | 
				
			||||||
 | 
					import com.megatron.common.utils.MapTools;
 | 
				
			||||||
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Service("IndexService")
 | 
				
			||||||
 | 
					@Slf4j
 | 
				
			||||||
 | 
					public class IndexServiceImpl implements IndexService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private YkUtils ykUtils;
 | 
				
			||||||
 | 
					    @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",user.getUserId());
 | 
				
			||||||
 | 
					            param.put("page",pager.getPage());
 | 
				
			||||||
 | 
					            param.put("limit",pager.getRows());
 | 
				
			||||||
 | 
					            String result = ykUtils.call(YkInfo.getTaskList, param, JSONArray.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            log.info("result");
 | 
				
			||||||
 | 
					            JSONArray dataArray = JSONArray.parseArray(result);
 | 
				
			||||||
 | 
					            return new GeneralResult(true, dataArray,"查询成功");
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            log.info("查询失败");
 | 
				
			||||||
 | 
					            return new GeneralResult(false, "查询失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,20 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONObject;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					public class YkReqVo {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String reqUserId;
 | 
				
			||||||
 | 
					    private String systemId;
 | 
				
			||||||
 | 
					    private String method;
 | 
				
			||||||
 | 
					    private JSONObject params;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public YkReqVo(String reqUserId, String systemId, String method, JSONObject params) {
 | 
				
			||||||
 | 
					        this.reqUserId = reqUserId;
 | 
				
			||||||
 | 
					        this.systemId = systemId;
 | 
				
			||||||
 | 
					        this.method = method;
 | 
				
			||||||
 | 
					        this.params = params;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,22 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.enums;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum YkInfo {
 | 
				
			||||||
 | 
					    //查询用户信息
 | 
				
			||||||
 | 
					    queryAllUser("/system/user/queryAllUser"),
 | 
				
			||||||
 | 
					    //获取应用列表
 | 
				
			||||||
 | 
					    getAppList("/system/sysapp/getAppList"),
 | 
				
			||||||
 | 
					    //获取运维工单接口
 | 
				
			||||||
 | 
					    getTaskList("/activiti/rwMainTask/getTaskList"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    getTaskByUser("/system/task/countTaskByUser");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    YkInfo(String url) {
 | 
				
			||||||
 | 
					        this.url = url;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getUrl() {
 | 
				
			||||||
 | 
					        return url;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,47 @@
 | 
				
			||||||
 | 
					package com.bocloud.sms.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cn.hutool.http.HttpUtil;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONObject;
 | 
				
			||||||
 | 
					import com.bocloud.sms.entity.YkReqVo;
 | 
				
			||||||
 | 
					import com.bocloud.sms.enums.YkInfo;
 | 
				
			||||||
 | 
					import com.google.protobuf.ServiceException;
 | 
				
			||||||
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Value;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Component
 | 
				
			||||||
 | 
					@Slf4j
 | 
				
			||||||
 | 
					public class YkUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //参考application.yml配置文件
 | 
				
			||||||
 | 
					    @Value("${yk.url:http://36.111.150.83:9527/}")
 | 
				
			||||||
 | 
					    private String url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Value("${yk.reqUserId:1}")
 | 
				
			||||||
 | 
					    private String reqUserId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Value("${yk.systemId:1}")
 | 
				
			||||||
 | 
					    private String systemId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public <T>  T call(YkInfo inf, JSONObject params, Class expectCls) throws Exception {
 | 
				
			||||||
 | 
					        YkReqVo reqVo = new YkReqVo(reqUserId,systemId,inf.getUrl(),params);
 | 
				
			||||||
 | 
					        String str = JSONObject.toJSONString(reqVo);
 | 
				
			||||||
 | 
					        log.info("call yk url [{}]" , url);
 | 
				
			||||||
 | 
					        log.info("call yk method[{}] req params[{}]",reqVo.getMethod(),str);
 | 
				
			||||||
 | 
					        String resultStr = HttpUtil.post(url, str);
 | 
				
			||||||
 | 
					        //logger.info("call method[{}] resp params[{}]",reqVo.getMethod(),resultStr);
 | 
				
			||||||
 | 
					        JSONObject result = JSONObject.parseObject(resultStr);
 | 
				
			||||||
 | 
					        log.info("call yk result [{}]" , result.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (result.getInteger("returnCode") != 1) {
 | 
				
			||||||
 | 
					            throw new ServiceException("调用运控接口异常" + result.getString("msg"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if(JSONObject.class.equals(expectCls)){
 | 
				
			||||||
 | 
					            return (T)result.getJSONObject("data");
 | 
				
			||||||
 | 
					        }else{
 | 
				
			||||||
 | 
					            return (T)result.getString("data");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue