用户接口
This commit is contained in:
parent
57945dce3e
commit
b2ccb03e33
|
|
@ -0,0 +1,59 @@
|
|||
package com.securitycontrol.system.base.controller;
|
||||
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||
import com.securitycontrol.entity.system.dto.UserDto;
|
||||
import com.securitycontrol.entity.system.vo.UserVo;
|
||||
import com.securitycontrol.system.base.service.IUserService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-02-20-15:49
|
||||
* @version:1.0
|
||||
* @description:用户管理-web
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/user/")
|
||||
public class UserController extends BaseController {
|
||||
|
||||
@Resource(name = "IUserService")
|
||||
private IUserService service;
|
||||
|
||||
@ApiOperation(value = "获取用户列表")
|
||||
@GetMapping("getUserLists")
|
||||
public TableDataInfo getUserLists(UserDto dto) {
|
||||
startPage();
|
||||
List<UserVo> list = service.getUserLists(dto);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增用户")
|
||||
@PostMapping("addUser")
|
||||
public AjaxResult addUser(@RequestBody UserVo vo){
|
||||
return service.addOrUpdateUser(vo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改用户")
|
||||
@PostMapping("editUser")
|
||||
public AjaxResult editUser(@RequestBody UserVo vo){
|
||||
return service.addOrUpdateUser(vo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户详情")
|
||||
@GetMapping("getUserById")
|
||||
public AjaxResult getUserById(UserDto dto){
|
||||
return service.getUserById(dto);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除用户")
|
||||
@PostMapping("delUser")
|
||||
public AjaxResult delUser(UserDto dto){
|
||||
return service.delUser(dto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.securitycontrol.system.base.mapper;
|
||||
|
||||
import com.securitycontrol.entity.system.dto.UserDto;
|
||||
import com.securitycontrol.entity.system.vo.UserVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-02-20-15:49
|
||||
* @version:1.0
|
||||
* @description:用户管理-数据库访问层
|
||||
*/
|
||||
@Repository(value = "IUserMapper")
|
||||
public interface IUserMapper {
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*
|
||||
* @param dto
|
||||
* @return List<UserVo>
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 16:37
|
||||
*/
|
||||
List<UserVo> getUserLists(UserDto dto);
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
* @param dto
|
||||
* @return UserVo
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:34
|
||||
*/
|
||||
UserVo getUserById(UserDto dto);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param dto
|
||||
* @description
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:39
|
||||
*/
|
||||
void delUser(UserDto dto);
|
||||
|
||||
/**
|
||||
* 新增/修改用户
|
||||
* @param vo
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:39
|
||||
*/
|
||||
void addOrUpdateUser(UserVo vo);
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.securitycontrol.system.base.service;
|
||||
|
||||
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||
import com.securitycontrol.entity.system.dto.UserDto;
|
||||
import com.securitycontrol.entity.system.vo.UserVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-02-20-15:49
|
||||
* @version:1.0
|
||||
* @description:用户管理-业务逻辑层
|
||||
*/
|
||||
public interface IUserService {
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*
|
||||
* @param dto
|
||||
* @return List<UserVo>
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 16:31
|
||||
*/
|
||||
List<UserVo> getUserLists(UserDto dto);
|
||||
|
||||
/**
|
||||
* 新增/修改用户
|
||||
*
|
||||
* @param vo
|
||||
* @return AjaxResult
|
||||
* @description
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:27
|
||||
*/
|
||||
AjaxResult addOrUpdateUser(UserVo vo);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param dto
|
||||
* @return AjaxResult
|
||||
* @description
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:29
|
||||
*/
|
||||
AjaxResult delUser(UserDto dto);
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
* @param dto
|
||||
* @return AjaxResult
|
||||
* @description
|
||||
* @author cwchen
|
||||
* @date 2024/2/20 17:31
|
||||
*/
|
||||
AjaxResult getUserById(UserDto dto);
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.securitycontrol.system.base.service.impl;
|
||||
|
||||
import com.securitycontrol.common.core.exception.ServiceException;
|
||||
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||
import com.securitycontrol.entity.system.dto.UserDto;
|
||||
import com.securitycontrol.entity.system.vo.UserVo;
|
||||
import com.securitycontrol.system.base.mapper.IUserMapper;
|
||||
import com.securitycontrol.system.base.service.IUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
* @date:2024-02-20-15:49
|
||||
* @version:1.0
|
||||
* @description:用户管理-业务层
|
||||
*/
|
||||
@Service(value = "IUserService")
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements IUserService {
|
||||
|
||||
@Resource(name = "IUserMapper")
|
||||
private IUserMapper mapper;
|
||||
|
||||
@Override
|
||||
public List<UserVo> getUserLists(UserDto dto) {
|
||||
List<UserVo> list = new ArrayList<>();
|
||||
list = mapper.getUserLists(dto);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult addOrUpdateUser(UserVo vo) {
|
||||
try {
|
||||
if (vo.getUserId() != null) {
|
||||
vo.setType(2);
|
||||
} else {
|
||||
vo.setType(1);
|
||||
}
|
||||
mapper.addOrUpdateUser(vo);
|
||||
} catch (Exception e) {
|
||||
log.error("用户",e);
|
||||
//手动回滚异常
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return AjaxResult.error();
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult delUser(UserDto dto) {
|
||||
mapper.delUser(dto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult getUserById(UserDto dto) {
|
||||
UserVo vo = new UserVo();
|
||||
vo = mapper.getUserById(dto);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?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.securitycontrol.system.base.mapper.IUserMapper">
|
||||
<!--新增/修改用户-->
|
||||
<insert id="addOrUpdateUser">
|
||||
<if test="type == 1">
|
||||
INSERT INTO sys_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userName != null and userName != ''">user_name,</if>
|
||||
<if test="loginName != null and loginName!=''">login_name,</if>
|
||||
<if test="password != null and password !=''">password,</if>
|
||||
<if test="orgId != null and orgId!=''">org_id,</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
||||
<if test="orgName != null and orgName != ''">org_name,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userName != null and userName != ''">#{userName},</if>
|
||||
<if test="loginName != null and loginName!=''">#{loginName},</if>
|
||||
<if test="password != null and password !=''">#{password},</if>
|
||||
<if test="orgId != null and orgId!=''">#{orgId},</if>
|
||||
<if test="deptName != null and deptName != ''">#{deptName},</if>
|
||||
<if test="orgName != null and orgName != ''">#{orgName},</if>
|
||||
</trim>
|
||||
</if>
|
||||
<if test="type == 2">
|
||||
UPDATE sys_user
|
||||
<set>
|
||||
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||||
<if test="orgId != null and orgId != ''">org_id = #{orgId},</if>
|
||||
<if test="orgName != null and orgName != ''">org_name = #{orgName},</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
|
||||
</set>
|
||||
WHERE user_id = #{userId}
|
||||
</if>
|
||||
</insert>
|
||||
<!--删除用户-->
|
||||
<update id="delUser">
|
||||
UPDATE sys_user SET del_flag = '1' WHERE user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<!--获取用户列表-->
|
||||
<select id="getUserLists" resultType="com.securitycontrol.entity.system.vo.UserVo">
|
||||
SELECT su.user_id AS userId,
|
||||
su.user_name AS userName,
|
||||
su.login_name AS loginName,
|
||||
su.del_flag AS delFlag,
|
||||
su.phone,
|
||||
su.del_flag AS delFlag
|
||||
FROM sys_user su
|
||||
<where>
|
||||
<if test="userName!=null and userName!=''">
|
||||
INSTR(su.user_name,#{userName}) > 0
|
||||
</if>
|
||||
<if test="loginName!=null and loginName!=''">
|
||||
AND INSTR(su.login_name,#{loginName}) > 0
|
||||
</if>
|
||||
<if test="phone!=null and phone!=''">
|
||||
AND INSTR(su.phone,#{phone}) > 0
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY su.update_time ASC,su.del_flag ASC
|
||||
</select>
|
||||
<!--用户详情-->
|
||||
<select id="getUserById" resultType="com.securitycontrol.entity.system.vo.UserVo">
|
||||
SELECT su.user_id AS userId,
|
||||
su.user_name AS userName,
|
||||
su.login_name AS loginName,
|
||||
su.del_flag AS delFlag,
|
||||
su.phone
|
||||
FROM sys_user su
|
||||
WHERE user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue