Browse Source

0310.1

master
zhangye 5 years ago
parent
commit
642574a288
  1. 9
      health/src/main/java/com/ccsens/health/api/WeixinController.java
  2. 1
      health/src/main/java/com/ccsens/health/bean/dto/EmployeeDto.java
  3. 19
      health/src/main/java/com/ccsens/health/bean/po/Department.java
  4. 100
      health/src/main/java/com/ccsens/health/bean/po/DepartmentExample.java
  5. 11
      health/src/main/java/com/ccsens/health/bean/po/Employee.java
  6. 70
      health/src/main/java/com/ccsens/health/bean/po/EmployeeExample.java
  7. 6
      health/src/main/java/com/ccsens/health/service/IWeiXinService.java
  8. 13
      health/src/main/java/com/ccsens/health/service/WeiXinService.java
  9. 4
      health/src/main/resources/application.yml
  10. 4
      health/src/main/resources/mapper_dao/EmployeeDao.xml
  11. 45
      health/src/main/resources/mapper_raw/DepartmentMapper.xml
  12. 39
      health/src/main/resources/mapper_raw/EmployeeMapper.xml
  13. 53
      tall/src/main/java/com/ccsens/tall/service/UserService.java
  14. 20
      util/src/main/java/com/ccsens/util/enterprisewx/WeiXinConstant.java
  15. 17
      util/src/main/java/com/ccsens/util/enterprisewx/vo/WeiXinVo.java

9
health/src/main/java/com/ccsens/health/api/WeixinController.java

@ -5,6 +5,7 @@ import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.health.bean.dto.EmployeeDto;
import com.ccsens.health.bean.po.Employee;
import com.ccsens.health.bean.po.HealthAuth;
import com.ccsens.health.persist.dao.EmployeeDao;
import com.ccsens.health.service.IConstantService;
@ -170,7 +171,7 @@ public class WeixinController {
String suiteToken = weiXinService.getSuiteToken(suiteId, suiteTicket);
HealthAuth auth = weiXinService.savePermanentCode(authCode, suiteToken);
if (auth != null) {
weiXinService.initDepartment(auth.getAccessToken());
weiXinService.initDepartment(auth.getAccessToken(), auth.getCorpid());
}
}
@ -202,9 +203,9 @@ public class WeixinController {
* @return
*/
@GetMapping("initMsg")
public JsonResponse bindUser(@RequestBody EmployeeDto.Bind bind) {
weiXinService.bindUser(bind);
return JsonResponse.newInstance().ok();
public JsonResponse<Employee> bindUser(@RequestBody EmployeeDto.Bind bind) {
Employee employee = weiXinService.bindUser(bind);
return JsonResponse.newInstance().ok(employee);
}
}

1
health/src/main/java/com/ccsens/health/bean/dto/EmployeeDto.java

@ -12,5 +12,6 @@ public class EmployeeDto {
public static class Bind{
private Long tallUserId;
private String userid;
private String corpid;
}
}

19
health/src/main/java/com/ccsens/health/bean/po/Department.java

@ -6,13 +6,11 @@ import java.util.Date;
public class Department implements Serializable {
private Long id;
private String weixinId;
private String name;
private String nameEn;
private String parentid;
private Long parentid;
private Integer order;
@ -32,14 +30,6 @@ public class Department implements Serializable {
this.id = id;
}
public String getWeixinId() {
return weixinId;
}
public void setWeixinId(String weixinId) {
this.weixinId = weixinId == null ? null : weixinId.trim();
}
public String getName() {
return name;
}
@ -56,12 +46,12 @@ public class Department implements Serializable {
this.nameEn = nameEn == null ? null : nameEn.trim();
}
public String getParentid() {
public Long getParentid() {
return parentid;
}
public void setParentid(String parentid) {
this.parentid = parentid == null ? null : parentid.trim();
public void setParentid(Long parentid) {
this.parentid = parentid;
}
public Integer getOrder() {
@ -103,7 +93,6 @@ public class Department implements Serializable {
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", weixinId=").append(weixinId);
sb.append(", name=").append(name);
sb.append(", nameEn=").append(nameEn);
sb.append(", parentid=").append(parentid);

100
health/src/main/java/com/ccsens/health/bean/po/DepartmentExample.java

@ -165,76 +165,6 @@ public class DepartmentExample {
return (Criteria) this;
}
public Criteria andWeixinIdIsNull() {
addCriterion("weixin_id is null");
return (Criteria) this;
}
public Criteria andWeixinIdIsNotNull() {
addCriterion("weixin_id is not null");
return (Criteria) this;
}
public Criteria andWeixinIdEqualTo(String value) {
addCriterion("weixin_id =", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdNotEqualTo(String value) {
addCriterion("weixin_id <>", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdGreaterThan(String value) {
addCriterion("weixin_id >", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdGreaterThanOrEqualTo(String value) {
addCriterion("weixin_id >=", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdLessThan(String value) {
addCriterion("weixin_id <", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdLessThanOrEqualTo(String value) {
addCriterion("weixin_id <=", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdLike(String value) {
addCriterion("weixin_id like", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdNotLike(String value) {
addCriterion("weixin_id not like", value, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdIn(List<String> values) {
addCriterion("weixin_id in", values, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdNotIn(List<String> values) {
addCriterion("weixin_id not in", values, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdBetween(String value1, String value2) {
addCriterion("weixin_id between", value1, value2, "weixinId");
return (Criteria) this;
}
public Criteria andWeixinIdNotBetween(String value1, String value2) {
addCriterion("weixin_id not between", value1, value2, "weixinId");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("name is null");
return (Criteria) this;
@ -385,62 +315,52 @@ public class DepartmentExample {
return (Criteria) this;
}
public Criteria andParentidEqualTo(String value) {
public Criteria andParentidEqualTo(Long value) {
addCriterion("parentid =", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidNotEqualTo(String value) {
public Criteria andParentidNotEqualTo(Long value) {
addCriterion("parentid <>", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidGreaterThan(String value) {
public Criteria andParentidGreaterThan(Long value) {
addCriterion("parentid >", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidGreaterThanOrEqualTo(String value) {
public Criteria andParentidGreaterThanOrEqualTo(Long value) {
addCriterion("parentid >=", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidLessThan(String value) {
public Criteria andParentidLessThan(Long value) {
addCriterion("parentid <", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidLessThanOrEqualTo(String value) {
public Criteria andParentidLessThanOrEqualTo(Long value) {
addCriterion("parentid <=", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidLike(String value) {
addCriterion("parentid like", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidNotLike(String value) {
addCriterion("parentid not like", value, "parentid");
return (Criteria) this;
}
public Criteria andParentidIn(List<String> values) {
public Criteria andParentidIn(List<Long> values) {
addCriterion("parentid in", values, "parentid");
return (Criteria) this;
}
public Criteria andParentidNotIn(List<String> values) {
public Criteria andParentidNotIn(List<Long> values) {
addCriterion("parentid not in", values, "parentid");
return (Criteria) this;
}
public Criteria andParentidBetween(String value1, String value2) {
public Criteria andParentidBetween(Long value1, Long value2) {
addCriterion("parentid between", value1, value2, "parentid");
return (Criteria) this;
}
public Criteria andParentidNotBetween(String value1, String value2) {
public Criteria andParentidNotBetween(Long value1, Long value2) {
addCriterion("parentid not between", value1, value2, "parentid");
return (Criteria) this;
}

11
health/src/main/java/com/ccsens/health/bean/po/Employee.java

@ -6,6 +6,8 @@ import java.util.Date;
public class Employee implements Serializable {
private Long id;
private String corpid;
private String userid;
private String name;
@ -38,6 +40,14 @@ public class Employee implements Serializable {
this.id = id;
}
public String getCorpid() {
return corpid;
}
public void setCorpid(String corpid) {
this.corpid = corpid == null ? null : corpid.trim();
}
public String getUserid() {
return userid;
}
@ -133,6 +143,7 @@ public class Employee implements Serializable {
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", corpid=").append(corpid);
sb.append(", userid=").append(userid);
sb.append(", name=").append(name);
sb.append(", gender=").append(gender);

70
health/src/main/java/com/ccsens/health/bean/po/EmployeeExample.java

@ -165,6 +165,76 @@ public class EmployeeExample {
return (Criteria) this;
}
public Criteria andCorpidIsNull() {
addCriterion("corpid is null");
return (Criteria) this;
}
public Criteria andCorpidIsNotNull() {
addCriterion("corpid is not null");
return (Criteria) this;
}
public Criteria andCorpidEqualTo(String value) {
addCriterion("corpid =", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidNotEqualTo(String value) {
addCriterion("corpid <>", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidGreaterThan(String value) {
addCriterion("corpid >", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidGreaterThanOrEqualTo(String value) {
addCriterion("corpid >=", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidLessThan(String value) {
addCriterion("corpid <", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidLessThanOrEqualTo(String value) {
addCriterion("corpid <=", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidLike(String value) {
addCriterion("corpid like", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidNotLike(String value) {
addCriterion("corpid not like", value, "corpid");
return (Criteria) this;
}
public Criteria andCorpidIn(List<String> values) {
addCriterion("corpid in", values, "corpid");
return (Criteria) this;
}
public Criteria andCorpidNotIn(List<String> values) {
addCriterion("corpid not in", values, "corpid");
return (Criteria) this;
}
public Criteria andCorpidBetween(String value1, String value2) {
addCriterion("corpid between", value1, value2, "corpid");
return (Criteria) this;
}
public Criteria andCorpidNotBetween(String value1, String value2) {
addCriterion("corpid not between", value1, value2, "corpid");
return (Criteria) this;
}
public Criteria andUseridIsNull() {
addCriterion("userid is null");
return (Criteria) this;

6
health/src/main/java/com/ccsens/health/service/IWeiXinService.java

@ -1,6 +1,7 @@
package com.ccsens.health.service;
import com.ccsens.health.bean.dto.EmployeeDto;
import com.ccsens.health.bean.po.Employee;
import com.ccsens.health.bean.po.HealthAuth;
/**
@ -33,12 +34,13 @@ public interface IWeiXinService {
/**
* 初始化部门和成员信息
* @param accessToken
* @param corpId
*/
void initDepartment(String accessToken);
void initDepartment(String accessToken, String corpId);
/**
* 用户绑定
* @param bind
*/
void bindUser(EmployeeDto.Bind bind);
Employee bindUser(EmployeeDto.Bind bind);
}

13
health/src/main/java/com/ccsens/health/service/WeiXinService.java

@ -79,10 +79,10 @@ public class WeiXinService implements IWeiXinService {
}
@Override
public void bindUser(EmployeeDto.Bind bind) {
public Employee bindUser(EmployeeDto.Bind bind) {
log.info("用户绑定:{}", bind);
EmployeeExample example = new EmployeeExample();
example.createCriteria().andUseridEqualTo(bind.getUserid());
example.createCriteria().andUseridEqualTo(bind.getUserid()).andCorpidEqualTo(bind.getCorpid());
List<Employee> employees = employeeDao.selectByExample(example);
log.info("有无用户信息");
if (CollectionUtil.isEmpty(employees)) {
@ -95,6 +95,7 @@ public class WeiXinService implements IWeiXinService {
bindEmployee.setTallUserId(bind.getTallUserId());
employeeDao.updateByPrimaryKeySelective(bindEmployee);
}
return employee;
}
@Override
@ -155,7 +156,7 @@ public class WeiXinService implements IWeiXinService {
}
@Override
public void initDepartment(String accessToken) {
public void initDepartment(String accessToken, String corpId) {
Map<String, Object> param = new HashMap<>();
param.put("access_token", accessToken);
JSONObject result = (JSONObject) RestTemplateUtil.getForEntity(WeiXinConstant.DEPARTMENT_LIST, param, JSONObject.class);
@ -178,7 +179,7 @@ public class WeiXinService implements IWeiXinService {
insertBatchDepartment(departments);
//初始化員工信息
departments.forEach(department -> {
initEmployee(accessToken, department);
initEmployee(accessToken, department, corpId);
});
@ -188,8 +189,9 @@ public class WeiXinService implements IWeiXinService {
* 初始化员工信息
* @param accessToken
* @param department
* @param corpId
*/
private void initEmployee(String accessToken, Department department) {
private void initEmployee(String accessToken, Department department, String corpId) {
// 查询员工信息
Map<String, Object> params = new HashMap<>();
params.put("access_token", accessToken);
@ -211,6 +213,7 @@ public class WeiXinService implements IWeiXinService {
JSONObject user = (JSONObject)obj;
Employee employee = user.toJavaObject(Employee.class);
employee.setId(snowflake.nextId());
employee.setCorpid(corpId);
employees.add(employee);
JSONArray departmentIds = user.getJSONArray("department");
JSONArray orders = user.getJSONArray("order");

4
health/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: dev
include: common, util-dev
active: test
include: common, util-test

4
health/src/main/resources/mapper_dao/EmployeeDao.xml

@ -4,13 +4,13 @@
<insert id="insertBatch" parameterType="ArrayList">
insert into t_employee (id, userid, name,
insert into t_employee (id, userid,corpid, name,
gender, status, address,
hide_mobile, english_name, tall_user_id
)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=BIGINT}, #{item.userid,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
(#{item.id,jdbcType=BIGINT}, #{item.userid,jdbcType=VARCHAR}, #{item.corpid,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
#{item.gender,jdbcType=TINYINT}, #{item.status,jdbcType=TINYINT}, #{item.address,jdbcType=VARCHAR},
#{item.hideMobile,jdbcType=TINYINT}, #{item.englishName,jdbcType=VARCHAR}, #{item.tallUserId,jdbcType=BIGINT}
)

45
health/src/main/resources/mapper_raw/DepartmentMapper.xml

@ -3,10 +3,9 @@
<mapper namespace="com.ccsens.health.persist.mapper.DepartmentMapper">
<resultMap id="BaseResultMap" type="com.ccsens.health.bean.po.Department">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="weixin_id" jdbcType="VARCHAR" property="weixinId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="name_en" jdbcType="VARCHAR" property="nameEn" />
<result column="parentid" jdbcType="VARCHAR" property="parentid" />
<result column="parentid" jdbcType="BIGINT" property="parentid" />
<result column="order" jdbcType="INTEGER" property="order" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
@ -71,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, weixin_id, name, name_en, parentid, order, created_at, updated_at, rec_status
id, name, name_en, parentid, order, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.health.bean.po.DepartmentExample" resultMap="BaseResultMap">
select
@ -104,14 +103,12 @@
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.health.bean.po.Department">
insert into t_department (id, weixin_id, name,
name_en, parentid, order,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{weixinId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{nameEn,jdbcType=VARCHAR}, #{parentid,jdbcType=VARCHAR}, #{order,jdbcType=INTEGER},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
insert into t_department (id, name, name_en,
parentid, order, created_at,
updated_at, rec_status)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{nameEn,jdbcType=VARCHAR},
#{parentid,jdbcType=BIGINT}, #{order,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.health.bean.po.Department">
insert into t_department
@ -119,9 +116,6 @@
<if test="id != null">
id,
</if>
<if test="weixinId != null">
weixin_id,
</if>
<if test="name != null">
name,
</if>
@ -148,9 +142,6 @@
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="weixinId != null">
#{weixinId,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
@ -158,7 +149,7 @@
#{nameEn,jdbcType=VARCHAR},
</if>
<if test="parentid != null">
#{parentid,jdbcType=VARCHAR},
#{parentid,jdbcType=BIGINT},
</if>
<if test="order != null">
#{order,jdbcType=INTEGER},
@ -186,9 +177,6 @@
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.weixinId != null">
weixin_id = #{record.weixinId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
name = #{record.name,jdbcType=VARCHAR},
</if>
@ -196,7 +184,7 @@
name_en = #{record.nameEn,jdbcType=VARCHAR},
</if>
<if test="record.parentid != null">
parentid = #{record.parentid,jdbcType=VARCHAR},
parentid = #{record.parentid,jdbcType=BIGINT},
</if>
<if test="record.order != null">
order = #{record.order,jdbcType=INTEGER},
@ -218,10 +206,9 @@
<update id="updateByExample" parameterType="map">
update t_department
set id = #{record.id,jdbcType=BIGINT},
weixin_id = #{record.weixinId,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
name_en = #{record.nameEn,jdbcType=VARCHAR},
parentid = #{record.parentid,jdbcType=VARCHAR},
parentid = #{record.parentid,jdbcType=BIGINT},
order = #{record.order,jdbcType=INTEGER},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
@ -233,9 +220,6 @@
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.health.bean.po.Department">
update t_department
<set>
<if test="weixinId != null">
weixin_id = #{weixinId,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
@ -243,7 +227,7 @@
name_en = #{nameEn,jdbcType=VARCHAR},
</if>
<if test="parentid != null">
parentid = #{parentid,jdbcType=VARCHAR},
parentid = #{parentid,jdbcType=BIGINT},
</if>
<if test="order != null">
order = #{order,jdbcType=INTEGER},
@ -262,10 +246,9 @@
</update>
<update id="updateByPrimaryKey" parameterType="com.ccsens.health.bean.po.Department">
update t_department
set weixin_id = #{weixinId,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
set name = #{name,jdbcType=VARCHAR},
name_en = #{nameEn,jdbcType=VARCHAR},
parentid = #{parentid,jdbcType=VARCHAR},
parentid = #{parentid,jdbcType=BIGINT},
order = #{order,jdbcType=INTEGER},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},

39
health/src/main/resources/mapper_raw/EmployeeMapper.xml

@ -3,6 +3,7 @@
<mapper namespace="com.ccsens.health.persist.mapper.EmployeeMapper">
<resultMap id="BaseResultMap" type="com.ccsens.health.bean.po.Employee">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="corpid" jdbcType="VARCHAR" property="corpid" />
<result column="userid" jdbcType="VARCHAR" property="userid" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="gender" jdbcType="TINYINT" property="gender" />
@ -74,7 +75,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, userid, name, gender, status, address, hide_mobile, english_name, tall_user_id,
id, corpid, userid, name, gender, status, address, hide_mobile, english_name, tall_user_id,
created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.health.bean.po.EmployeeExample" resultMap="BaseResultMap">
@ -108,16 +109,16 @@
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.health.bean.po.Employee">
insert into t_employee (id, userid, name,
gender, status, address,
hide_mobile, english_name, tall_user_id,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{userid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{gender,jdbcType=TINYINT}, #{status,jdbcType=TINYINT}, #{address,jdbcType=VARCHAR},
#{hideMobile,jdbcType=TINYINT}, #{englishName,jdbcType=VARCHAR}, #{tallUserId,jdbcType=BIGINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
insert into t_employee (id, corpid, userid,
name, gender, status,
address, hide_mobile, english_name,
tall_user_id, created_at, updated_at,
rec_status)
values (#{id,jdbcType=BIGINT}, #{corpid,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{gender,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
#{address,jdbcType=VARCHAR}, #{hideMobile,jdbcType=TINYINT}, #{englishName,jdbcType=VARCHAR},
#{tallUserId,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.health.bean.po.Employee">
insert into t_employee
@ -125,6 +126,9 @@
<if test="id != null">
id,
</if>
<if test="corpid != null">
corpid,
</if>
<if test="userid != null">
userid,
</if>
@ -163,6 +167,9 @@
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="corpid != null">
#{corpid,jdbcType=VARCHAR},
</if>
<if test="userid != null">
#{userid,jdbcType=VARCHAR},
</if>
@ -210,6 +217,9 @@
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.corpid != null">
corpid = #{record.corpid,jdbcType=VARCHAR},
</if>
<if test="record.userid != null">
userid = #{record.userid,jdbcType=VARCHAR},
</if>
@ -251,6 +261,7 @@
<update id="updateByExample" parameterType="map">
update t_employee
set id = #{record.id,jdbcType=BIGINT},
corpid = #{record.corpid,jdbcType=VARCHAR},
userid = #{record.userid,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
gender = #{record.gender,jdbcType=TINYINT},
@ -269,6 +280,9 @@
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.health.bean.po.Employee">
update t_employee
<set>
<if test="corpid != null">
corpid = #{corpid,jdbcType=VARCHAR},
</if>
<if test="userid != null">
userid = #{userid,jdbcType=VARCHAR},
</if>
@ -307,7 +321,8 @@
</update>
<update id="updateByPrimaryKey" parameterType="com.ccsens.health.bean.po.Employee">
update t_employee
set userid = #{userid,jdbcType=VARCHAR},
set corpid = #{corpid,jdbcType=VARCHAR},
userid = #{userid,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
gender = #{gender,jdbcType=TINYINT},
status = #{status,jdbcType=TINYINT},

53
tall/src/main/java/com/ccsens/tall/service/UserService.java

@ -7,7 +7,8 @@ import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.cloudutil.feign.HealthFeignClient;
import com.ccsens.tall.bean.dto.ProjectDto;
import com.ccsens.tall.bean.dto.UserDto;
@ -125,16 +126,13 @@ public class UserService implements IUserService {
throw new BaseException(CodeEnum.PARAM_ERROR);
}
String suiteAccessToken = healthFeignClient.getSuiteAccessToken(suiteId);
WeiXinVo.UserInfo userInfo = WeiXinConstant.getUserInfo(identifier, suiteAccessToken);
WeiXinVo.Code2Session userInfo = WeiXinConstant.code2Session(identifier, suiteAccessToken);
log.info("用户信息:{}", userInfo);
if (userInfo == null) {
throw new BaseException(CodeEnum.PARAM_ERROR);
}
WxEnterpriseParam param = new WxEnterpriseParam();
param.setRedirect(redirect);
param.setSuiteAccessToken(suiteAccessToken);
param.setUserTicket(userInfo.getUser_ticket());
UserVo.UserSign userSignVo = getUserSign(userInfo.getUserId(), null, (byte) WebConstant.IDENTIFY_TYPE.WxEnterprise.value, param);
UserVo.UserSign userSignVo = getUserSign(userInfo.getUserId(), userInfo.getCorpId(), (byte) WebConstant.IDENTIFY_TYPE.WxEnterprise.value, redirect);
return userSignVo;
}
@ -396,6 +394,7 @@ public class UserService implements IUserService {
return userSignVo;
}
@Data
private static class WxEnterpriseParam {
private String suiteAccessToken;
@ -403,13 +402,15 @@ public class UserService implements IUserService {
private String redirect;
}
/**
* @param openId
* @param unionId
* @return
*/
private UserVo.UserSign getUserSign(String openId, String unionId,
byte identifyType, WxEnterpriseParam param) {
byte identifyType, String redirect) {
UserVo.UserSign userSignVo;//1.查找对应账户,不存在则注册
List<SysAuth> authList = null;
SysAuth theAuth = null;
@ -445,7 +446,7 @@ public class UserService implements IUserService {
SysUser user = new SysUser();
user.setId(snowflake.nextId());
//企业微信获取详细用户信息,并绑定用户信息
getUserDetail(identifyType, param, user);
getUserDetail(identifyType, openId, unionId, redirect, user);
userDao.insertSelective(user);
//添加认证方式
theAuth = new SysAuth();
@ -478,26 +479,33 @@ public class UserService implements IUserService {
}
/**
<<<<<<< HEAD
* 获取企业微信信息并绑定用户
*
=======
* 绑定用户信息并获取用户性别
>>>>>>> 1cb0cb3e14834bb8d60b2060c0e49a8b7615b036
* @param identifyType
* @param param
* @param userid
* @param corpId
* @param redirect
* @param user
*/
private void getUserDetail(byte identifyType, WxEnterpriseParam param, SysUser user) {
private void getUserDetail(byte identifyType, String userid, String corpId, String redirect, SysUser user) {
if (identifyType == WebConstant.IDENTIFY_TYPE.Wxmp.value) {
WeiXinVo.UserDetail userDetail = WeiXinConstant.getUserDetail(param.getSuiteAccessToken(), param.getUserTicket());
if (userDetail != null) {
user.setNickname(userDetail.getName());
user.setGender(userDetail.getGender());
user.setAvatarUrl(userDetail.getAvatar());
}
Map<String, Object> map = new HashMap<>();
map.put("tallUserId", user.getId());
map.put("userid", userDetail.getUserid());
String s = RestTemplateUtil.postBody(param.getRedirect(), map);
log.info("{}绑定关系结果:{}", s);
//TODO 绑定失败如何处理
map.put("userid", userid);
map.put("corpid", corpId);
String result = RestTemplateUtil.postBody(redirect, map);
log.info("{}绑定关系结果:{}", result);
JSONObject json = JSONObject.parseObject(result);
if (json.getIntValue("code") == 0) {
JSONObject data = json.getJSONObject("data");
user.setNickname(data.getString("name"));
user.setGender(data.getByteValue("gender"));
}
}
}
@ -560,6 +568,9 @@ public class UserService implements IUserService {
tokenExpired = 3600 * 1000L * 2;
refreshTokenExpired = 3600 * 1000L * 24 * 30;
break;
case WxEnterprise:
tokenExpired = 3600 * 1000L * 24;
break;
default:
}

20
util/src/main/java/com/ccsens/util/enterprisewx/WeiXinConstant.java

@ -65,6 +65,7 @@ public class WeiXinConstant {
public static final String USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/list";
public static final String USER_INFO_3RD = "https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd";
public static final String USER_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/service/getuserdetail3rd";
public static final String CODE2SESSION = "https://qyapi.weixin.qq.com/cgi-bin/service/miniprogram/jscode2session";
/**
* 获取第三方凭证
@ -115,6 +116,25 @@ public class WeiXinConstant {
return result.getInteger(ERR_CODE) == null || result.getIntValue(ERR_CODE) == 0;
}
/**
* 客户端登录
* @param code
* @param suiteAccessToken
* @return
*/
public static WeiXinVo.Code2Session code2Session(String code, String suiteAccessToken) {
Map<String, Object> param = new HashMap<>();
param.put("suite_access_token", suiteAccessToken);
param.put("js_code", code);
param.put("grant_type", "authorization_code");
WeiXinVo.Code2Session userInfo = (WeiXinVo.Code2Session) RestTemplateUtil.getForEntity(CODE2SESSION, param, WeiXinVo.Code2Session.class);
log.info("获取用户信息:{}", userInfo);
if (StrUtil.isNotBlank(userInfo.getErrcode()) && !"0".equals(userInfo.getErrcode())) {
return null;
}
return userInfo;
}
/**
* 查询用户信息
* @param code

17
util/src/main/java/com/ccsens/util/enterprisewx/vo/WeiXinVo.java

@ -7,6 +7,23 @@ import lombok.Data;
@Data
@ApiModel("微信相关接口返回")
public class WeiXinVo {
@Data
@ApiModel("微信用户 useId")
public static class Code2Session{
@ApiModelProperty("返回码")
private String errcode;
@ApiModelProperty("对返回码的文本描述内容")
private String errmsg;
@ApiModelProperty("用户所属企业的corpid")
private String CorpId;
@ApiModelProperty("用户在企业内的UserID,如果该企业与第三方应用有授权关系时,返回明文UserId,否则返回密文UserId")
private String UserId;
@ApiModelProperty("会话密钥")
private String session_key;
}
@Data
@ApiModel("微信用戶信息")
public static class UserInfo{

Loading…
Cancel
Save