Commit 1a128613 by zhaolianjie

Merge remote-tracking branch 'origin/master'

2 parents 2fa4eb4c ca7d5d6f
package com.pipihelper.project.configurer; package com.pipihelper.project.configurer;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import javax.sql.DataSource;
import java.util.Properties;
/** /**
* Mybatis & Mapper & PageHelper 配置 * Mybatis & Mapper & PageHelper 配置
...@@ -8,27 +19,27 @@ import org.springframework.context.annotation.Configuration; ...@@ -8,27 +19,27 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class MybatisConfigurer { public class MybatisConfigurer {
// @Bean @Bean
// public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception { public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
// SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
// factory.setDataSource(dataSource); factory.setDataSource(dataSource);
// factory.setTypeAliasesPackage(MODEL_PACKAGE); //factory.setTypeAliasesPackage("com.pipitest.project");
//
//// //配置分页插件,详情请查阅官方文档 //配置分页插件,详情请查阅官方文档
//// PageHelper pageHelper = new PageHelper(); PageHelper pageHelper = new PageHelper();
//// Properties properties = new Properties(); Properties properties = new Properties();
//// properties.setProperty("pageSizeZero", "true");//分页尺寸为0时查询所有纪录不再执行分页 properties.setProperty("pageSizeZero", "true");//分页尺寸为0时查询所有纪录不再执行分页
//// properties.setProperty("reasonable", "true");//页码<=0 查询第一页,页码>=总页数查询最后一页 properties.setProperty("reasonable", "true");//页码<=0 查询第一页,页码>=总页数查询最后一页
//// properties.setProperty("supportMethodsArguments", "true");//支持通过 Mapper 接口参数来传递分页参数 properties.setProperty("supportMethodsArguments", "true");//支持通过 Mapper 接口参数来传递分页参数
//// pageHelper.setProperties(properties); pageHelper.setProperties(properties);
////
//// //添加插件 /* //添加插件
//// factory.setPlugins(new Interceptor[]{pageHelper}); factory.setPlugins(new Interceptor[]{pageHelper});*/
//
// //添加XML目录 //添加XML目录
// ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); factory.setMapperLocations(resolver.getResources("classpath:mybatis/*.xml"));
// return factory.getObject(); return factory.getObject();
// } }
} }
package com.pipihelper.project.feishu.bo;
import lombok.Data;
@Data
public class PushPainBO {
Integer index;
String openId;
String name;
String departMentName; //部门名
String timeRange; //时间区间 15:00 - 16:00
}
package com.pipihelper.project.feishu.controller; package com.pipihelper.project.feishu.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.FeiShuConfig; import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO; import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.employee.SystemFieldsDTO;
import com.pipihelper.project.feishu.entity.Employee;
import com.pipihelper.project.feishu.service.EmployeeService;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.FeiShuEventService; import com.pipihelper.project.feishu.service.FeiShuEventService;
import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter; import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter;
import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/** /**
* @Description: TODO * @Description: TODO
...@@ -25,6 +38,13 @@ public class FeiShuEventController { ...@@ -25,6 +38,13 @@ public class FeiShuEventController {
@Resource @Resource
private FeiShuEventService feiShuEventService; private FeiShuEventService feiShuEventService;
@Autowired
private FeiShuApiService feiShuApiService;
@Autowired
private EmployeeService employeeService;
@PostMapping("/event") @PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception { public JSONObject event(@RequestBody String s) throws Exception {
...@@ -65,4 +85,38 @@ public class FeiShuEventController { ...@@ -65,4 +85,38 @@ public class FeiShuEventController {
// } // }
// //
// } // }
@PostMapping("/employee-list")
public Object event() {
List<FeiShuEmployeeDTO> dtos = feiShuApiService.getEmployeeList();
List<Employee> employeeList = employeeService.findAll();
Map<String, Employee> employeeMap = employeeList.stream().collect(Collectors.toMap(Employee::getOpenId, Function.identity()));
List<String> openIdList = dtos.stream().map(FeiShuEmployeeDTO::getUserId).collect(Collectors.toList());
employeeList.forEach(it -> {
if (!openIdList.contains(it.getOpenId())) {
employeeService.deleteById(it.getId());
}
});
dtos.forEach(it -> {
Employee currentEmployee = employeeMap.get(it.getUserId());
if (currentEmployee != null) {
return;
}
Employee employee = new Employee();
SystemFieldsDTO systemFieldsDTO = it.getSystemFields();
employee.setOpenId(it.getUserId());
if (systemFieldsDTO != null) {
employee.setGender(systemFieldsDTO.getGender());
employee.setStatus(systemFieldsDTO.getStatus());
employee.setDepartmentId(systemFieldsDTO.getDepartmentId());
employee.setName(systemFieldsDTO.getName());
employee.setMobile(systemFieldsDTO.getMobile());
}
employeeService.create(employee);
});
return dtos;
}
} }
package com.pipihelper.project.feishu.dao;
import com.pipihelper.project.feishu.entity.Employee;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface EmployeeDao {
Employee findById(Integer id);
Employee findByOpenId(String openId);
void deleteById(Integer id);
void create(Employee employee);
void update(Employee employee);
List<Employee> findAll();
}
...@@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; ...@@ -6,7 +6,6 @@ import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
@NoArgsConstructor
@Data @Data
public class SystemFieldsDTO { public class SystemFieldsDTO {
@JsonProperty("name") @JsonProperty("name")
......
package com.pipihelper.project.feishu.entity;
import lombok.Data;
@Data
public class Employee {
private Integer id;
private String openId;
private String mobile;
private String name;
private Integer gender;
private Integer status;
private String departmentId;
}
package com.pipihelper.project.feishu.service;
import com.pipihelper.project.feishu.dao.EmployeeDao;
import com.pipihelper.project.feishu.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EmployeeService {
@Autowired
private EmployeeDao employeeDao;
public Employee findById(Integer id) {
return employeeDao.findById(id);
}
public Employee findByOpenId(String openId) {
return employeeDao.findByOpenId(openId);
}
public void deleteById(Integer id) {
employeeDao.deleteById(id);
}
public void create(Employee employee) {
employeeDao.create(employee);
}
public void update(Employee employee) {
employeeDao.update(employee);
}
public List<Employee> findAll() {
return employeeDao.findAll();
}
}
...@@ -62,10 +62,10 @@ public class FeiShuApiService { ...@@ -62,10 +62,10 @@ public class FeiShuApiService {
.expireAfterWrite(Duration.ofHours(2)) .expireAfterWrite(Duration.ofHours(2))
.build(); .build();
private final Cache<String, List<FeiShuEmployeeDTO>> EMPLOYEE_LIST_CACHE = Caffeine.newBuilder() /* private final Cache<String, List<FeiShuEmployeeDTO>> EMPLOYEE_LIST_CACHE = Caffeine.newBuilder()
.maximumSize(100) .maximumSize(100)
.expireAfterWrite(Duration.ofHours(2)) .expireAfterWrite(Duration.ofHours(2))
.build(); .build();*/
public String getTenantToken() { public String getTenantToken() {
return FEISHU_CACHE.get("tenantAccessToken", key -> setTenantAccessToken()); return FEISHU_CACHE.get("tenantAccessToken", key -> setTenantAccessToken());
...@@ -155,7 +155,7 @@ public class FeiShuApiService { ...@@ -155,7 +155,7 @@ public class FeiShuApiService {
@Async @Async
public JSONObject patchUrgentApp(String message_id, JSONObject content) { public JSONObject patchUrgentApp(String message_id, JSONObject content) {
String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=open_id"; String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=user_id";
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
String url = feiShuConfig.getFeiShuOpenApiHost() + api; String url = feiShuConfig.getFeiShuOpenApiHost() + api;
RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json")); RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json"));
...@@ -334,6 +334,7 @@ public class FeiShuApiService { ...@@ -334,6 +334,7 @@ public class FeiShuApiService {
} }
} }
/** /**
* 获取飞书人事花名单信息 * 获取飞书人事花名单信息
* 文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/ehr/ehr-v1/employee/list * 文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/ehr/ehr-v1/employee/list
...@@ -341,11 +342,7 @@ public class FeiShuApiService { ...@@ -341,11 +342,7 @@ public class FeiShuApiService {
* @return * @return
*/ */
public List<FeiShuEmployeeDTO> getEmployeeList() { public List<FeiShuEmployeeDTO> getEmployeeList() {
return EMPLOYEE_LIST_CACHE.get("employeeList", s -> setEmployeeList()); String api = "/ehr/v1/employees?view=full&status=2&status=4&page_size=100&user_id_type=open_id";
}
private List<FeiShuEmployeeDTO> setEmployeeList() {
String api = "/ehr/v1/employees?view=full&status=2&status=4&page_size=100";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken()); headers.set("Authorization", "Bearer " + getTenantToken());
......
...@@ -50,6 +50,6 @@ public class FeiShuEventDataDecrypter { ...@@ -50,6 +50,6 @@ public class FeiShuEventDataDecrypter {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter("kudryavka"); FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter("kudryavka");
System.out.println(d.decrypt("FIAfJPGRmFZWkaxPQ1XrJZVbv2JwdjfLk4jx0k/U1deAqYK3AXOZ5zcHt/cC4ZNTqYwWUW/EoL+b2hW/C4zoAQQ5CeMtbxX2zHjm+E4nX/Aww+FHUL6iuIMaeL2KLxqdtbHRC50vgC2YI7xohnb3KuCNBMUzLiPeNIpVdnYaeteCmSaESb+AZpJB9PExzTpRDzCRv+T6o5vlzaE8UgIneC1sYu85BnPBEMTSuj1ZZzfdQi7ZW992Z4dmJxn9e8FL2VArNm99f5Io3c2O4AcNsQENNKtfAAxVjCqc3mg5jF0nKabA+u/5vrUD76flX1UOF5fzJ0sApG2OEn9wfyPDRBsApn9o+fceF9hNrYBGsdtZrZYyGG387CGOtKsuj8e2E8SNp+Pn4E9oYejOTR+ZNLNi+twxaXVlJhr6l+RXYwEiMGQE9zGFBD6h2dOhKh3W84p1GEYnSRIz1+9/Hp66arjC7RCrhuW5OjCj4QFEQJiwgL45XryxHtiZ7JdAlPmjVsL03CxxFZarzxzffryrWUG3VkRdHRHbTsC34+ScoL5MTDU1QAWdqUC1T7xT0lCvQELaIhBTXAYrznJl6PlA83oqlMxpHh0gZBB1jFbfoUr7OQbBs1xqzpYK6Yjux6diwpQB1zlZErYJUfCqK7G/zI9yK/60b4HW0k3M+AvzMcw=")); //hello world System.out.println(d.decrypt("5QyoWWZ3QI5xbQ6Q/niQRVUS+nxnOLk+EEoWJbwPoi1+tQvl92BzKwfS8vFc/ubRHJ4VmOROpjA8TZieBLBWBmh5IcphCVIh5ciPSgjMY5wKRA26G+LN2VvldyO8hUwm7z9XGCNpM7Cbdi/qWmQEC9AmFxdVlSaR0H8m15TVVLVKOHZt9yFCa8s4hy7Q2kG/")); //hello world
} }
} }
...@@ -13,8 +13,8 @@ feishu: ...@@ -13,8 +13,8 @@ feishu:
feiShuOpenApiHost: https://open.feishu.cn/open-apis feiShuOpenApiHost: https://open.feishu.cn/open-apis
encryptKey: aGTqmJcfXluKWfFWHGw5SdzIg6QIxPsp encryptKey: aGTqmJcfXluKWfFWHGw5SdzIg6QIxPsp
verificationToken: ChUEDdWQbyHpHUV6H5fVeL5fOP3HfBE6 verificationToken: ChUEDdWQbyHpHUV6H5fVeL5fOP3HfBE6
appId: cli_a2cff17bd3f8d013 appId: cli_a3c2be2801f8500d
appSecret: E5vXXmRipOD6vyolib186b25XXLbdYfE appSecret: bw3ZXzSj47DgHT19YT268bcwYVVnRTZD
fkChatId: oc_5124ee21dbdecf5d802f9e9e33dab722 fkChatId: oc_5124ee21dbdecf5d802f9e9e33dab722
# 腾讯云配置参数 # 腾讯云配置参数
......
<?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.pipihelper.project.feishu.dao.EmployeeDao">
<resultMap id="EmployeeResultMap" type="com.pipihelper.project.feishu.entity.Employee">
<id column="id" property="id"/>
<result column="open_id" property="openId"/>
<result column="mobile" property="mobile"/>
<result column="name" property="name"/>
<result column="gender" property="gender"/>
<result column="department_id" property="departmentId"/>
</resultMap>
<!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee"
extends="EmployeeResultMap">
</resultMap>-->
<sql id="Base_Column_List">
id,open_id,mobile,name,gender,department_id
</sql>
<select id="findById" parameterType="java.lang.Integer" resultMap="EmployeeResultMap">
select
<include refid="Base_Column_List"/>
from t_employee
<where>
id = #{id}
</where>
</select>
<select id="findByOpenId" parameterType="java.lang.String" resultMap="EmployeeResultMap">
select
<include refid="Base_Column_List"/>
from t_employee
<where>
open_id = #{openId}
</where>
</select>
<select id="findAll" resultMap="EmployeeResultMap">
select
<include refid="Base_Column_List"/>
from t_employee
</select>
<delete id="deleteById" parameterType="java.lang.Integer">
delete from t_employee
<where>
id = #{id}
</where>
</delete>
<insert id="create" useGeneratedKeys="true" keyProperty="id"
parameterType="com.pipihelper.project.feishu.entity.Employee">
insert into t_employee (open_id, mobile, name, gender, status, department_id)
values (#{openId}, #{mobile}, #{name}, #{gender}, #{status}, #{departmentId})
</insert>
<update id="update" parameterType="com.pipihelper.project.feishu.entity.Employee">
update t_employee
<set>
<if test="openId != null">
open_id = #{openId},
</if>
<if test="mobile != null">
mobile = #{mobile},
</if>
<if test="gender != null">
gender = #{gender},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="departmentId != null">
department_id = #{departmentId},
</if>
</set>
<where>
id = #{id}
</where>
</update>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!