|
|
@@ -0,0 +1,198 @@
|
|
|
+package cn.iocoder.yudao.server.service;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.system.oa.E9ApiTokenUtil;
|
|
|
+import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class PortalOaFlow {
|
|
|
+ @Value("${oa.appid}")
|
|
|
+ private String appid;
|
|
|
+ @Value("${oa.cpk}")
|
|
|
+ private String cpk;
|
|
|
+ @Value("${oa.register}")
|
|
|
+ private String registerUrl;
|
|
|
+ @Value("${oa.gettoken}")
|
|
|
+ private String tokenUrl;
|
|
|
+ @Value("${oa.companyUrl}")
|
|
|
+ private String companyUrl;
|
|
|
+ @Value("${oa.departmentUrl}")
|
|
|
+ private String departmentUrl;
|
|
|
+ @Value("${oa.userUrl}")
|
|
|
+ private String userUrl;
|
|
|
+ @Value("${oa.workflowId}")
|
|
|
+ private String workflowId;
|
|
|
+ @Value("${oa.requestName}")
|
|
|
+ private String requestName;
|
|
|
+ @Value("${oa.outMaintain}")
|
|
|
+ private String outMaintainUrl;
|
|
|
+
|
|
|
+ private static String spk = "";
|
|
|
+ private static String secret = "";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void register() throws Exception{
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("appid", appid);
|
|
|
+ headers.add("cpk", cpk);
|
|
|
+
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+
|
|
|
+ String result = restTemplate.postForObject(registerUrl, requestEntity, String.class);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ spk = String.valueOf(jsonObject.get("spk"));
|
|
|
+ secret = String.valueOf(jsonObject.get("secret"));
|
|
|
+ System.out.println("result register:" + result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getToken() throws Exception{
|
|
|
+ if (StringUtils.isBlank(spk) || StringUtils.isBlank(secret)) {
|
|
|
+ register();
|
|
|
+ }
|
|
|
+ String secretEn = E9ApiTokenUtil.encryptString(spk, secret);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("appid", appid);
|
|
|
+ headers.add("secret", secretEn);
|
|
|
+
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+
|
|
|
+ String result = restTemplate.postForObject(tokenUrl, requestEntity, String.class);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ String token = String.valueOf(jsonObject.get("token"));
|
|
|
+ System.out.println("result token:" + result);
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ public ImmutableMap<String, Object> getOaTodo(String oaId) throws Exception {
|
|
|
+ String token = getToken();
|
|
|
+
|
|
|
+ HttpHeaders headersOut = new HttpHeaders();
|
|
|
+ headersOut.add("token", token);
|
|
|
+ headersOut.add("appid", appid);
|
|
|
+ String person = E9ApiTokenUtil.encryptString(spk, oaId);
|
|
|
+ headersOut.add("userid", person);
|
|
|
+ headersOut.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("root", ImmutableMap.of("createrid", oaId));
|
|
|
+ params.put("conditions", map);
|
|
|
+ params.put("pageSize", 20);
|
|
|
+ params.put("pageNo", 1);
|
|
|
+ System.out.println(JSON.toJSONString(params));
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
+ //待办数量
|
|
|
+ String out = restTemplate.postForObject("https://yfoa.keruioil.com/api/workflow/paService/getDoingWorkflowRequestCount", requestEntityOut, String.class);
|
|
|
+ //待办明细
|
|
|
+ map.put("root", ImmutableMap.of("craterid", oaId));
|
|
|
+ params.put("conditions", map);
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut1 = new HttpEntity<>(params, headersOut);
|
|
|
+ String todoList = restTemplate.postForObject("https://yfoa.keruioil.com/api/workflow/paService/getDoingWorkflowRequestList", requestEntityOut1, String.class);
|
|
|
+ List<JSONObject> jsonObjects = JSON.parseArray(todoList, JSONObject.class);
|
|
|
+ ImmutableMap<String, Object> todo = ImmutableMap.of("todoCount", out,"todoList", jsonObjects);
|
|
|
+ return todo;
|
|
|
+ }
|
|
|
+
|
|
|
+// public void createOutRepairFlow(IotMaintainDO iotMaintainDO) throws Exception {
|
|
|
+// String token = getToken();
|
|
|
+// HttpHeaders headersOut = new HttpHeaders();
|
|
|
+// headersOut.add("token", token);
|
|
|
+// headersOut.add("appid", appid);
|
|
|
+// String person = E9ApiTokenUtil.encryptString(spk, iotMaintainDO.getApplyPersonId());
|
|
|
+// headersOut.add("userid", person);
|
|
|
+// headersOut.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+//
|
|
|
+// OutRepairFlow flow = new OutRepairFlow().setFieldName("xmjl").setFieldValue(iotMaintainDO.getProjectManager());
|
|
|
+// OutRepairFlow flow1 = new OutRepairFlow().setFieldName("sqr").setFieldValue(iotMaintainDO.getApplyPersonId());
|
|
|
+// List<IotOaPersonDO> dos = iotOaPersonMapper.selectList("oa_id", iotMaintainDO.getApplyPersonId());
|
|
|
+// if (CollUtil.isEmpty(dos)) {
|
|
|
+// throw new ServiceException(new ErrorCode(111, "不存在oa部门"));
|
|
|
+// }
|
|
|
+// OutRepairFlow flow2 = new OutRepairFlow().setFieldName("sqbm").setFieldValue(dos.get(0).getDepartmentid());
|
|
|
+// OutRepairFlow flow3 = new OutRepairFlow().setFieldName("sqrq").setFieldValue(DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN));
|
|
|
+// OutRepairFlow flow4 = new OutRepairFlow().setFieldName("clxh").setFieldValue(iotMaintainDO.getDeviceName());
|
|
|
+// OutRepairFlow flow5 = new OutRepairFlow().setFieldName("cph").setFieldValue(iotMaintainDO.getDeviceName());
|
|
|
+// OutRepairFlow flow6 = new OutRepairFlow().setFieldName("wxyy").setFieldValue(iotMaintainDO.getMaintainDescription());
|
|
|
+// OutRepairFlow flow7 = new OutRepairFlow().setFieldName("ygjey").setFieldValue(String.valueOf(iotMaintainDO.getMaintainFee()));
|
|
|
+// OutRepairFlow flow8 = new OutRepairFlow().setFieldName("wxdd").setFieldValue(Objects.isNull(iotMaintainDO.getAddress())?"": iotMaintainDO.getAddress());
|
|
|
+// OutRepairFlow flow9 = new OutRepairFlow().setFieldName("ggxh").setFieldValue(String.valueOf(iotMaintainDO.getModel()));
|
|
|
+// OutRepairFlow flow10 = new OutRepairFlow().setFieldName("qyrq").setFieldValue(StringUtils.substring(iotMaintainDO.getEnableDate(), 0,10));
|
|
|
+// OutRepairFlow flow11 = new OutRepairFlow().setFieldName("wxlb").setFieldValue(String.valueOf(iotMaintainDO.getMaintainClassify()));
|
|
|
+// OutRepairFlow flow12 = new OutRepairFlow().setFieldName("yzglxs").setFieldValue(Objects.isNull(iotMaintainDO.getKmHour())?"": iotMaintainDO.getKmHour());
|
|
|
+// OutRepairFlow flow13 = new OutRepairFlow().setFieldName("wxcj").setFieldValue(String.valueOf(iotMaintainDO.getSupplier()));
|
|
|
+// OutRepairFlow flow14 = new OutRepairFlow().setFieldName("gzms").setFieldValue(String.valueOf(iotMaintainDO.getDescription()));
|
|
|
+// OutRepairFlow flow15 = new OutRepairFlow().setFieldName("wxxm").setFieldValue(String.valueOf(iotMaintainDO.getMaintainItem()));
|
|
|
+// List<String> strings = JSON.parseArray(iotMaintainDO.getOutFile(), String.class);
|
|
|
+// List<ImmutableMap> files = new ArrayList<>();
|
|
|
+// strings.forEach(e ->{
|
|
|
+// String fileName = FileUtils.getFileNameByUrlParse(e);
|
|
|
+// String s1 = FileUtils.encodePathSegment(fileName);
|
|
|
+// String s = StringUtils.substringBeforeLast(e, "/");
|
|
|
+// files.add(ImmutableMap.of("filePath", s+"/"+s1,"fileName", fileName));
|
|
|
+// });
|
|
|
+//
|
|
|
+// OutRepairFlow flow16 = new OutRepairFlow().setFieldName("fjsc").setFieldValue(JSON.toJSONString(files));
|
|
|
+// OutRepairFlow flow17 = new OutRepairFlow().setFieldName("sfdy").setFieldValue("1");
|
|
|
+// ImmutableList<OutRepairFlow> outRepairFlows = ImmutableList.of(flow16,flow12, flow3, flow4, flow5, flow6, flow7, flow8, flow9, flow10, flow11, flow2, flow, flow14, flow1, flow15, flow13,flow17);
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// // 创建表单数据
|
|
|
+// MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
|
+// params.add("workflowId", workflowId);
|
|
|
+// params.add("requestName", requestName);
|
|
|
+// params.add("mainData", JSON.toJSONString(outRepairFlows));
|
|
|
+// Map<String, String> other = new HashMap<>();
|
|
|
+// other.put("isnextflow", "1");
|
|
|
+// params.add("otherParams", JSON.toJSONString(other));
|
|
|
+// System.out.println("------------"+JSON.toJSONString(params));
|
|
|
+// System.out.println(headersOut);
|
|
|
+//
|
|
|
+// // 3. 组合请求头和请求体
|
|
|
+// HttpEntity<MultiValueMap<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
+//// RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+// String out = restTemplate.postForObject(outMaintainUrl, requestEntityOut, String.class);
|
|
|
+// JSONObject outInfo = JSON.parseObject(out);
|
|
|
+// //请求成功
|
|
|
+// if (Objects.isNull(outInfo) || !"success".equalsIgnoreCase(String.valueOf(outInfo.get("code")))) {
|
|
|
+// throw new ServiceException(new ErrorCode(777, String.valueOf(outInfo.get("msg"))));
|
|
|
+// }
|
|
|
+// JSONObject jsonObject = JSON.parseObject(outInfo.get("data").toString());
|
|
|
+// String requestid = String.valueOf(jsonObject.get("requestid"));
|
|
|
+// iotMaintainDO.setRequestId(requestid);
|
|
|
+// iotMaintainMapper.updateById(iotMaintainDO);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Data
|
|
|
+// @Builder
|
|
|
+// @NoArgsConstructor
|
|
|
+// @AllArgsConstructor
|
|
|
+// public static class OutRepairFlow {
|
|
|
+// private String fieldName;
|
|
|
+// private String fieldValue;
|
|
|
+// }
|
|
|
+
|
|
|
+}
|