Commit c2529e7e by 水库浪子

新增通讯录根据部门id获取员工,以及员工账号的启用停用功能

1 parent 1b6865e3
......@@ -8,6 +8,8 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -30,34 +32,35 @@ import com.linkwechat.wecom.service.IWeUserService;
*/
@RestController
@RequestMapping("/wecom/user")
public class WeUserController extends BaseController
{
@Api("通讯录人员接口")
public class WeUserController extends BaseController {
@Autowired
private IWeUserService weUserService;
// /**
// * 查询通讯录相关客户列表
// */
// @PreAuthorize("@ss.hasPermi('wecom:user:list')")
// @GetMapping("/list")
// public TableDataInfo list(WeUser weUser)
// {
// startPage();
// List<WeUser> list = weUserService.selectWeUserList(weUser);
// return getDataTable(list);
// }
/**
* 查询通讯录相关客户列表
*/
@PreAuthorize("@ss.hasPermi('wecom:user:list')")
@GetMapping("/list")
@ApiOperation("获取通讯录人员列表")
public TableDataInfo list(WeUser weUser)
{
startPage();
List<WeUser> list = weUserService.selectWeUserList(weUser);
return getDataTable(list);
}
// /**
// * 获取通讯录相关客户详细信息
// */
// @PreAuthorize("@ss.hasPermi('wecom:user:query')")
// @GetMapping(value = "/{id}")
// public AjaxResult getInfo(@PathVariable("id") Long id)
// {
// return AjaxResult.success(weUserService.selectWeUserById(id));
// }
/**
* 获取通讯录相关客户详细信息
*/
@PreAuthorize("@ss.hasPermi('wecom:user:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(weUserService.selectWeUserById(id));
}
/**
* 新增通讯录相关客户
......@@ -65,6 +68,7 @@ public class WeUserController extends BaseController
@PreAuthorize("@ss.hasPermi('wecom:user:add')")
@Log(title = "通讯录相关客户", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增通讯录客户")
public AjaxResult add(@RequestBody WeUser weUser)
{
return toAjax(weUserService.insertWeUser(weUser));
......@@ -81,6 +85,15 @@ public class WeUserController extends BaseController
return toAjax(weUserService.updateWeUser(weUser));
}
@PreAuthorize("@ss.hasPermi('wecom:user:startOrStop')")
@Log(title = "启用禁用用户", businessType = BusinessType.UPDATE)
@PutMapping("/startOrStop")
public AjaxResult startOrStop(Long id,Integer enable){
return toAjax(weUserService.startOrStop(id,enable));
}
// /**
// * 删除通讯录相关客户
// */
......
......@@ -456,4 +456,43 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
{
return (T) obj;
}
/**
* 将数组使用分隔符变为字符串
*
* @param array
* @param separator
* @return
*/
public static String join(Object[] array, String separator) {
return join(array, 0, array.length, separator);
}
private static String join(Object[] array, int startIndex, int endIndex, String separator) {
if (separator == null) {
return "";
}
StringBuilder sb = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
/**
* 在前面加,就不会出瑞最后多一个分隔符的现象同时判断不是第一个才加分隔符
*/
if (i > startIndex) {
sb.append(separator);
}
if (array[i] != null) {
sb.append(array[i]);
}
}
return sb.toString();
}
public static void main(String[] args) {
Integer[] arrays = { 1,2,3,4,5,6,7 };
String join = join(arrays, ",");
System.out.println(join);// 1,2,3,4,5,6,7
}
}
\ No newline at end of file
package com.linkwechat.framework.handler;
import com.linkwechat.common.utils.StringUtils;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* @description: Mybatis数组转字符串a, b, c, d, e
* @author: HaoN
* @create: 2020-09-08 17:19
**/
@MappedTypes(value = { Integer[].class,Short[].class,Long[].class })
@MappedJdbcTypes(value = JdbcType.VARCHAR)
public class IntArrayJoinTypeHandler extends BaseTypeHandler<Integer[]> {
String split = ",";
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType)
throws SQLException {
ps.setString(i, StringUtils.join(parameter, split));
}
@Override
public Integer[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
String reString = rs.getString(columnName);
if (reString != null && reString.length() > 0) {
String[] arrs = reString.split(split);
List<Integer> idList = new ArrayList<>(arrs.length);
for (String id : arrs) {
if (id != null && id.length() > 0) {
idList.add(Integer.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
}
return null;
}
@Override
public Integer[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String reString = rs.getString(columnIndex);
if (reString != null && reString.length() > 0) {
String[] arrs = reString.split(split);
List<Integer> idList = new ArrayList<>(arrs.length);
for (String id : arrs) {
if (id != null && id.length() > 0) {
idList.add(Integer.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
}
return null;
}
@Override
public Integer[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String reString = cs.getString(columnIndex);
if (reString != null && reString.length() > 0) {
String[] arrs = reString.split(split);
List<Integer> idList = new ArrayList<>(arrs.length);
for (String id : arrs) {
if (id != null && id.length() > 0) {
idList.add(Integer.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
}
return null;
}
}
package com.linkwechat.wecom.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.dto.WeUserDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
......@@ -14,70 +18,102 @@ import org.apache.commons.lang3.builder.ToStringStyle;
* @author ruoyi
* @date 2020-08-31
*/
@Data
@ApiModel("通讯录用户")
public class WeUser extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
private Long id= SnowFlakeUtil.nextId();
/** 头像地址 */
private String headImageUrl;
/** 用户头像 */
@ApiModelProperty("用户头像,该值来自素材库")
private String avatarMediaid;
/** 用户名称 */
private String userName;
@ApiModelProperty("姓名")
private String name;
/** 用户昵称 */
@ApiModelProperty("昵称")
private String alias;
/** 账号 */
@ApiModelProperty("账号")
private String userId;
/** 性别。1表示男性,2表示女性 */
private Integer gender;
@ApiModelProperty("性别。1表示男性,2表示女性")
private Integer gender=new Integer(1);
/** 手机号 */
@ApiModelProperty("手机号")
private String mobile;
/** 邮箱 */
@ApiModelProperty("邮箱")
private String email;
/** 个人微信号 */
@ApiModelProperty("个人微信号")
private String wxAccount;
/** 用户所属部门,使用逗号隔开,字符串格式存储 */
private String department;
@ApiModelProperty("用户所属部门,使用逗号隔开,字符串格式存储")
private Long[] department;
/** 职务 */
@ApiModelProperty("职务")
private String position;
/** 1表示为上级,0表示普通成员(非上级)。 */
private Long isLeaderInDept;
@ApiModelProperty("1表示为上级,0表示普通成员(非上级)")
private Long[] isLeaderInDept;
/** 入职时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("入职时间")
private Date joinTime;
/** 是否启用(1表示启用成员,0表示禁用成员) */
private Long enable;
@ApiModelProperty("是否启用(1表示启用成员,0表示禁用成员)")
private Integer enable=new Integer(1);
/** 身份证号 */
@ApiModelProperty("身份证号")
private String idCard;
/** QQ号 */
@ApiModelProperty("QQ号")
private String qqAccount;
/** 座机 */
@ApiModelProperty("座机")
private String telephone;
/** 地址 */
@ApiModelProperty("地址")
private String address;
/** 生日 */
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("生日")
private Date birthday;
/** 是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 */
private Long isActivate;
@ApiModelProperty("是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 ")
private Integer isActivate=new Integer(1);
/** 转化成企业微信需要的dto对象 */
public WeUserDto transformWeUserDto(){
WeUserDto weUserDto=new WeUserDto();
BeanUtils.copyPropertiesignoreOther(this,weUserDto);
return weUserDto;
}
}
......@@ -21,7 +21,7 @@ public class WeUserDto {
private String userid;
//性别。1表示男性,2表示女性
private String gender;
private Integer gender;
//手机号码。企业内必须唯一,mobile/email二者不能同时为空
private String mobile;
......
......@@ -58,4 +58,12 @@ public interface WeUserMapper
* @return 结果
*/
public int deleteWeUserByIds(Long[] ids);
/**
* 根据部门id获取员工
* @param departmentId
* @return
*/
public List<WeUser> findWeUsersByDepartmentId(Long departmentId);
}
......@@ -58,4 +58,13 @@ public interface IWeUserService
* @return 结果
*/
public int deleteWeUserById(Long id);
/**
* 启用或禁用用户
* @param id
* @param enable
* @return
*/
public int startOrStop(Long id,Integer enable);
}
......@@ -90,15 +90,16 @@ public class WeDepartmentServiceImpl implements IWeDepartmentService
if(returnCode>0){
WeResultDto weResultDto=weDepartMentClient.createWeDepartMent(
weDepartment.transformDeartMentDto(weDepartment)
);
//微信端调用不成功
if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
throw new WeComException(weResultDto.getErrmsg());
}
WeDepartMentDto.DeartMentDto deartMentDto = weDepartment.transformDeartMentDto(weDepartment);
// WeResultDto weResultDto=weDepartMentClient.createWeDepartMent(
// weDepartment.transformDeartMentDto(weDepartment)
// );
//
// //微信端调用不成功
// if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
// throw new WeComException(weResultDto.getErrmsg());
// }
}
......
package com.linkwechat.wecom.service.impl;
import java.util.List;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.WeUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.linkwechat.wecom.mapper.WeUserMapper;
......@@ -19,6 +25,10 @@ public class WeUserServiceImpl implements IWeUserService
@Autowired
private WeUserMapper weUserMapper;
@Autowired
private WeUserClient weUserClient;
/**
* 查询通讯录相关客户
*
......@@ -52,7 +62,21 @@ public class WeUserServiceImpl implements IWeUserService
@Override
public int insertWeUser(WeUser weUser)
{
return weUserMapper.insertWeUser(weUser);
int returnCode = weUserMapper.insertWeUser(weUser);
if(returnCode>0){
WeResultDto weResultDto = weUserClient.createUser(
weUser.transformWeUserDto()
);
if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
throw new WeComException(weResultDto.getErrmsg());
}
}
return returnCode;
}
/**
......@@ -64,7 +88,20 @@ public class WeUserServiceImpl implements IWeUserService
@Override
public int updateWeUser(WeUser weUser)
{
return weUserMapper.updateWeUser(weUser);
int returnCode = weUserMapper.updateWeUser(weUser);
if(returnCode >0){
WeResultDto weResultDto = weUserClient.updateUser(
weUser.transformWeUserDto()
);
if(!WeConstans.WE_SUCCESS_CODE.equals(weResultDto.getErrcode())){
throw new WeComException(weResultDto.getErrmsg());
}
}
return returnCode;
}
/**
......@@ -90,4 +127,31 @@ public class WeUserServiceImpl implements IWeUserService
{
return weUserMapper.deleteWeUserById(id);
}
/**
* 启用或禁用用户
* @param id
* @param enable
* @return
*/
@Override
public int startOrStop(Long id, Integer enable) {
int returnCode = -1;
WeUser weUser = this.selectWeUserById(id);
if(null != weUser){
weUser.setEnable(enable);
returnCode=updateWeUser(weUser);
}
return returnCode;
}
}
......@@ -6,17 +6,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="WeUser" id="WeUserResult">
<result property="id" column="id" />
<result property="headImageUrl" column="head_image_url" />
<result property="userName" column="user_name" />
<result property="avatarMediaid" column="head_image_url" />
<result property="name" column="user_name" />
<result property="alias" column="alias" />
<result property="userId" column="user_id" />
<result property="gender" column="gender" />
<result property="mobile" column="mobile" />
<result property="email" column="email" />
<result property="wxAccount" column="wx_account" />
<result property="department" column="department" />
<result property="department" column="department" typeHandler="com.linkwechat.framework.handler.IntArrayJoinTypeHandler" />
<result property="position" column="position" />
<result property="isLeaderInDept" column="is_leader_in_dept" />
<result property="isLeaderInDept" column="is_leader_in_dept" typeHandler="com.linkwechat.framework.handler.IntArrayJoinTypeHandler" />
<result property="joinTime" column="join_time" />
<result property="enable" column="enable" />
<result property="idCard" column="id_card" />
......@@ -29,14 +29,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectWeUserVo">
select id, head_image_url, user_name, alias, user_id, gender, mobile, email, wx_account, department, position, is_leader_in_dept, join_time, enable, id_card, qq_account, telephone, address, birthday, remark, is_activate from we_user
select id, head_image_url as avatarMediaid, user_name as name, alias, user_id, gender, mobile, email, wx_account, department, position, is_leader_in_dept, join_time, enable, id_card, qq_account, telephone, address, birthday, remark, is_activate from we_user
</sql>
<select id="selectWeUserList" parameterType="WeUser" resultMap="WeUserResult">
<include refid="selectWeUserVo"/>
<where>
<if test="headImageUrl != null and headImageUrl != ''"> and head_image_url = #{headImageUrl}</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="avatarMediaid != null and avatarMediaid != ''"> and head_image_url = #{avatarMediaid}</if>
<if test="name != null and name != ''"> and user_name like concat('%', #{name}, '%')</if>
<if test="alias != null and alias != ''"> and alias = #{alias}</if>
<if test="userId != null and userId != ''"> and user_id = #{userId}</if>
<if test="gender != null "> and gender = #{gender}</if>
......@@ -66,8 +66,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into we_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="headImageUrl != null">head_image_url,</if>
<if test="userName != null">user_name,</if>
<if test="avatarMediaid != null">head_image_url,</if>
<if test="name != null">user_name,</if>
<if test="alias != null">alias,</if>
<if test="userId != null">user_id,</if>
<if test="gender != null">gender,</if>
......@@ -89,8 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="headImageUrl != null">#{headImageUrl},</if>
<if test="userName != null">#{userName},</if>
<if test="avatarMediaid != null">#{avatarMediaid},</if>
<if test="name != null">#{name},</if>
<if test="alias != null">#{alias},</if>
<if test="userId != null">#{userId},</if>
<if test="gender != null">#{gender},</if>
......@@ -115,8 +115,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateWeUser" parameterType="WeUser">
update we_user
<trim prefix="SET" suffixOverrides=",">
<if test="headImageUrl != null">head_image_url = #{headImageUrl},</if>
<if test="userName != null">user_name = #{userName},</if>
<if test="avatarMediaid != null">head_image_url = #{avatarMediaid},</if>
<if test="name != null">user_name = #{name},</if>
<if test="alias != null">alias = #{alias},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="gender != null">gender = #{gender},</if>
......@@ -149,5 +149,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="findWeUsersByDepartmentId" parameterType="Long" resultMap="WeUserResult">
<include refid="selectWeUserVo"/>
where FIND_IN_SET(#{departmentId},department)
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!