|
@@ -1,6 +1,7 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -14,13 +15,18 @@ import com.management.platform.mapper.WxCorpInfoMapper;
|
|
|
import com.management.platform.service.CompanyService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import org.apache.el.parser.BooleanNode;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -36,6 +42,10 @@ import java.util.stream.Collectors;
|
|
|
@RestController
|
|
|
@RequestMapping("/company")
|
|
|
public class CompanyController {
|
|
|
+ @Value("${syncDDMembUrl}")
|
|
|
+ private String syncDDMembUrl;
|
|
|
+ @Autowired
|
|
|
+ RestTemplate restTemplate;
|
|
|
@Resource
|
|
|
CompanyMapper companyMapper;
|
|
|
@Resource
|
|
@@ -45,6 +55,8 @@ public class CompanyController {
|
|
|
@Resource
|
|
|
CompanyDingdingMapper companyDingdingMapper;
|
|
|
|
|
|
+ public static LocalDateTime lastSyncDDTime;
|
|
|
+
|
|
|
/**
|
|
|
* 获取企业列表,显示到期时间
|
|
|
* @return
|
|
@@ -64,18 +76,21 @@ public class CompanyController {
|
|
|
IPage<Company> result = companyMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
|
|
|
List<Company> records = result.getRecords();
|
|
|
List<Integer> collect = records.stream().map(Company::getId).collect(Collectors.toList());
|
|
|
- List<WxCorpInfo> wxComps = wxCorpInfoMapper.selectList(new QueryWrapper<WxCorpInfo>().in("company_id", collect));
|
|
|
- List<CompanyDingding> dingdingList = companyDingdingMapper.selectList(new QueryWrapper<CompanyDingding>().in("company_id", collect));
|
|
|
- records.forEach(r->{
|
|
|
- Optional<WxCorpInfo> first = wxComps.stream().filter(wx -> wx.getCompanyId().intValue() == r.getId()).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- r.setWxCorpid(first.get().getCorpid());
|
|
|
- }
|
|
|
- Optional<CompanyDingding> first1 = dingdingList.stream().filter(d -> d.getCompanyId().intValue() == r.getId()).findFirst();
|
|
|
- if (first1.isPresent()) {
|
|
|
- r.setDingdingCorpid(first1.get().getCorpid());
|
|
|
- }
|
|
|
- });
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ List<WxCorpInfo> wxComps = wxCorpInfoMapper.selectList(new QueryWrapper<WxCorpInfo>().in("company_id", collect));
|
|
|
+ List<CompanyDingding> dingdingList = companyDingdingMapper.selectList(new QueryWrapper<CompanyDingding>().in("company_id", collect));
|
|
|
+ records.forEach(r->{
|
|
|
+ Optional<WxCorpInfo> first = wxComps.stream().filter(wx -> wx.getCompanyId().intValue() == r.getId()).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ r.setWxCorpid(first.get().getCorpid());
|
|
|
+ }
|
|
|
+ Optional<CompanyDingding> first1 = dingdingList.stream().filter(d -> d.getCompanyId().intValue() == r.getId()).findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ r.setDingdingCorpid(first1.get().getCorpid());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
msg.data = result;
|
|
|
return msg;
|
|
|
}
|
|
@@ -116,5 +131,41 @@ public class CompanyController {
|
|
|
public HttpRespMsg setPackageList(Company company) {
|
|
|
return companyService.setPackageList(company);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/syncDindDingMembs")
|
|
|
+ public HttpRespMsg syncDingDingMembs(String corpid) {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ if (lastSyncDDTime != null) {
|
|
|
+ if (now.isBefore(lastSyncDDTime.plusSeconds(60))) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ msg.setError("两次同步操作必须间隔一分钟");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lastSyncDDTime = now;
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+
|
|
|
+ ResponseEntity<HttpRespMsg> responseEntity = this.restTemplate.getForEntity(syncDDMembUrl+"?corpid="+corpid, HttpRespMsg.class);
|
|
|
+
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ HttpRespMsg msg = responseEntity.getBody();
|
|
|
+ if (msg.code.equals("error")) {
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ if ("调用成功".equals(msg.data)) {
|
|
|
+ return new HttpRespMsg();
|
|
|
+ } else {
|
|
|
+ HttpRespMsg errMsg = new HttpRespMsg();
|
|
|
+ errMsg.setError((String)msg.data);
|
|
|
+ return errMsg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ HttpRespMsg error = new HttpRespMsg();
|
|
|
+ error.setError("请求失败:"+responseEntity.getStatusCode()+", "+responseEntity.getStatusCodeValue());
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|