Commit 5746e67f authored by Fred's avatar Fred

批量删除

parent b6449fc2
......@@ -73,7 +73,7 @@ public class OAuth2Realm extends AuthorizingRealm {
throw new IncorrectCredentialsException("账号或密码不正确");
}
// 账号锁定
if (Constant.DeleteState.DELETE.getValue() == ue.getState()) {
if (Constant.STATE_LOCK == ue.getState()) {
throw new LockedAccountException("账号已被锁定,请联系管理员");
}
......
......@@ -12,60 +12,18 @@ public class Constant {
/** 超级管理员ID */
public static final int SUPER_ADMIN = 1;
/**
* 菜单类型
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
public enum MenuType {
/**
* 目录
*/
CATALOG(0),
/**
* 菜单
*/
MENU(1),
/**
* 按钮
*/
BUTTON(2);
/** 数据状态 */
public static final int STATE_DELETE = 0;
private Integer value;
public static final int STATE_NORMAL = 1;
public static final int STATE_LOCK = 2;
MenuType(Integer value) {
this.value = value;
}
/** 菜单类型 */
public static final int MENU_CATALOG = 1;
public Integer getValue() {
return value;
}
}
public static final int MENU_MENU = 2;
/**
* 删除状态
*
*/
public enum DeleteState {
/**
* 删除
*/
DELETE(0),
/**
* 正常
*/
NORMAL(1);
public static final int MENU_BUTTON = 3;
private Integer value;
private DeleteState(Integer value) {
this.value = value;
}
public int getValue() {
return value;
}
}
}
......@@ -24,7 +24,7 @@ public class MyMetaObjectHandler extends MetaObjectHandler {
setFieldValByName("createTime", date, metaObject);
setFieldValByName("modifyBy", ue.getId(), metaObject);
setFieldValByName("modifyTime", date, metaObject);
setFieldValByName("state", 1, metaObject);
setFieldValByName("state", Constant.STATE_NORMAL, metaObject);
}
@Override
......
package com.govmade.modules.system.controller;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -10,10 +11,11 @@ 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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Sets;
import com.govmade.common.utils.Constant;
import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R;
......@@ -22,9 +24,7 @@ import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.UserEntity;
import com.govmade.modules.system.service.UserService;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import io.swagger.annotations.ApiOperation;
/**
* 系统管理 - 用户设置
......@@ -62,13 +62,13 @@ public class UserController extends AbstractController {
* 用户列表
*/
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
public R list(Map<String, Object> params) {
// 只有超级管理员,才能查看所有用户列表
if (getUserId() == Constant.SUPER_ADMIN) {
params.put("createBy", getUserId());
} else {
//params.put("deptId", getUser().getDeptId()); // 部门管理员,查看本部门用户列表
// params.put("deptId", getUser().getDeptId()); // 部门管理员,查看本部门用户列表
}
PageUtils page = userService.queryPage(params);
......@@ -86,54 +86,59 @@ public class UserController extends AbstractController {
public R info(@PathVariable("id") Long id) {
return R.ok().put("user", userService.queryById(id));
}
/**
* 删除、批量删除用户
*
* @param ids
* @return
*/
/**
* 删除、批量删除用户
*
* @param ids
* @return
*/
@DeleteMapping("/delete")
public R deleteUser(@RequestParam Set<Long> ids) {
public R deleteUser() {
Set<Long> ids = Sets.newHashSet();
ids.add(1L);
ids.add(2L);
userService.deleteBatch(ids);
return R.ok();
}
userService.deleteBatchIds(ids);
return R.ok();
}
/**
* 重置密码
*
* @param id
* @return
*/
@PostMapping("/reset")
public R reset(UserEntity ue) {
if (null != ue.getId()) {
@PostMapping("/reset")
public R reset(UserEntity ue) {
if (null != ue.getId()) {
String password = SecureUtil.md5("123456");
ue.setPassword(password);
userService.updateById(ue);
}
return R.ok();
}
/**
* 修改登录用户密码
*/
@PutMapping("updatePassword")
public R password(String password, String newPassword) {
password = new Sha256Hash(password).toHex();
newPassword = new Sha256Hash(newPassword).toHex();
//int count = userService.updatePassword(ShiroUtils.getUserId(), password, newPassword);
// if (count == 0) {
// return R.error("原密码不正确");
// }
ShiroUtils.logout();
return R.ok();
}
return R.ok();
}
/**
* 修改登录用户密码
*/
@PutMapping("updatePassword")
public R password(String password, String newPassword) {
password = new Sha256Hash(password).toHex();
newPassword = new Sha256Hash(newPassword).toHex();
// int count = userService.updatePassword(ShiroUtils.getUserId(), password,
// newPassword);
// if (count == 0) {
// return R.error("原密码不正确");
// }
ShiroUtils.logout();
return R.ok();
}
}
package com.govmade.modules.system.dao;
import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.govmade.modules.system.entity.UserEntity;
......@@ -33,4 +35,6 @@ public interface UserDao extends BaseMapper<UserEntity> {
*/
UserEntity queryByUserName(String username);
void deleteBatch(@Param("ids") Set<Long> ids);
}
package com.govmade.modules.system.service;
import java.util.Map;
import java.util.Set;
import com.baomidou.mybatisplus.service.IService;
import com.govmade.common.utils.PageUtils;
......@@ -28,7 +29,7 @@ public interface UserService extends IService<UserEntity> {
/**
* 删除用户
*/
void deleteBatch(Long[] userIds);
void deleteBatch(Set<Long> ids);
/**
* 修改密码
......
package com.govmade.modules.system.service.impl;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
......@@ -13,6 +13,7 @@ import com.govmade.modules.system.dao.UserDao;
import com.govmade.modules.system.entity.UserEntity;
import com.govmade.modules.system.service.UserService;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
/**
......@@ -49,9 +50,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
}
@Override
public void deleteBatch(Long[] userIds) {
// TODO Auto-generated method stub
public void deleteBatch(Set<Long> ids) {
this.baseMapper.deleteBatch(ids);
}
@Override
......
......@@ -3,8 +3,11 @@
<mapper namespace="com.govmade.modules.system.dao.UserDao">
<select id="queryByUserName" resultType="UserEntity">
select * from sys_user where username = #{username}
</select>
<!-- 批量删除 -->
<update id="deleteBatch">
UPDATE system_users SET state =${@com.govmade.common.utils.Constant@STATE_NORMAL} WHERE id IN
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment