Browse Source

定时同步suite ticket到开发环境

seyason 2 years ago
parent
commit
d34f659586

+ 24 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -146,7 +146,8 @@ public class WeiXinCorpController {
         public LocalDateTime expireTime = null;
     }
     public static Map<String, AgentItem> agentCorpTicketMap = new HashMap<String,AgentItem>();
-
+    @Value("${configEnv.isDev}")
+    boolean isDev;
     @Resource
     SysConfigMapper sysConfigMapper;
     @Resource
@@ -1700,7 +1701,7 @@ public class WeiXinCorpController {
                 }
                 if (!userItem.getName().equals(oldUser.getName())) {
                     changeUser.setId(oldUser.getId());
-                    changeUser.setName(oldUser.getName());
+                    changeUser.setName(userItem.getName());
                 }
                 if (!userItem.getCorpwxDeptid().equals(oldUser.getCorpwxDeptid())) {
                     changeUser.setId(oldUser.getId());
@@ -1721,6 +1722,8 @@ public class WeiXinCorpController {
                     //有变动
                     finalUpdateUserList.add(changeUser);
                 }
+            } else {
+                System.out.println("没找到用户:"+userItem.getName()+", "+userItem.getCorpwxUserid());
             }
         }
 
@@ -2107,7 +2110,7 @@ public class WeiXinCorpController {
             return msg;
         }
         int companyId = company.getId();
-        //获取公司根部门人员,也就是没有分配部门的人员
+        //获取公司根部门人员,属于公司这个组织下面的人员
         int companyRootDeptId = 1;
         JSONArray unAssignedUserList = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
         SysRole defaultRole = sysRoleMapper.selectOne(
@@ -2478,6 +2481,24 @@ public class WeiXinCorpController {
         return msg;
     }
 
+    @RequestMapping("/updateSuiteTicket")
+    public HttpRespMsg updateSuiteTicket(String suiteTicket) {
+        HttpRespMsg msg = new HttpRespMsg();
+        String remoteHost = request.getRemoteHost();
+        System.out.println("请求来自:"+remoteHost);
+        if ("47.100.37.243".equals(remoteHost) && isDev) {
+            SysConfig config = sysConfigMapper.selectOne(new QueryWrapper<SysConfig>().eq("param_key", "wx_suite_ticket"));
+            if (config != null) {
+                config.setParamValue(suiteTicket);
+                config.setIndate(LocalDateTime.now());
+                sysConfigMapper.updateById(config);
+            }
+        }
+        return msg;
+    }
+
+
+
     //将部门id转换为部门层级
     private String convertDepartmentIdToCascade(Integer id, List<Department> allDeptList) {
         StringBuilder cascade = new StringBuilder();

+ 17 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.injector.methods.SelectById;
+import com.management.platform.controller.WeiXinCorpController;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.*;
@@ -65,7 +66,8 @@ public class TimingTask {
     public String appSecret;
     @Autowired
     private RedisUtil redisUtil;
-
+    @Autowired
+    RestTemplate restTemplate;
     @Resource
     private CompanyMapper companyMapper;
     @Resource
@@ -536,7 +538,20 @@ public class TimingTask {
         }
 
     }
-
+    //推送到开发环境,每10分钟一次
+    @Scheduled(fixedRate = 600 * 1000)
+    private void genRandomCode() {
+        if (isDev) {
+            return;
+        }
+        String url = "http://47.101.180.183:10010/wxcorp/updateSuiteTicket?suiteTicket="
+                +sysConfigMapper.selectOne(new QueryWrapper<SysConfig>().eq("param_key", "wx_suite_ticket")).getParamValue();
+        String forObject = this.restTemplate.getForObject(url, String.class);
+        JSONObject json = JSONObject.parseObject(forObject);
+        if (json.getString("code").equals("error")) {
+            System.out.println("推送失败:"+json.getString("msg"));
+        }
+    }
     //每分钟校验是否有需要提醒的填报
     @Scheduled(fixedRate = 60 * 1000)
     private void process() {