Commit c156f5be by duanhq

用户管理 by duanht 2019/1/4

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@16306 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 74ab33da
package com.glsx.common.utils;
/**
* 对字符串解密与解密功能
*
*/
public final class EncryptUtil {
//默认字符编码
private static final String CHARSET_UTF8 = "UTF-8" ;
//盐
private static final byte[] SLAT_ARRAY = new byte[] {24,17,61,78,9,45,13,55};
//密钥种子
private static final String PWD_ARRAY = "web4sVMS";
/**
* 对v值进行加密,加密后以base64编码格式输出,如果加密失败,则返回null。
* @param v :java.lang.String,需要进行加密的值
* @param t :java.lang.String,8位日期字符串
* @return java.lang.String
*/
public static String PBEEncrypt(String v) {
try {
return StringUtils.trim(Encrypter.encryptBASE64(PBEEncrypter.encrypt(v.getBytes(CHARSET_UTF8),PWD_ARRAY,SLAT_ARRAY)));
} catch (Exception e) {
return null ;
}
}
/**
* 对v值进行解密,解密后以base64编码格式输出,如果解密失败,则返回null。
* @param v :java.lang.String,需要进行解密的值
* @param t :java.lang.String,8位日期字符串
* @return java.lang.String
*/
public static String PBEDecrypt(String v) {
try {
return new String(PBEEncrypter.decrypt(PBEEncrypter.decryptBASE64(v),PWD_ARRAY,SLAT_ARRAY));
} catch (Exception e) {
return null ;
}
}
public static void main(String[] args) {
String a = "r8jeKkyiu+RFgmHbN+jBQsCtyptN0QKn";
String t = PBEEncrypt(a);
System.out.println(a);
System.out.println(t);
System.out.println(PBEDecrypt(a));
}
}
package com.glsx.common.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.MessageDigest;
/**
* 基础加密组件
*
*/
public abstract class Encrypter {
public static final String KEY_SHA = "SHA";
public static final String KEY_MD5 = "MD5";
/**
* MAC 算法可选以下多种算法
*
* <pre>
* HmacMD5
* HmacSHA1
* HmacSHA256
* HmacSHA384
* HmacSHA512
* </pre>
*/
public static final String KEY_MAC = "HmacMD5";
/**
* BASE64 解密
*
* @param key
* @return
* @throws Exception
*/
public static byte[] decryptBASE64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* BASE64 加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE64(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}
/**
* MD5 加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptMD5(byte[] data) throws Exception {
MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
md5.update(data);
return md5.digest();
}
/**
* SHA 加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptSHA(byte[] data) throws Exception {
MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
sha.update(data);
return sha.digest();
}
/**
* 初始化HMAC密钥
*
* @return
* @throws Exception
*/
public static String initMacKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_MAC);
SecretKey secretKey = keyGenerator.generateKey();
return encryptBASE64(secretKey.getEncoded());
}
/**
* HMAC 加密
*
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] encryptHMAC(byte[] data, String key) throws Exception {
SecretKey secretKey = new SecretKeySpec(decryptBASE64(key), KEY_MAC);
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
return mac.doFinal(data);
}
public static String encoder(String str){
return (new BASE64Encoder()).encode(str.getBytes());
}
public static String deEncoder(String str){
try {
return new String((new BASE64Decoder()).decodeBuffer(str));
} catch (IOException e) {
return null;
}
}
}
\ No newline at end of file
package com.glsx.common.utils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.security.Key;
import java.util.Random;
/**
* PBE 安全编码组件
*
*/
public abstract class PBEEncrypter extends Encrypter {
/**
* 支持以下任意一种算法
*
* <pre>
* PBEWithMD5AndDES
* PBEWithMD5AndTripleDES
* PBEWithSHA1AndDESede
* PBEWithSHA1AndRC2_40
* </pre>
*/
public static final String ALGORITHM = "PBEWithSHA1AndDESede";
/**
* 盐初始化
*
* @return
* @throws Exception
*/
public static byte[] initSalt() throws Exception {
byte[] salt = new byte[8];
Random random = new Random();
random.nextBytes(salt);
return salt;
}
/**
* 转换密钥<br>
*
* @param password
* @return
* @throws Exception
*/
private static Key toKey(String password) throws Exception {
PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey secretKey = keyFactory.generateSecret(keySpec);
return secretKey;
}
/**
* 加密
*
* @param data
* 数据
* @param password
* 密码
* @param salt
* 盐
* @return
* @throws Exception
*/
public static byte[] encrypt(byte[] data, String password, byte[] salt)
throws Exception {
Key key = toKey(password);
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 100);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
return cipher.doFinal(data);
}
/**
* 解密
*
* @param data
* 数据
* @param password
* 密码
* @param salt
* 盐
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] data, String password, byte[] salt)
throws Exception {
Key key = toKey(password);
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 100);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
return cipher.doFinal(data);
}
}
\ No newline at end of file
package com.glsx.manager.controller;
import com.github.pagehelper.PageHelper;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.EncryptUtil;
import com.glsx.common.utils.Page;
import com.glsx.manager.constants.ResultCodeEnum;
import com.glsx.manager.pojo.user.SysUser;
import com.glsx.manager.pojo.vo.UserQueryVo;
import com.glsx.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author duanht
* @version 1.0.0
* @Title UserController
* @Package com.glsx.manager.controller
* @Description TODO 用户信息管理
* @date 2018/12/26 10:16
*/
@RestController
@RequestMapping(value = "/user")
public class UserController extends BaseController {
@Autowired
UserService userService;
/**
* @param userQueryVo
* @return ResultObject
* @author duanht
* @Title: getUserList
* @Description: TODO 获取用户列表
*/
@RequestMapping(value = "/getUserList", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public ResultObject getUserList(Page page, UserQueryVo userQueryVo) {
Map<String, Object> result = new HashMap<String, Object>(16);
PageHelper.startPage(page.getPageIndex(), page.getPageSize(), true);
//测试
userQueryVo.setUserId(17);
List<SysUser> list = userService.getUserList(userQueryVo);
com.github.pagehelper.Page<SysUser> pages = (com.github.pagehelper.Page<SysUser>) list;
page.setTotalCount((int) pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
/**
* @param record
* @return ResultObject
* @author duanht
* @Title: saveUser
* @Description: (新增, 编辑)用户
*/
@RequestMapping(value = "/saveUser")
@ResponseBody
public ResultObject saveUser(@RequestBody SysUser record) {
SysUser user = userService.selectByPrimaryKey(record.getId());
if (user == null) {
// 新增用户
if (!userService.findByUserName(record.getUsername()).isEmpty()) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "用户信息已存在");
}
record.setPassword(EncryptUtil.PBEEncrypt(record.getPassword()));
record.setCreateTime(DateUtil.getCurrentDate());
//测试
record.setCreateBy("1");
}
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), userService.save(record));
}
/**
* @param sysUser
* @return ResultObject
* @author duanht
* @Title: updatePassword
* @Description: TODO 重置用户密码
*/
@RequestMapping(value = "/updatePassword", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public ResultObject updatePassword(SysUser sysUser) {
sysUser.setPassword(EncryptUtil.PBEEncrypt(sysUser.getPassword()));
int result = userService.updatePassword(sysUser);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
/**
* @param id
* @return ResultObject
* @author duanht
* @Title: getUserById
* @Description: TODO 根据用户id获取用户信息
*/
@RequestMapping(value = "/getUserById", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public ResultObject getUserById(Integer id) {
SysUser result = userService.getUserById(id);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
/**
* @param id
* @return ResultObject
* @author duanht
* @Title: deleteUser
* @Description: TODO 注销用户
*/
@RequestMapping(value = "/deleteUser", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public ResultObject deleteUser(@RequestParam("id[]") List<Integer> id) {
int result = userService.deleteUser(id);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
}
......@@ -2,8 +2,12 @@ package com.glsx.manager.mapper;
import java.util.List;
import com.glsx.manager.pojo.menu.SysOrganization;
import com.glsx.manager.pojo.user.SysUser;
import com.glsx.manager.pojo.user.SysUserExample;
import com.glsx.manager.pojo.user.SysUserOrg;
import com.glsx.manager.pojo.user.SysUserRole;
import com.glsx.manager.pojo.vo.UserQueryVo;
import org.apache.ibatis.annotations.Param;
......@@ -33,4 +37,7 @@ public interface SysUserMapper {
List<SysUser> getUserList(UserQueryVo userQueryVo);
int deleteUserById(List<Integer> id);
SysUser getUserById(Integer id);
}
\ No newline at end of file
package com.glsx.manager.mapper;
import com.glsx.manager.pojo.user.SysUserRole;
import com.glsx.manager.pojo.user.SysUserOrg;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysUserOrgMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Integer id);
int insert(SysUserRole record);
int insert(SysUserOrg record);
int insertSelective(SysUserRole record);
int insertSelective(SysUserOrg record);
SysUserRole selectByPrimaryKey(Integer id);
SysUserOrg selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SysUserRole record);
int updateByPrimaryKeySelective(SysUserOrg record);
int updateByPrimaryKey(SysUserRole record);
int updateByPrimaryKey(SysUserOrg record);
List<SysUserRole> findUserOrgs(@Param(value = "userId") Integer userId);
List<SysUserOrg> findUserOrgs(@Param(value = "userId") Integer userId);
int deleteByUserId(@Param(value = "userId") int userId);
List<SysUserOrg> getOrgByUserId(Integer id);
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ public interface SysUserRoleMapper {
int insertSelective(SysUserRole record);
SysUserRole selectByPrimaryKey(Long id);
SysUserRole selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SysUserRole record);
......@@ -19,4 +19,6 @@ public interface SysUserRoleMapper {
List<SysUserRole> findUserRoles(@Param(value="userId") Long userId);
int deleteByUserId(@Param(value="userId") int userId);
List<SysUserRole> getRoleByUserId(Integer id);
}
\ No newline at end of file
......@@ -13,9 +13,9 @@ public class SysUser extends BaseModel {
private Integer orgId;
private Integer phoneNumber;
private String phoneNumber;
private Byte userStatus;
private Integer userStatus;
private String password;
......@@ -25,7 +25,13 @@ public class SysUser extends BaseModel {
private String occupation;
private List<SysUserRole> userRoles = new ArrayList<>();
private List<Integer> rolesId = new ArrayList<>();
private List<Integer> orgsId = new ArrayList<>();
private List<SysUserRole> sysUserRole = new ArrayList<>();
private List<SysUserOrg> sysUserOrg = new ArrayList<>();
public String getUsername() {
return username;
......@@ -51,19 +57,19 @@ public class SysUser extends BaseModel {
this.orgId = orgId;
}
public Integer getPhoneNumber() {
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(Integer phoneNumber) {
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Byte getUserStatus() {
public Integer getUserStatus() {
return userStatus;
}
public void setUserStatus(Byte userStatus) {
public void setUserStatus(Integer userStatus) {
this.userStatus = userStatus;
}
......@@ -99,11 +105,36 @@ public class SysUser extends BaseModel {
this.occupation = occupation == null ? null : occupation.trim();
}
public List<SysUserRole> getUserRoles() {
return userRoles;
public List<SysUserRole> getSysUserRole() {
return sysUserRole;
}
public void setSysUserRole(List<SysUserRole> sysUserRole) {
this.sysUserRole = sysUserRole;
}
public List<SysUserOrg> getSysUserOrg() {
return sysUserOrg;
}
public void setSysUserOrg(List<SysUserOrg> sysUserOrg) {
this.sysUserOrg = sysUserOrg;
}
public List<Integer> getRolesId() {
return rolesId;
}
public void setRolesId(List<Integer> rolesId) {
this.rolesId = rolesId;
}
public List<Integer> getOrgsId() {
return orgsId;
}
public void setUserRoles(List<SysUserRole> userRoles) {
this.userRoles = userRoles;
public void setOrgsId(List<Integer> orgsId) {
this.orgsId = orgsId;
}
}
\ No newline at end of file
}
package com.glsx.manager.pojo.user;
import com.glsx.manager.pojo.BaseModel;
public class SysUserOrg {
public class SysUserOrg extends BaseModel {
private Integer id;
private Integer userId;
private Integer orgId;
private String orgName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getOrgName() {
return orgName;
}
public void setOrgName(String orgName) {
this.orgName = orgName;
}
public Integer getUserId() {
return userId;
}
......
package com.glsx.manager.pojo.user;
import com.glsx.manager.pojo.BaseModel;
public class SysUserRole {
public class SysUserRole extends BaseModel {
private Integer id;
private Integer userId;
private Integer roleId;
private String roleName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Integer getUserId() {
return userId;
}
......
......@@ -13,7 +13,7 @@ public class UserQueryVo extends BaseQueryVo {
/**
*登录名称
*/
private int loginName;
private int userName;
/**
* 用户状态
......@@ -29,12 +29,12 @@ public class UserQueryVo extends BaseQueryVo {
}
public int getLoginName() {
return loginName;
public int getUserName() {
return userName;
}
public void setLoginName(int loginName) {
this.loginName = loginName;
public void setUserName(int userName) {
this.userName = userName;
}
public int getUserStatus() {
......@@ -49,7 +49,7 @@ public class UserQueryVo extends BaseQueryVo {
public String toString() {
return "UserQueryVo{" +
"idList=" + idList +
", loginName=" + loginName +
", userName=" + userName +
", userStatus=" + userStatus +
'}';
}
......
package com.glsx.manager.service;
import com.glsx.manager.pojo.user.SysUser;
import com.glsx.manager.pojo.vo.UserQueryVo;
import java.util.List;
/**
* @author duanht
* @version 1.0.0
* @Title UserService
* @Package com.glsx.manager.service
* @Description TODO 用户信息管理
* @date 2018/12/26 10:26
*/
public interface UserService {
/**
* @author duanht
* @Title: getUserList
* @Description: TODO 获取用户列表
* @param userQueryVo
* @return List<SysUser>
*/
List<SysUser> getUserList(UserQueryVo userQueryVo);
/**
* @author duanht
* @Title: selectByPrimaryKey
* @Description: TODO 根据主键查询用户信息
* @param id
* @return SysUser
*/
SysUser selectByPrimaryKey(Integer id);
/**
* @author duanht
* @Title: deleteUser
* @Description: TODO 注销用户
* @param id
* @return int
*/
int deleteUser(List<Integer> id);
/**
* @author duanht
* @Title: findByName
* @Description: TODO 根据用户名查询用户信息
* @param userName
* @return int
*/
List<SysUser> findByUserName(String userName);
/**
* @author duanht
* @Title: save
* @Description: TODO 保存用户信息
* @param record
* @return int
*/
int save(SysUser record);
/**
* @author duanht
* @Title: resetPassword
* @Description: TODO 修改用户密码
* @param sysUser
* @return int
*/
int updatePassword(SysUser sysUser);
/**
* @author duanht
* @Title: getUserById
* @Description: TODO 根据id查询用户信息
* @param id
* @return SysUser
*/
SysUser getUserById(Integer id);
}
package com.glsx.manager.service.impl;
import com.glsx.common.utils.DateUtil;
import com.glsx.manager.mapper.SysUserMapper;
import com.glsx.manager.mapper.SysUserOrgMapper;
import com.glsx.manager.mapper.SysUserRoleMapper;
import com.glsx.manager.pojo.menu.SysOrganization;
import com.glsx.manager.pojo.role.SysRole;
import com.glsx.manager.pojo.user.SysUser;
import com.glsx.manager.pojo.user.SysUserExample;
import com.glsx.manager.pojo.user.SysUserOrg;
import com.glsx.manager.pojo.user.SysUserRole;
import com.glsx.manager.pojo.vo.UserQueryVo;
import com.glsx.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* @author duanht
* @version 1.0.0
* @Title UserServiceImpl
* @Package com.glsx.manager.service.impl
* @Description TODO 用户信息管理
* @date 2018/12/26 10:26
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private SysUserRoleMapper sysUserRoleMapper;
@Autowired
private SysUserOrgMapper sysUserOrgMapper;
@Override
public List<SysUser> getUserList(UserQueryVo userQueryVo) {
return sysUserMapper.getUserList(userQueryVo);
}
@Override
public SysUser selectByPrimaryKey(Integer id) {
return sysUserMapper.selectByPrimaryKey(id);
}
@Override
public int deleteUser(List<Integer> id) {
return sysUserMapper.deleteUserById(id);
}
@Override
public List<SysUser> findByUserName(String userName) {
SysUserExample sysUserExample = new SysUserExample();
SysUserExample.Criteria criteria = sysUserExample.createCriteria();
criteria.andUsernameEqualTo(userName);
criteria.andUserStatusEqualTo(Byte.valueOf("1"));
return sysUserMapper.selectByExample(sysUserExample);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(SysUser record) {
//性别默认为未知
if (record.getSex() == null) {
record.setSex("3");
}
record.setUpdateBy("1");
record.setUpdateTime(DateUtil.getCurrentDate());
Integer user_id = null;
if (record.getId() == null || record.getId() == 0) {
// 新增用户
sysUserMapper.insertSelective(record);
user_id = record.getId();
} else {
// 更新用户信息
sysUserMapper.updateByPrimaryKeySelective(record);
}
List<SysUserRole> sysUserRoles = new ArrayList<>();
List<SysUserOrg> sysUserOrgs = new ArrayList<>();
// 更新用户角色和用户数据权限
if (user_id != null) {
for (Integer rolesId : record.getRolesId()) {
SysUserRole sysUserRole = new SysUserRole();
sysUserRole.setUserId(user_id);
sysUserRole.setRoleId(rolesId);
sysUserRoles.add(sysUserRole);
}
for (Integer orgId : record.getOrgsId()) {
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setUserId(user_id);
sysUserOrg.setOrgId(orgId);
sysUserOrgs.add(sysUserOrg);
}
} else {
sysUserRoleMapper.deleteByUserId(record.getId());
sysUserOrgMapper.deleteByUserId(record.getId());
}
for (SysUserRole sysUserRole : sysUserRoles) {
sysUserRoleMapper.insertSelective(sysUserRole);
}
for (SysUserOrg sysUserOrg : sysUserOrgs) {
sysUserOrgMapper.insertSelective(sysUserOrg);
}
return 1;
}
@Override
public int updatePassword(SysUser sysUser) {
return sysUserMapper.updateByPrimaryKeySelective(sysUser);
}
@Override
public SysUser getUserById(Integer id) {
SysUser sysUser = sysUserMapper.selectByPrimaryKey(id);
List<SysUserRole> sysRole = sysUserRoleMapper.getRoleByUserId(id);
List<SysUserOrg> sysOrg = sysUserOrgMapper.getOrgByUserId(id);
sysUser.setSysUserRole(sysRole);
sysUser.setSysUserOrg(sysOrg);
return sysUser;
}
}
......@@ -6,7 +6,7 @@
<result column="username" jdbcType="VARCHAR" property="username" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="org_id" jdbcType="INTEGER" property="orgId" />
<result column="phone_number" jdbcType="INTEGER" property="phoneNumber" />
<result column="phone_number" jdbcType="VARCHAR" property="phoneNumber" />
<result column="user_status" jdbcType="TINYINT" property="userStatus" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
......@@ -121,7 +121,7 @@
password, mail, sex,
occupation, remark)
values (#{username,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{orgId,jdbcType=INTEGER},
#{phoneNumber,jdbcType=INTEGER}, #{userStatus,jdbcType=TINYINT}, #{createBy,jdbcType=VARCHAR},
#{phoneNumber,jdbcType=VARCHAR}, #{userStatus,jdbcType=TINYINT}, #{createBy,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{password,jdbcType=VARCHAR}, #{mail,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR},
#{occupation,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR})
......@@ -186,7 +186,7 @@
#{orgId,jdbcType=INTEGER},
</if>
<if test="phoneNumber != null">
#{phoneNumber,jdbcType=INTEGER},
#{phoneNumber,jdbcType=VARCHAR},
</if>
<if test="userStatus != null">
#{userStatus,jdbcType=TINYINT},
......@@ -242,7 +242,7 @@
org_id = #{record.orgId,jdbcType=INTEGER},
</if>
<if test="record.phoneNumber != null">
phone_number = #{record.phoneNumber,jdbcType=INTEGER},
phone_number = #{record.phoneNumber,jdbcType=VARCHAR},
</if>
<if test="record.userStatus != null">
user_status = #{record.userStatus,jdbcType=TINYINT},
......@@ -285,7 +285,7 @@
username = #{record.username,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
org_id = #{record.orgId,jdbcType=INTEGER},
phone_number = #{record.phoneNumber,jdbcType=INTEGER},
phone_number = #{record.phoneNumber,jdbcType=VARCHAR},
user_status = #{record.userStatus,jdbcType=TINYINT},
create_by = #{record.createBy,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
......@@ -313,7 +313,7 @@
org_id = #{orgId,jdbcType=INTEGER},
</if>
<if test="phoneNumber != null">
phone_number = #{phoneNumber,jdbcType=INTEGER},
phone_number = #{phoneNumber,jdbcType=VARCHAR},
</if>
<if test="userStatus != null">
user_status = #{userStatus,jdbcType=TINYINT},
......@@ -353,7 +353,7 @@
set username = #{username,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
org_id = #{orgId,jdbcType=INTEGER},
phone_number = #{phoneNumber,jdbcType=INTEGER},
phone_number = #{phoneNumber,jdbcType=VARCHAR},
user_status = #{userStatus,jdbcType=TINYINT},
create_by = #{createBy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
......@@ -370,12 +370,12 @@
<select id="getUserList" parameterType="com.glsx.manager.pojo.vo.UserQueryVo" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_user_data ud LEFT JOIN sys_user u ON ud.data_id = u.department WHERE ud.id = #{id,jdbcType=VARCHAR}
<if test="loginName != null">
and u.loginName like #{loginName,jdbcType=VARCHAR}
from sys_user_org uo LEFT JOIN sys_user u ON uo.org_id = u.org_id WHERE uo.user_id = #{id,jdbcType=VARCHAR}
<if test="userName != null">
and u.userName like #{userName,jdbcType=VARCHAR}
</if>
<if test="userStatus != null">
and u.userStatus like #{userStatus,jdbcType=TINYINT}
and u.user_status &lt;&gt; #{userStatus,jdbcType=TINYINT}
</if>
<if test="sTime != null and eTime!=null and sTime !='' and eTime !=''">
and u.createTime between #{sTime,jdbcType=TIMESTAMP} and #{eTime,jdbcType=TIMESTAMP}
......@@ -385,7 +385,7 @@
<update id="deleteUserById" parameterType="java.util.List" >
update sys_user
set status = 2
set user_status = 2
where id in
<foreach collection="list" index="index" item="id"
separator="," open="(" close=")">
......@@ -394,4 +394,7 @@
</update>
</mapper>
\ No newline at end of file
......@@ -7,26 +7,26 @@
<result column="org_id" jdbcType="INTEGER" property="org_id" />
</resultMap>
<sql id="Base_Column_List">
id, user_id, role_id
id, user_id, org_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_user_role
from sys_user_org
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sys_user_role
delete from sys_user_org
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.glsx.manager.pojo.user.SysUserRole">
insert into sys_user_role (id, user_id, role_id
<insert id="insert" parameterType="com.glsx.manager.pojo.user.SysUserOrg">
insert into sys_user_org (id, user_id, org_id
)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{orgId,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.glsx.manager.pojo.user.SysUserRole">
insert into sys_user_role
<insert id="insertSelective" parameterType="com.glsx.manager.pojo.user.SysUserOrg">
insert into sys_user_org
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
......@@ -34,8 +34,8 @@
<if test="userId != null">
user_id,
</if>
<if test="roleId != null">
role_id,
<if test="orgId != null">
org_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
......@@ -45,37 +45,42 @@
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="roleId != null">
#{roleId,jdbcType=INTEGER},
<if test="orgId != null">
#{orgId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.glsx.manager.pojo.user.SysUserRole">
update sys_user_role
<update id="updateByPrimaryKeySelective" parameterType="com.glsx.manager.pojo.user.SysUserOrg">
update sys_user_org
<set>
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="roleId != null">
role_id = #{roleId,jdbcType=INTEGER},
<if test="orgId != null">
org_id = #{orgId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.glsx.manager.pojo.user.SysUserRole">
update sys_user_role
<update id="updateByPrimaryKey" parameterType="com.glsx.manager.pojo.user.SysUserOrg">
update sys_user_org
set user_id = #{userId,jdbcType=INTEGER},
role_id = #{roleId,jdbcType=INTEGER}
org_id = #{orgId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="findUserRoles" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<select id="findUserOrgs" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_user_role
from sys_user_org
where user_id = #{userId,jdbcType=INTEGER}
</select>
<delete id="deleteByUserId" parameterType="java.lang.Integer">
delete from sys_user_role
delete from sys_user_org
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<select id="getOrgByUserId" parameterType="java.lang.Integer" resultType="com.glsx.manager.pojo.user.SysUserOrg">
SELECT so.id userId ,so.name orgName from sys_user su LEFT JOIN sys_user_org suo on su.id = suo.user_id
LEFT JOIN sys_organization so on suo.org_id = so.id WHERE su.id = #{id,jdbcType=TINYINT}
</select>
</mapper>
\ No newline at end of file
......@@ -78,4 +78,9 @@
delete from sys_user_role
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<select id="getRoleByUserId" parameterType="java.lang.Integer" resultType="com.glsx.manager.pojo.user.SysUserRole">
SELECT sr.id userId,sr.role_name roleName from sys_user su LEFT JOIN sys_user_role sur on su.id = sur.user_id
LEFT JOIN sys_role sr on sur.role_id = sr.id WHERE su.id = #{id,jdbcType=TINYINT}
</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!