| | |
| | | import com.stylefeng.guns.config.properties.GunsProperties; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.base.tips.Tip; |
| | | import com.stylefeng.guns.core.beetl.ShiroExtUtil; |
| | | import com.stylefeng.guns.core.common.annotion.BussinessLog; |
| | | import com.stylefeng.guns.core.common.annotion.Permission; |
| | | import com.stylefeng.guns.core.common.constant.Const; |
| | |
| | | import com.stylefeng.guns.core.common.constant.factory.PageFactory; |
| | | import com.stylefeng.guns.core.common.constant.state.ManagerStatus; |
| | | import com.stylefeng.guns.core.common.exception.BizExceptionEnum; |
| | | import com.stylefeng.guns.core.datascope.DataScope; |
| | | import com.stylefeng.guns.core.db.Db; |
| | | import com.stylefeng.guns.core.exception.GunsException; |
| | | import com.stylefeng.guns.core.log.LogObjectHolder; |
| | |
| | | import com.stylefeng.guns.modular.system.service.ITDriverService; |
| | | import com.stylefeng.guns.modular.system.service.IUserService; |
| | | import com.stylefeng.guns.modular.system.transfer.UserDto; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.EmployeeUtil; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.model.GetStaffNodeRequest; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | |
| | | import javax.validation.Valid; |
| | | import java.io.File; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | |
| | | if (ToolUtil.isEmpty(userId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | assertAuth(userId); |
| | | User user = this.userService.selectById(userId); |
| | | model.addAttribute(user); |
| | | model.addAttribute("roleName", ConstantFactory.me().getRoleName(user.getRoleid())); |
| | |
| | | */ |
| | | @RequestMapping("/user_info") |
| | | public String userInfo(Model model) { |
| | | Integer userId = ShiroKit.getUser().getId(); |
| | | Integer userId = ShiroExtUtil.getUser().getId(); |
| | | if (ToolUtil.isEmpty(userId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | |
| | | if (!newPwd.equals(rePwd)) { |
| | | throw new GunsException(BizExceptionEnum.TWO_PWD_NOT_MATCH); |
| | | } |
| | | Integer userId = ShiroKit.getUser().getId(); |
| | | User user = userService.selectById(userId); |
| | | Integer userId = ShiroExtUtil.getUser().getId(); |
| | | User user = userService.selectById(userId); |
| | | String oldMd5 = ShiroKit.md5(oldPwd, user.getSalt()); |
| | | if (user.getPassword().equals(oldMd5)) { |
| | | String newMd5 = ShiroKit.md5(newPwd, user.getSalt()); |
| | |
| | | //创建日期 |
| | | String beginTime = null; |
| | | String endTime = null; |
| | | if (SinataUtil.isNotEmpty(createTime)){ |
| | | String[] timeArray = createTime.split(" - "); |
| | | beginTime = timeArray[0]; |
| | | endTime = timeArray[1]; |
| | | } |
| | | if (ShiroKit.isAdmin()) { |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | page.setRecords(userService.getUserListPage(page,null, name, beginTime, endTime, deptid)); |
| | | return super.packForBT(page); |
| | | } else { |
| | | DataScope dataScope = new DataScope(ShiroKit.getDeptDataScope()); |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | page.setRecords(userService.getUserListPage(page,dataScope, name, beginTime, endTime, deptid)); |
| | | return super.packForBT(page); |
| | | } |
| | | if (SinataUtil.isNotEmpty(createTime)) { |
| | | String[] timeArray = createTime.split(" - "); |
| | | beginTime = timeArray[0]; |
| | | endTime = timeArray[1]; |
| | | } |
| | | if (ShiroExtUtil.getUser().isAdmin()) { |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | page.setRecords(userService.getUserListPage(page, null, name, beginTime, endTime, deptid)); |
| | | return super.packForBT(page); |
| | | } else { |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | page.setRecords(userService.getUserListPage(page, null, name, beginTime, endTime, deptid)); |
| | | return super.packForBT(page); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @BussinessLog(value = "修改管理员", key = "account", dict = UserDict.class) |
| | | @ResponseBody |
| | | public Tip edit(@Valid UserDto user, BindingResult result) throws NoPermissionException { |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | |
| | | |
| | | User oldUser = userService.selectById(user.getId()); |
| | | |
| | | if (ShiroKit.hasRole(Const.ADMIN_NAME)) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | | assertAuth(user.getId()); |
| | | ShiroUser shiroUser = ShiroKit.getUser(); |
| | | if (shiroUser.getId().equals(user.getId())) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | | throw new GunsException(BizExceptionEnum.NO_PERMITION); |
| | | } |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | User oldUser = userService.selectById(user.getId()); |
| | | //调用中台接口 |
| | | GetStaffNodeRequest request = new GetStaffNodeRequest(); |
| | | |
| | | EmployeeUtil.getStaffNode(request); |
| | | |
| | | |
| | | if (ShiroExtUtil.getUser().isAdmin) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | | ShiroUser shiroUser = ShiroExtUtil.getUser(); |
| | | if (shiroUser.getId().equals(user.getId())) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | | throw new GunsException(BizExceptionEnum.NO_PERMITION); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | assertAuth(userId); |
| | | this.userService.setStatus(userId, ManagerStatus.DELETED.getCode()); |
| | | return SUCCESS_TIP; |
| | | } |
| | |
| | | if (ToolUtil.isEmpty(userId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | assertAuth(userId); |
| | | return this.userService.selectById(userId); |
| | | } |
| | | |
| | |
| | | if (ToolUtil.isEmpty(userId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | assertAuth(userId); |
| | | User user = this.userService.selectById(userId); |
| | | user.setSalt(ShiroKit.getRandomSalt(5)); |
| | | user.setPassword(ShiroKit.md5(Const.DEFAULT_PWD, user.getSalt())); |
| | |
| | | if (userId.equals(Const.ADMIN_ID)) { |
| | | throw new GunsException(BizExceptionEnum.CANT_FREEZE_ADMIN); |
| | | } |
| | | assertAuth(userId); |
| | | this.userService.setStatus(userId, ManagerStatus.FREEZED.getCode()); |
| | | |
| | | User user = userService.selectById(userId); |
| | |
| | | if (ToolUtil.isEmpty(userId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | assertAuth(userId); |
| | | this.userService.setStatus(userId, ManagerStatus.OK.getCode()); |
| | | |
| | | User user = userService.selectById(userId); |
| | |
| | | if (userId.equals(Const.ADMIN_ID)) { |
| | | throw new GunsException(BizExceptionEnum.CANT_CHANGE_ADMIN); |
| | | } |
| | | assertAuth(userId); |
| | | this.userService.setRoles(userId, roleIds); |
| | | |
| | | |
| | |
| | | } |
| | | return pictureName; |
| | | } |
| | | |
| | | /** |
| | | * 判断当前登录的用户是否有操作这个用户的权限 |
| | | */ |
| | | private void assertAuth(Integer userId) { |
| | | if (ShiroKit.isAdmin()) { |
| | | return; |
| | | } |
| | | List<Integer> deptDataScope = ShiroKit.getDeptDataScope(); |
| | | User user = this.userService.selectById(userId); |
| | | Integer deptid = user.getDeptid(); |
| | | if (deptDataScope.contains(deptid)) { |
| | | return; |
| | | } else { |
| | | throw new GunsException(BizExceptionEnum.NO_PERMITION); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |