Commit c62f08f9 by HaoN

通讯录员工新增,修改,启用禁用,列表功能接口完成,并测试。

1 parent c2529e7e
package com.linkwechat.web.controller.system;
import java.util.List;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
......@@ -34,6 +17,15 @@ import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysPostService;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户信息
......@@ -42,7 +34,6 @@ import com.linkwechat.system.service.ISysUserService;
*/
@RestController
@RequestMapping("/system/user")
@Api("系统用户管理")
public class SysUserController extends BaseController
{
@Autowired
......@@ -62,7 +53,6 @@ public class SysUserController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list")
@ApiOperation("获取用户列表")
public TableDataInfo list(SysUser user)
{
startPage();
......
package com.linkwechat.web.controller.tool;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
/**
* swagger 用户测试方法
*
* @author ruoyi
*/
@Api("用户信息管理")
@RestController
@RequestMapping("/test/user")
public class TestController extends BaseController
{
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
{
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
}
@ApiOperation("获取用户列表")
@GetMapping("/list")
public AjaxResult userList()
{
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
return AjaxResult.success(userList);
}
@ApiOperation("获取用户详细")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
@GetMapping("/{userId}")
public AjaxResult getUser(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
return AjaxResult.success(users.get(userId));
}
else
{
return AjaxResult.error("用户不存在");
}
}
@ApiOperation("新增用户")
@ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
@PostMapping("/save")
public AjaxResult save(UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return AjaxResult.error("用户ID不能为空");
}
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("更新用户")
@ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
@PutMapping("/update")
public AjaxResult update(UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return AjaxResult.error("用户ID不能为空");
}
if (users.isEmpty() || !users.containsKey(user.getUserId()))
{
return AjaxResult.error("用户不存在");
}
users.remove(user.getUserId());
return AjaxResult.success(users.put(user.getUserId(), user));
}
@ApiOperation("删除用户信息")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path")
@DeleteMapping("/{userId}")
public AjaxResult delete(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
users.remove(userId);
return AjaxResult.success();
}
else
{
return AjaxResult.error("用户不存在");
}
}
}
@ApiModel("用户实体")
class UserEntity
{
@ApiModelProperty("用户ID")
private Integer userId;
@ApiModelProperty("用户名称")
private String username;
@ApiModelProperty("用户密码")
private String password;
@ApiModelProperty("用户手机")
private String mobile;
public UserEntity()
{
}
public UserEntity(Integer userId, String username, String password, String mobile)
{
this.userId = userId;
this.username = username;
this.password = password;
this.mobile = mobile;
}
public Integer getUserId()
{
return userId;
}
public void setUserId(Integer userId)
{
this.userId = userId;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getMobile()
{
return mobile;
}
public void setMobile(String mobile)
{
this.mobile = mobile;
}
}
package com.linkwechat.web.controller.wecom;
import java.util.List;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
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 com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.service.IWeUserService;
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;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.service.IWeUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
......@@ -78,30 +70,32 @@ public class WeUserController extends BaseController {
* 修改通讯录相关客户
*/
@PreAuthorize("@ss.hasPermi('wecom:user:edit')")
@Log(title = "通讯录相关客户", businessType = BusinessType.UPDATE)
@Log(title = "更新通讯录客户", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新通讯录客户")
public AjaxResult edit(@RequestBody WeUser weUser)
{
return toAjax(weUserService.updateWeUser(weUser));
}
/**
* 启用或者禁止
* @param id
* @param enable
* @return
*/
@PreAuthorize("@ss.hasPermi('wecom:user:startOrStop')")
@Log(title = "启用禁用用户", businessType = BusinessType.UPDATE)
@PutMapping("/startOrStop")
public AjaxResult startOrStop(Long id,Integer enable){
@ApiOperation("启用禁用用户 true:启用 false:禁用")
public AjaxResult startOrStop(Long id,Boolean enable){
return toAjax(weUserService.startOrStop(id,enable));
}
// /**
// * 删除通讯录相关客户
// */
// @PreAuthorize("@ss.hasPermi('wecom:user:remove')")
// @Log(title = "通讯录相关客户", businessType = BusinessType.DELETE)
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable Long[] ids)
// {
// return toAjax(weUserService.deleteWeUserByIds(ids));
// }
}
......@@ -11,5 +11,10 @@ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
<setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 -->
<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> 驼峰式命名 -->
</settings>
<typeHandlers>
<typeHandler handler="com.linkwechat.framework.handler.LongArrayJoinTypeHandler"/>
</typeHandlers>
</configuration>
......@@ -23,4 +23,16 @@ public class WeConstans {
* 企业微信端根部门id
*/
public static final Long WE_ROOT_DEPARMENT_ID = 1L;
/**
* 企业微信通讯录用户启用
*/
public static final Integer WE_USER_START= 1;
/**
* 企业微信通讯录用户停用
*/
public static final Integer WE_USER_STOP= 0;
}
......@@ -19,36 +19,36 @@ import java.util.List;
**/
@MappedTypes(value = { Integer[].class,Short[].class,Long[].class })
@MappedJdbcTypes(value = JdbcType.VARCHAR)
public class IntArrayJoinTypeHandler extends BaseTypeHandler<Integer[]> {
public class LongArrayJoinTypeHandler extends BaseTypeHandler<Long[]> {
String split = ",";
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType)
public void setNonNullParameter(PreparedStatement ps, int i, Long[] parameter, JdbcType jdbcType)
throws SQLException {
ps.setString(i, StringUtils.join(parameter, split));
}
@Override
public Integer[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
public Long[] 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);
List<Long> idList = new ArrayList<>(arrs.length);
for (String id : arrs) {
if (id != null && id.length() > 0) {
idList.add(Integer.valueOf(id));
idList.add(Long.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
return idList.toArray(new Long[idList.size()]);
}
return null;
}
@Override
public Integer[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
public Long[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String reString = rs.getString(columnIndex);
if (reString != null && reString.length() > 0) {
String[] arrs = reString.split(split);
......@@ -59,13 +59,13 @@ public class IntArrayJoinTypeHandler extends BaseTypeHandler<Integer[]> {
idList.add(Integer.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
return idList.toArray(new Long[idList.size()]);
}
return null;
}
@Override
public Integer[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
public Long[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String reString = cs.getString(columnIndex);
if (reString != null && reString.length() > 0) {
String[] arrs = reString.split(split);
......@@ -76,7 +76,7 @@ public class IntArrayJoinTypeHandler extends BaseTypeHandler<Integer[]> {
idList.add(Integer.valueOf(id));
}
}
return idList.toArray(new Integer[idList.size()]);
return idList.toArray(new Long[idList.size()]);
}
return null;
}
......
......@@ -103,7 +103,7 @@ public class WeUser extends BaseEntity
/** 是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 */
@ApiModelProperty("是否激活(1:是;2:否)该字段主要表示当前信息是否同步微信 ")
private Integer isActivate=new Integer(1);
private Integer isActivate=new Integer(2);
/** 转化成企业微信需要的dto对象 */
......
package com.linkwechat.wecom.mapper;
import java.util.List;
import com.linkwechat.wecom.domain.WeUser;
import java.util.List;
/**
* 通讯录相关客户Mapper接口
*
......@@ -60,10 +61,4 @@ public interface WeUserMapper
public int deleteWeUserByIds(Long[] ids);
/**
* 根据部门id获取员工
* @param departmentId
* @return
*/
public List<WeUser> findWeUsersByDepartmentId(Long departmentId);
}
package com.linkwechat.wecom.service;
import java.util.List;
import com.linkwechat.wecom.domain.WeUser;
import java.util.List;
/**
* 通讯录相关客户Service接口
*
......@@ -66,5 +67,8 @@ public interface IWeUserService
* @param enable
* @return
*/
public int startOrStop(Long id,Integer enable);
public int startOrStop(Long id,Boolean enable);
}
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.WeUser;
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;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.service.IWeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 通讯录相关客户Service业务层处理
......@@ -60,6 +60,7 @@ public class WeUserServiceImpl implements IWeUserService
* @return 结果
*/
@Override
@Transactional
public int insertWeUser(WeUser weUser)
{
......@@ -86,6 +87,7 @@ public class WeUserServiceImpl implements IWeUserService
* @return 结果
*/
@Override
@Transactional
public int updateWeUser(WeUser weUser)
{
int returnCode = weUserMapper.updateWeUser(weUser);
......@@ -137,7 +139,8 @@ public class WeUserServiceImpl implements IWeUserService
* @return
*/
@Override
public int startOrStop(Long id, Integer enable) {
@Transactional
public int startOrStop(Long id, Boolean enable) {
int returnCode = -1;
......@@ -145,7 +148,7 @@ public class WeUserServiceImpl implements IWeUserService
if(null != weUser){
weUser.setEnable(enable);
weUser.setEnable(enable?WeConstans.WE_USER_START:WeConstans.WE_USER_STOP);
returnCode=updateWeUser(weUser);
}
......@@ -154,4 +157,7 @@ public class WeUserServiceImpl implements IWeUserService
return returnCode;
}
}
......@@ -14,9 +14,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="mobile" column="mobile" />
<result property="email" column="email" />
<result property="wxAccount" column="wx_account" />
<result property="department" column="department" typeHandler="com.linkwechat.framework.handler.IntArrayJoinTypeHandler" />
<result property="department" column="department" typeHandler="com.linkwechat.framework.handler.LongArrayJoinTypeHandler" />
<result property="position" column="position" />
<result property="isLeaderInDept" column="is_leader_in_dept" typeHandler="com.linkwechat.framework.handler.IntArrayJoinTypeHandler" />
<result property="isLeaderInDept" column="is_leader_in_dept" typeHandler="com.linkwechat.framework.handler.LongArrayJoinTypeHandler" />
<result property="joinTime" column="join_time" />
<result property="enable" column="enable" />
<result property="idCard" column="id_card" />
......@@ -43,7 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mobile != null and mobile != ''"> and mobile = #{mobile}</if>
<if test="email != null and email != ''"> and email = #{email}</if>
<if test="wxAccount != null and wxAccount != ''"> and wx_account = #{wxAccount}</if>
<if test="department != null and department != ''"> and department = #{department}</if>
<if test="department != null and department != ''"> and FIND_IN_SET(#{department},department)</if>
<if test="position != null and position != ''"> and position = #{position}</if>
<if test="isLeaderInDept != null "> and is_leader_in_dept = #{isLeaderInDept}</if>
<if test="joinTime != null "> and join_time = #{joinTime}</if>
......@@ -97,9 +97,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mobile != null and mobile != ''">#{mobile},</if>
<if test="email != null">#{email},</if>
<if test="wxAccount != null">#{wxAccount},</if>
<if test="department != null">#{department},</if>
<if test="department != null" >#{department,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.LongArrayJoinTypeHandler},</if>
<if test="position != null">#{position},</if>
<if test="isLeaderInDept != null">#{isLeaderInDept},</if>
<if test="isLeaderInDept != null">#{isLeaderInDept,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.LongArrayJoinTypeHandler},</if>
<if test="joinTime != null">#{joinTime},</if>
<if test="enable != null">#{enable},</if>
<if test="idCard != null">#{idCard},</if>
......@@ -150,10 +150,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</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!