bug修复
parent
245da6248b
commit
6185a4790b
|
@ -59,18 +59,17 @@ public class AccountController extends BaseController {
|
|||
|
||||
@RequestMapping(value = "/updatePassword")
|
||||
@ResponseBody
|
||||
public ResponseMsg updatePassword(HttpServletRequest request, ModifyPasswordRequest modifyPasswordRequest){
|
||||
public ResponseMsg updatePassword(HttpServletRequest request, ModifyPasswordRequest modifyPasswordRequest) {
|
||||
ResponseMsg responseMsg = new ResponseMsg();
|
||||
try{
|
||||
try {
|
||||
String privateKey = (String) request.getSession().getAttribute(Constant.PRIVATEKEY);
|
||||
adminService.updatePassword(modifyPasswordRequest.getId(), modifyPasswordRequest.getPassword(),
|
||||
modifyPasswordRequest.getNewPassword(), privateKey);
|
||||
modifyPasswordRequest.getNewPassword(), privateKey);
|
||||
responseMsg.setStatus(0);
|
||||
responseMsg.setMsg("密码修改成功");
|
||||
}
|
||||
catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
responseMsg.setStatus(1);
|
||||
responseMsg.setMsg("密码修改失败:"+e.getMessage());
|
||||
responseMsg.setMsg("密码修改失败:" + e.getMessage());
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ public class AccountController extends BaseController {
|
|||
model.put("roleList", sysRoleService.getAllEnableSysRole());
|
||||
model.put("deptList", deptRepository.findAll());
|
||||
model.put("positionList", userPositionRepository.findAll());
|
||||
model.put("pager", accountService.getAdminList(searchInfo, pageSize, pageNumber));
|
||||
model.put("pager", accountService.list(searchInfo, pageNumber, pageSize));
|
||||
return "/admin/account_list";
|
||||
}
|
||||
|
||||
|
@ -122,23 +121,23 @@ public class AccountController extends BaseController {
|
|||
* 保存或更新用户
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public String save(@RequestParam("userId") int userId,Admin admin, HttpServletRequest request, Map<String, Object> model) throws IOException {
|
||||
if(admin.getRoleId()<=0){
|
||||
model.put("errorMessage","角色不能为空!");
|
||||
public String save(@RequestParam("userId") int userId, Admin admin, HttpServletRequest request, Map<String, Object> model) throws IOException {
|
||||
if (admin.getRoleId() <= 0) {
|
||||
model.put("errorMessage", "角色不能为空!");
|
||||
return "/common/error";
|
||||
}
|
||||
//获取验证用户信息
|
||||
String message = accountService.validateUserExistInfo(userId,admin);
|
||||
if(StringUtils.isNotEmpty(message)){
|
||||
model.put("errorMessage",message);
|
||||
String message = accountService.validateUserExistInfo(userId, admin);
|
||||
if (StringUtils.isNotEmpty(message)) {
|
||||
model.put("errorMessage", message);
|
||||
return "/common/error";
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
HttpSession session = request.getSession();
|
||||
String privateKey = (String) session.getAttribute(Constant.PRIVATEKEY);
|
||||
|
||||
accountService.saveOrUpdateAccount(userId,admin.getRoleId(),admin, privateKey);
|
||||
accountService.saveOrUpdateAccount(userId, admin.getRoleId(), admin, privateKey);
|
||||
} catch (Exception e) {
|
||||
logger.error("保存账号出错!" + e.toString());
|
||||
return "新增账号出错!请联系管理员处理!";
|
||||
|
@ -151,7 +150,7 @@ public class AccountController extends BaseController {
|
|||
*/
|
||||
@RequestMapping("/changeStatus")
|
||||
public ResponseMsg changeStatus(Admin admin) {
|
||||
boolean locked = accountService.changeStatus(admin.getId(),admin.getEnabled());
|
||||
boolean locked = accountService.changeStatus(admin.getId(), admin.getEnabled());
|
||||
if (locked) {
|
||||
return ResponseMsg.buildSuccessMsg("操作成功");
|
||||
} else {
|
||||
|
@ -183,10 +182,10 @@ public class AccountController extends BaseController {
|
|||
*/
|
||||
@RequestMapping("/resetPassword")
|
||||
@ResponseBody
|
||||
public ResponseMsg resetPassword(@RequestParam("userId") int userId,HttpServletRequest request) {
|
||||
public ResponseMsg resetPassword(@RequestParam("userId") int userId, HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
String privateKey = (String) session.getAttribute(Constant.PRIVATEKEY);
|
||||
boolean flag = accountService.resetPassword(userId,privateKey);
|
||||
boolean flag = accountService.resetPassword(userId, privateKey);
|
||||
ResponseMsg responseMsg = new ResponseMsg();
|
||||
if (flag) {
|
||||
responseMsg.setStatus(0);
|
||||
|
@ -202,7 +201,7 @@ public class AccountController extends BaseController {
|
|||
* 修改密码请求
|
||||
*/
|
||||
@RequestMapping("/password")
|
||||
public String password(HttpServletRequest request,Map<String, Object> model){
|
||||
public String password(HttpServletRequest request, Map<String, Object> model) {
|
||||
Admin admin = adminService.getAdminById(InterfaceUtil.getAdminId());
|
||||
try {
|
||||
String id = new DESAS().encrypt(admin.getId().toString());
|
||||
|
@ -211,7 +210,7 @@ public class AccountController extends BaseController {
|
|||
e.printStackTrace();
|
||||
}
|
||||
model.put("SysUser", admin);
|
||||
genRSAKeyPair(request,model);
|
||||
genRSAKeyPair(request, model);
|
||||
return "/admin/account_password";
|
||||
}
|
||||
|
||||
|
@ -221,23 +220,23 @@ public class AccountController extends BaseController {
|
|||
}
|
||||
|
||||
@RequestMapping("/export")
|
||||
public void export(@RequestParam(value = "keywords",required = false) String keywords, HttpServletResponse httpServletResponse) throws IOException {
|
||||
public void export(@RequestParam(value = "keywords", required = false) String keywords, HttpServletResponse httpServletResponse) throws IOException {
|
||||
Map<String, String> searchInfo = getSearchInfo(keywords);
|
||||
downloadHeader(httpServletResponse , Utils.generateExcelName("人员信息"), "application/octet-stream");
|
||||
downloadHeader(httpServletResponse, Utils.generateExcelName("人员信息"), "application/octet-stream");
|
||||
String[] headers = {"工号", "手机号码", "姓名", "常驻地", "一级部门", "直接主管", "职位", "所属角色", "公司邮件地址"};
|
||||
String[] exportColumns = {"empCode", "telephone", "workLocation", "deptName", "directManager", "positionName", "roleName", "companyEmail"};
|
||||
String[] exportColumns = {"empCode", "telephone", "realName", "workLocation", "deptName", "directManager", "positionName", "roleName", "companyEmail"};
|
||||
ExportUtils.exportToExcel(headers, exportColumns, 1, 10000,
|
||||
httpServletResponse.getOutputStream(), (pN, pS) -> accountService.getAdminList(searchInfo, pN, pS).getList());
|
||||
httpServletResponse.getOutputStream(), (pN, pS) -> accountService.list(searchInfo, pN, pS).getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
*/
|
||||
@RequestMapping("/template")
|
||||
public void template(HttpServletResponse response) throws Exception{
|
||||
public void template(HttpServletResponse response) throws Exception {
|
||||
|
||||
String[] headers = new String[]{"工号", "手机号码", "姓名", "常驻地", "一级部门", "直接主管", "职位", "所属角色", "公司邮件地址"};
|
||||
downloadHeader(response , Utils.generateExcelName("人员信息批量导入模板"));
|
||||
String[] headers = new String[]{"工号", "手机号码", "登录名称", "姓名", "常驻地", "一级部门", "直接主管", "职位", "所属角色", "公司邮件地址"};
|
||||
downloadHeader(response, Utils.generateExcelName("人员信息批量导入模板"));
|
||||
ExportUtils exportUtils = new ExportUtils(headers);
|
||||
exportUtils.write(response.getOutputStream());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Date;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name = "sys_user")
|
||||
public class Admin implements Serializable{
|
||||
public class Admin{
|
||||
public static final int ENABLED = 1;
|
||||
public static final int DISABLED = 0;
|
||||
public static final int LOCKED = 1;
|
||||
|
|
|
@ -3,4 +3,6 @@ package cn.palmte.work.model;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DeptRepository extends JpaRepository<Dept,Integer> {
|
||||
|
||||
Dept findByNameEquals(String name);
|
||||
}
|
||||
|
|
|
@ -49,4 +49,6 @@ public interface SysRoleRepository extends JpaRepository<SysRole, Integer> {
|
|||
@Query(" from SysRole where deleted=0 and isEnable=1 and type = 1")
|
||||
List<SysRole> getAllEnableSysRole();
|
||||
|
||||
SysRole findByNameEqualsAndDeletedEquals(String name,int deleted);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,4 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||
|
||||
public interface UserPositionRepository extends JpaRepository<UserPosition,Integer> {
|
||||
|
||||
UserPosition findByPositionNameEquals(String name);
|
||||
|
||||
}
|
||||
|
|
|
@ -60,20 +60,26 @@ public class AccountService {
|
|||
return adminList;
|
||||
}
|
||||
|
||||
public Page<Admin> list(ConcurrentHashMap<String, String> searchInfo, int pageNumber, int pageSize) {
|
||||
QueryHelper queryHelper = new QueryHelper("select su.id,su.user_name,su.real_name,su.created_time,su.enabled,sr.type,sr.name as roleName,su.telephone,su.region_name", " 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");
|
||||
queryHelper.addCondition("su.is_deleted = 0");
|
||||
public Page<Admin> list(Map<String, String> searchInfo, int pageNumber, int pageSize) {
|
||||
QueryHelper queryHelper = new QueryHelper("*", "sys_user u");
|
||||
queryHelper.addCondition("u.is_deleted = 0");
|
||||
queryHelper.addCondition(searchInfo.containsKey("realName"), "u.real_name like ?", "%" +
|
||||
searchInfo.get("realName") + "%");
|
||||
queryHelper.addCondition(searchInfo.containsKey("telephone"), "u.telephone =?", searchInfo.get("telephone"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("empCode"), "u.emp_code =?", searchInfo.get("empCode"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("deptId") &&
|
||||
StrKit.notBlank(searchInfo.get("deptId")) && !"-1".equals(searchInfo.get("deptId")),
|
||||
"u.dept_id =?", searchInfo.get("deptId"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("roleId") &&
|
||||
StrKit.notBlank(searchInfo.get("roleId")) && !"-1".equals(searchInfo.get("roleId")),
|
||||
"sr.id =?", searchInfo.get("roleId"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("userName"), "su.user_name like ?", "%" +
|
||||
"su.is_deleted = 0" + "%");
|
||||
queryHelper.addCondition(searchInfo.containsKey("telephone"), "su.telephone = ?" + searchInfo.get("telephone"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("regionId") &&
|
||||
StrKit.notBlank(searchInfo.get("regionId")) && !"-1".equals(searchInfo.get("regionId")),
|
||||
"su.region_id =?", searchInfo.get("regionId"));
|
||||
queryHelper.addOrderProperty("su.created_time", false);
|
||||
"u.role_id =?", searchInfo.get("roleId"));
|
||||
queryHelper.addCondition(searchInfo.containsKey("workLocation"), "u.work_location like ?", "%" +
|
||||
searchInfo.get("workLocation") + "%");
|
||||
queryHelper.addCondition(searchInfo.containsKey("startTime"), "u.created_time >= ?",
|
||||
searchInfo.get("startTime") + " 00:00:00");
|
||||
queryHelper.addCondition(searchInfo.containsKey("endTime"), "u.created_time <= ?",
|
||||
searchInfo.get("endTime") + " 23:59:59");
|
||||
queryHelper.addOrderProperty("u.created_time", false);
|
||||
Page<Admin> page = pagination.paginate(queryHelper.getSql(), Admin.class, pageNumber, pageSize);
|
||||
return page;
|
||||
|
||||
|
@ -276,10 +282,157 @@ public class AccountService {
|
|||
return false;
|
||||
}
|
||||
|
||||
public ResponseMsg check(Collection<Map> maps) {
|
||||
@Transactional
|
||||
public ResponseMsg check(Collection<Map> excelMap) {
|
||||
int successCount = 0;
|
||||
int errorCount = 0;
|
||||
List<String> errorList = new ArrayList<>();
|
||||
int createAdminId = InterfaceUtil.getAdminId();
|
||||
Admin admin = null;
|
||||
|
||||
if (excelMap.size() == 0) {
|
||||
ResponseMsg msg = ResponseMsg.buildSuccessMsg("请填写人员数据!");
|
||||
msg.setData(errorList);
|
||||
return msg;
|
||||
}
|
||||
|
||||
return null;
|
||||
for (Map m : excelMap) {
|
||||
|
||||
try {
|
||||
Object empCode = m.get("工号");
|
||||
if (empCode == null || StrKit.isBlank(empCode.toString())) {
|
||||
throw new Exception("工号不能为空");
|
||||
}
|
||||
|
||||
Admin byEmpCode = adminRepository.findByEmpCode(empCode.toString());
|
||||
|
||||
if (null != byEmpCode) {
|
||||
throw new Exception("工号" + empCode.toString() + "已存在");
|
||||
}
|
||||
|
||||
Object telephone = m.get("手机号码");
|
||||
if (telephone == null || StrKit.isBlank(telephone.toString())) {
|
||||
throw new Exception("手机号码不能为空");
|
||||
}
|
||||
|
||||
Admin byTelephone = adminRepository.findByTelephone(telephone.toString());
|
||||
if (null != byTelephone) {
|
||||
throw new Exception("手机号码" + telephone.toString() + "已存在");
|
||||
}
|
||||
|
||||
Object userName = m.get("登录名称");
|
||||
if (userName == null || StrKit.isBlank(userName.toString())) {
|
||||
throw new Exception("登录名称不能为空");
|
||||
}
|
||||
|
||||
Admin byUsername = adminRepository.getAdminByUsername(userName.toString());
|
||||
if (null != byUsername) {
|
||||
throw new Exception("登录名称" + byUsername.toString() + "已存在");
|
||||
}
|
||||
|
||||
Object realName = m.get("姓名");
|
||||
if (realName == null || StrKit.isBlank(realName.toString())) {
|
||||
throw new Exception("姓名不能为空");
|
||||
}
|
||||
|
||||
Admin byRealName = adminRepository.getAdminByRealName(realName.toString());
|
||||
if (null != byRealName) {
|
||||
throw new Exception("姓名" + realName.toString() + "已存在");
|
||||
}
|
||||
|
||||
Object workLocation = m.get("常驻地");
|
||||
if (workLocation == null || StrKit.isBlank(workLocation.toString())) {
|
||||
throw new Exception("常驻地不能为空");
|
||||
}
|
||||
|
||||
Object deptName = m.get("一级部门");
|
||||
if (deptName == null || StrKit.isBlank(deptName.toString())) {
|
||||
throw new Exception("一级部门不能为空");
|
||||
}
|
||||
|
||||
Dept dept = deptRepository.findByNameEquals(deptName.toString());
|
||||
|
||||
if (null == dept) {
|
||||
throw new Exception("一级部门" + deptName.toString() + "不存在");
|
||||
}
|
||||
|
||||
Object directManager = m.get("直接主管");
|
||||
if (directManager == null || StrKit.isBlank(directManager.toString())) {
|
||||
throw new Exception("直接主管不能为空");
|
||||
}
|
||||
|
||||
Object positionName = m.get("职位");
|
||||
if (positionName == null || StrKit.isBlank(positionName.toString())) {
|
||||
throw new Exception("职位不能为空");
|
||||
}
|
||||
|
||||
UserPosition userPosition = userPositionRepository.findByPositionNameEquals(positionName.toString());
|
||||
|
||||
if (null == userPosition) {
|
||||
throw new Exception("职位" + positionName.toString() + "不存在");
|
||||
}
|
||||
|
||||
Object sysRole = m.get("所属角色");
|
||||
if (sysRole == null || StrKit.isBlank(sysRole.toString())) {
|
||||
throw new Exception("所属角色不能为空");
|
||||
}
|
||||
|
||||
SysRole role = sysRoleRepository.findByNameEqualsAndDeletedEquals(sysRole.toString(), 0);
|
||||
|
||||
if (null == role) {
|
||||
throw new Exception("所属角色" + sysRole.toString() + "不存在");
|
||||
}
|
||||
|
||||
Object companyEmail = m.get("公司邮件地址");
|
||||
if (companyEmail == null || StrKit.isBlank(companyEmail.toString())) {
|
||||
throw new Exception("公司邮件地址不能为空");
|
||||
}
|
||||
|
||||
admin = new Admin();
|
||||
admin.setEmpCode(empCode.toString());
|
||||
admin.setTelephone(telephone.toString());
|
||||
admin.setUserName(userName.toString());
|
||||
admin.setWorkLocation(workLocation.toString());
|
||||
admin.setDeptId(dept.getId());
|
||||
admin.setDeptName(dept.getName());
|
||||
admin.setDirectManager(directManager.toString());
|
||||
admin.setPositionId(userPosition.getId());
|
||||
admin.setPositionName(userPosition.getPositionName());
|
||||
admin.setRoleId(role.getId());
|
||||
admin.setRealName(role.getName());
|
||||
admin.setCompanyEmail(companyEmail.toString());
|
||||
|
||||
String salt = RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||
String password = decEncPassword(admin.getTelephone().substring(5), salt, "");
|
||||
|
||||
admin.setSalt(salt);
|
||||
admin.setPassword(password);
|
||||
admin.setCreatedBy(createAdminId);
|
||||
admin.setCreatedTime(new Date());
|
||||
admin.setLastUpdatedBy(createAdminId);
|
||||
admin.setLastUpdatedTime(new Date());
|
||||
adminRepository.saveAndFlush(admin);
|
||||
|
||||
//设置当前用户角色关系状态为删除
|
||||
sysUserRoleRepository.deleteSysUserRoleByUserId(createAdminId, new Date(), admin.getId());
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
//保存用户角色关系
|
||||
sysUserRole.setUserId(admin.getId());
|
||||
sysUserRole.setRoleId(role.getId());
|
||||
sysUserRole.setCreatedBy(createAdminId);
|
||||
sysUserRole.setCreatedTime(new Date());
|
||||
sysUserRoleRepository.save(sysUserRole);
|
||||
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
errorCount++;
|
||||
errorList.add(e.getMessage());
|
||||
}
|
||||
}
|
||||
final ResponseMsg msg = ResponseMsg.buildSuccessMsg(String.format("成功:%d, 失败:%d", successCount, errorCount));
|
||||
msg.setData(errorList);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue