Browse Source

花名册同步子系统

lizhenhao 2 years ago
parent
commit
27d1cecb6c

+ 166 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/centerservice/utils/RestTemplateService.java

@@ -0,0 +1,166 @@
+package com.jeeplus.centerservice.utils;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.jeeplus.sys.service.dto.UserDTO;
+import com.jeeplus.sys.utils.Global;
+import com.jeeplus.sys.utils.StringUtils;
+import com.jeeplus.sys.utils.UserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.nio.charset.Charset;
+import java.util.Map;
+import java.util.Objects;
+
+@Component
+public class RestTemplateService {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    /**
+     * 访问post接口 - CCPM 系统
+     * @param path 接口路径
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @param bodyMap 请求参数-请求体
+     * @return
+     */
+    public Object postCCPM(String path, String token, Map<String, Object> paramMap, Map<String, Object> bodyMap) {
+        return httpRequest(HttpMethod.POST, token, paramMap, bodyMap, Global.getConfig("CCPM_PATH"), path);
+    }
+
+    /**
+     * 访问get接口 - CCPM 系统
+     * @param path 接口路径
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @return
+     */
+    public Object getCCPM(String path, String token, Map<String, Object> paramMap) {
+        return httpRequest(HttpMethod.GET, token, paramMap, null, Global.getConfig("CCPM_PATH"), path);
+    }
+
+    /**
+     * 访问post接口 - CPA 评估系统
+     * @param path 接口路径
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @param bodyMap 请求参数-请求体
+     * @return
+     */
+    public Object postCPA_EVALUATION(String path, String token, Map<String, Object> paramMap, Map<String, Object> bodyMap) {
+        return httpRequest(HttpMethod.POST, token, paramMap, bodyMap, Global.getConfig("CPA_EVALUATION_PATH"), path);
+    }
+
+    /**
+     * 访问get接口 - CPA 评估系统
+     * @return
+     */
+    public Object getCPA_EVALUATION(String path, String token, Map<String, Object> paramMap) {
+        return httpRequest(HttpMethod.GET, token, paramMap, null, Global.getConfig("CPA_EVALUATION_PATH"), path);
+    }
+
+    /**
+     * 访问post接口 - CPA 财务系统
+     * @param path 接口路径
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @param bodyMap 请求参数-请求体
+     * @return
+     */
+    public Object postCPA_FINANCE(String path, String token, Map<String, Object> paramMap, Map<String, Object> bodyMap) {
+        return httpRequest(HttpMethod.POST, token, paramMap, bodyMap, Global.getConfig("CPA_FINANCE_PATH"), path);
+    }
+
+    /**
+     * 访问get接口 - CPA 财务系统
+     * @return
+     */
+    public Object getCPA_FINANCE(String path, String token, Map<String, Object> paramMap) {
+        return httpRequest(HttpMethod.GET, token, paramMap, null, Global.getConfig("CPA_FINANCE_PATH"), path);
+    }
+
+    /**
+     * 访问post接口 - CPA 中审系统
+     * @param path 接口路径
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @param bodyMap 请求参数-请求体
+     * @return
+     */
+    public Object postCPA_AUDIT(String path, String token, Map<String, Object> paramMap, Map<String, Object> bodyMap) {
+        return httpRequest(HttpMethod.POST, token, paramMap, bodyMap, Global.getConfig("CPA_AUDIT_PATH"), path);
+    }
+
+    /**
+     * 访问get接口 - CPA 中审系统
+     * @return
+     */
+    public Object getCPA_AUDIT(String path, String token, Map<String, Object> paramMap) {
+        return httpRequest(HttpMethod.GET, token, paramMap, null, Global.getConfig("CPA_AUDIT_PATH"), path);
+    }
+
+    /**
+     * 访问远程接口方法
+     * @param method 请求类型
+     * @param token token
+     * @param paramMap 请求参数-路径后
+     * @param bodyMap 请求参数-请求体
+     * @param hostAddress 服务host地址
+     * @param path 接口路径
+     * @return
+     */
+    public Object httpRequest(HttpMethod method, String token, Map<String, Object> paramMap, Map<String, Object> bodyMap, String hostAddress, String path) {
+        UserDTO currentUserDTO = UserUtils.getCurrentUserDTO();
+        Object res = null;
+        try {
+            JSONObject jsonObject = new JSONObject();
+            if (CollectionUtil.isNotEmpty(bodyMap)) {
+                jsonObject = new JSONObject(bodyMap); // 另一端接口需要使用@RequestBody来接收此参数
+            }
+            String url = getUrl(hostAddress, path, paramMap);
+            HttpHeaders httpHeaders = new HttpHeaders();
+            httpHeaders.add("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODU0MjkxNzUsInVzZXJuYW1lIjoiYWRtaW4ifQ.AActFiVcl2IzY1LR-0ILYcJqhm2YUXBFuDTxGx7pBDU");
+            httpHeaders.add("Accept", MediaType.ALL_VALUE);
+//            httpHeaders.add("cookie", "jeeplus.session.id=3cb71cc227e348ea883e0f009579088f");
+            httpHeaders.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
+            HttpEntity<Object> entity = new HttpEntity<>(jsonObject, httpHeaders);
+            ResponseEntity<Object> responseEntity = restTemplate.exchange(url, method, entity, Object.class);
+            res = responseEntity.getBody();
+        } catch (Exception e) {
+            System.out.println("远程调用失败");
+            e.printStackTrace();
+        }
+        return res;
+    }
+
+    /**
+     * 将参数拼接到请求路径中
+     * @param hostAddress 服务host地址
+     * @param path 接口路径
+     * @param map 请求参数
+     * @return
+     */
+    public String getUrl(String hostAddress, String path, Map<String, Object> map) {
+        String url = hostAddress + path;
+        StringBuilder paramStr = new StringBuilder();
+        if (CollectionUtil.isNotEmpty(map)) {
+            for (String key : map.keySet()) {
+                Object o = map.get(key);
+                if (Objects.nonNull(o)) {
+//                    String value = URLEncoder.encode(o.toString(), "utf-8");
+                    paramStr.append("&").append(key).append("=").append(o);
+                }
+            }
+        }
+        if (StringUtils.isNotBlank(paramStr.toString())){
+            String param = paramStr.substring(1).toString(); // 去掉第一个&
+            url = url + "?" + param;
+        }
+        return url;
+    }
+}

+ 42 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/domain/SysUserFailedLog.java

@@ -0,0 +1,42 @@
+package com.jeeplus.sys.domain;
+
+import com.jeeplus.core.domain.BaseEntity;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 其他系统同步失败记录
+ * @TableName sys_user_failed_log
+ */
+@Data
+public class SysUserFailedLog extends BaseEntity {
+    /**
+     * 备注
+     */
+    private String remarks;
+
+    /**
+     * 保存失败的用户id
+     */
+    private String userId;
+
+    /**
+     * 所属系统
+     */
+    private String belongService;
+
+    /**
+     * 0保存操作  1清空操作  2删除操作
+     */
+    private String isSuccess;
+
+    /**
+     * 0未手动推送  1手动推送完成
+     */
+    private String isPush;
+
+    private static final long serialVersionUID = 1L;
+
+}

+ 11 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/SysUserFailedLogMapper.java

@@ -0,0 +1,11 @@
+package com.jeeplus.sys.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jeeplus.sys.domain.SysUserFailedLog;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface SysUserFailedLogMapper extends BaseMapper<SysUserFailedLog> {
+
+    void finishById(String id);
+}

+ 8 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/SysUserFailedLogMapper.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.jeeplus.sys.mapper.SysUserFailedLogMapper">
+
+    <update id="finishById">
+        update sys_user_failed_log set is_push = '1' where id = #{id}
+    </update>
+</mapper>

+ 65 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/SysUserFailedLogService.java

@@ -0,0 +1,65 @@
+/**
+ * Copyright &copy; 2021-2026 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
+ */
+package com.jeeplus.sys.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jeeplus.center.enums.ServiceAliasEnum;
+import com.jeeplus.sys.domain.*;
+import com.jeeplus.sys.mapper.SysUserFailedLogMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class SysUserFailedLogService extends ServiceImpl<SysUserFailedLogMapper, SysUserFailedLog> {
+
+	@Autowired
+	private SysUserFailedLogMapper sysUserFailedLogMapper;
+
+	public String saveFailedLog(String userId,String belongService) {
+		SysUserFailedLog sysUserFailedLog = new SysUserFailedLog();
+		sysUserFailedLog.setUserId(userId);
+		sysUserFailedLog.setBelongService(belongService);
+		sysUserFailedLogMapper.insert(sysUserFailedLog);
+		return sysUserFailedLog.getId();
+	}
+
+	/**
+	 * 在切换用户所属部门时,清除之前所属子系统数据失败记录
+	 */
+	public String deleteFailedLog(String userId,String belongService) {
+		SysUserFailedLog sysUserFailedLog = new SysUserFailedLog();
+		sysUserFailedLog.setUserId(userId);
+		sysUserFailedLog.setBelongService(belongService);
+		sysUserFailedLog.setIsSuccess("1"); // 清除操作标记为失败
+		sysUserFailedLogMapper.insert(sysUserFailedLog);
+		return sysUserFailedLog.getId();
+	}
+
+	/**
+	 * 在删除花名册数据时,删除子系统花名册数据失败记录
+	 */
+	public String removeFailedLog(String userId,String belongService) {
+		SysUserFailedLog sysUserFailedLog = new SysUserFailedLog();
+		sysUserFailedLog.setUserId(userId);
+		sysUserFailedLog.setBelongService(belongService);
+		sysUserFailedLog.setIsSuccess("2"); // 删除数据操作标记为失败
+		sysUserFailedLogMapper.insert(sysUserFailedLog);
+		return sysUserFailedLog.getId();
+	}
+
+	public void deleteByUserAndService(String userId,String belongService) {
+		sysUserFailedLogMapper.delete(new LambdaQueryWrapper<SysUserFailedLog>()
+				.eq(SysUserFailedLog::getUserId,userId)
+				.eq(SysUserFailedLog::getBelongService,belongService)
+		);
+	}
+
+	public void finishById(String id) {
+		sysUserFailedLogMapper.finishById(id);
+	}
+
+}

+ 49 - 0
jeeplus-plugins/jeeplus-center/src/main/java/com/jeeplus/center/enums/ServiceAliasEnum.java

@@ -0,0 +1,49 @@
+package com.jeeplus.center.enums;
+
+import java.util.Arrays;
+import java.util.List;
+
+public enum ServiceAliasEnum {
+    CPA_EVALUATION ("xgzcpg", "CPA-评估"),
+    CPA_FINANCE ("xgkjssws", "CPA-财务"),
+    CPA_AUDIT ("zsjsfs", "CPA-中审"),
+    CPA_HR ("hr", "CPA-人力资源"),
+    CPA_PUBLIC ("public", "公共部门");
+
+    private String value;
+
+    private String label;
+
+    private ServiceAliasEnum(String value, String label) {
+        this.value = value;
+        this.label = label;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public String toString() {
+        return this.value;
+    }
+
+    /**
+     * 根据枚举value值匹配到对应的枚举
+     * @param value
+     * @return
+     */
+    public static ServiceAliasEnum getByValue(String value) {
+        ServiceAliasEnum result = null;
+        for (ServiceAliasEnum s : values()) {
+            if (s.value.equals(value)) {
+                return s;
+            }
+        }
+        return result;
+    }
+}