| | |
| | | package com.stylefeng.guns.modular.system.controller.system; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | 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.dictmap.UserDict; |
| | | import com.stylefeng.guns.core.common.constant.factory.ConstantFactory; |
| | | 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.*; |
| | | 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; |
| | | |
| | |
| | | @Controller |
| | | @RequestMapping("/mgr") |
| | | public class UserMgrController extends BaseController { |
| | | |
| | | |
| | | private static String PREFIX = "/system/user/"; |
| | | |
| | | |
| | | @Autowired |
| | | private GunsProperties gunsProperties; |
| | | |
| | | |
| | | @Autowired |
| | | private IUserService userService; |
| | | |
| | | |
| | | @Autowired |
| | | private ITDriverService itDriverService; |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private ITCompanyService companyService; |
| | | |
| | | |
| | | /** |
| | | * 跳转到查看管理员列表的页面 |
| | | */ |
| | |
| | | public String index() { |
| | | return PREFIX + "user.html"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 跳转到查看管理员列表的页面 |
| | | */ |
| | |
| | | /** |
| | | * 跳转到角色分配页面 |
| | | */ |
| | | //@RequiresPermissions("/mgr/role_assign") //利用shiro自带的权限检查 |
| | | @Permission |
| | | @RequestMapping("/role_assign/{userId}") |
| | | public String roleAssign(@PathVariable Integer userId, Model model) { |
| | | if (ToolUtil.isEmpty(userId)) { |
| | |
| | | /** |
| | | * 跳转到编辑管理员页面 |
| | | */ |
| | | @Permission |
| | | @RequestMapping("/user_edit/{userId}") |
| | | public String userEdit(@PathVariable Integer userId, Model model) { |
| | | 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()); |
| | |
| | | * 查询管理员列表 |
| | | */ |
| | | @RequestMapping("/list") |
| | | @Permission |
| | | @ResponseBody |
| | | public Object list(@RequestParam(required = false) String name, @RequestParam(required = false) String createTime, @RequestParam(required = false) Integer deptid) { |
| | | //创建日期 |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RequestMapping("/add") |
| | | @BussinessLog(value = "添加管理员", key = "account", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip add(@Valid UserDto user, BindingResult result) { |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | |
| | | |
| | | // 判断账号是否重复 |
| | | User theUser = userService.getByAccount(user.getAccount()); |
| | | if (theUser != null) { |
| | | throw new GunsException(BizExceptionEnum.USER_ALREADY_REG); |
| | | } |
| | | |
| | | ShiroUser user1 = ShiroExtUtil.getUser(); |
| | | User user2 = userService.selectById(user1.getId()); |
| | | TCompany tCompany = companyService.selectById(user2.getObjectId()); |
| | | SaveStaffNodeRequest request1 = new SaveStaffNodeRequest(); |
| | | request1.setMobile(user2.getPhone()); |
| | | request1.setEntercode(tCompany.getEnterCode()); |
| | | request1.setEmpName(user.getName()); |
| | | request1.setEmpNickname(user.getName()); |
| | | request1.setLoginNo(user.getAccount()); |
| | | request1.setEmpSex(user.getSex() == 1 ? "男" : "女"); |
| | | request1.setMphone(user.getPhone()); |
| | | request1.setEmail(user.getPhone() + "@qyt.com"); |
| | | request1.setDeptId(0); |
| | | request1.setPositionId(1); |
| | | request1.setSuperLevel(0); |
| | | request1.setHideMobile(0); |
| | | SaveStaffNode saveStaffNode = EmployeeUtil.saveStaffNode(request1); |
| | | Long empId = saveStaffNode.getEmpId(); |
| | | |
| | | // 完善账号信息 |
| | | user.setSalt(ShiroKit.getRandomSalt(5)); |
| | | user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt())); |
| | | user.setStatus(ManagerStatus.OK.getCode()); |
| | | user.setCreatetime(new Date()); |
| | | |
| | | user.setEmpId(empId); |
| | | user.setEntercode(tCompany.getEnterCode()); |
| | | user.setEnterId(Long.valueOf(tCompany.getEnterCode())); |
| | | |
| | | User objectUser = UserFactory.createUser(user); |
| | | //查找平台所属公司 |
| | | TCompany company = itCompanyService.selectOne(new EntityWrapper<TCompany>().eq("type", 1).orderBy("id", true).last(" limit 1")); |
| | | if (SinataUtil.isNotEmpty(company)){ |
| | | objectUser.setObjectId(company.getId()); |
| | | } |
| | | objectUser.setObjectId(user1.getObjectId()); |
| | | this.userService.insert(objectUser); |
| | | |
| | | |
| | | return SUCCESS_TIP; |
| | | } |
| | | |
| | |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | |
| | | |
| | | User oldUser = userService.selectById(user.getId()); |
| | | |
| | | if (ShiroKit.hasRole(Const.ADMIN_NAME)) { |
| | | ShiroUser user1 = ShiroExtUtil.getUser(); |
| | | User user2 = userService.selectById(user1.getId()); |
| | | TCompany tCompany = companyService.selectById(user2.getObjectId()); |
| | | //调用中台接口 |
| | | GetStaffNodeRequest request = new GetStaffNodeRequest(); |
| | | request.setEmpId(oldUser.getEmpId()); |
| | | request.setMobile(user2.getPhone()); |
| | | request.setEntercode(tCompany.getEnterCode()); |
| | | StaffNodeInfo staffNode = EmployeeUtil.getStaffNode(request); |
| | | Long empId = null; |
| | | if (null == staffNode || "0".equals(staffNode.getIsValid())) { |
| | | SaveStaffNodeRequest request1 = new SaveStaffNodeRequest(); |
| | | request1.setMobile(user2.getPhone()); |
| | | request1.setEntercode(tCompany.getEnterCode()); |
| | | request1.setEmpName(user.getName()); |
| | | request1.setEmpNickname(user.getName()); |
| | | request1.setLoginNo(user.getAccount()); |
| | | request1.setEmpSex(user.getSex() == 1 ? "男" : "女"); |
| | | request1.setMphone(user.getPhone()); |
| | | request1.setEmail(user.getPhone() + "@qyt.com"); |
| | | request1.setDeptId(0); |
| | | request1.setPositionId(1); |
| | | request1.setSuperLevel(0); |
| | | request1.setHideMobile(0); |
| | | SaveStaffNode saveStaffNode = EmployeeUtil.saveStaffNode(request1); |
| | | empId = saveStaffNode.getEmpId(); |
| | | } else { |
| | | EditStaffNodeRequest request1 = new EditStaffNodeRequest(); |
| | | request1.setEmpId(staffNode.getEmpId()); |
| | | request1.setMobile(user2.getPhone()); |
| | | request1.setEntercode(tCompany.getEnterCode()); |
| | | request1.setEnterId(Long.valueOf(tCompany.getEnterCode())); |
| | | request1.setEmpName(user.getName()); |
| | | request1.setEmpNickname(user.getName()); |
| | | request1.setLoginNo(user.getAccount()); |
| | | request1.setEmpSex(user.getSex() == 1 ? "男" : "女"); |
| | | request1.setMphone(user.getPhone()); |
| | | request1.setEmail(user.getPhone() + "@qyt.com"); |
| | | request1.setDeptIds(staffNode.getDeptId() + ""); |
| | | request1.setPositionId(1); |
| | | request1.setSuperLevel(0); |
| | | request1.setHideMobile(0); |
| | | EmployeeUtil.editStaffNode(request1); |
| | | empId = staffNode.getEmpId(); |
| | | } |
| | | oldUser.setEmpId(empId); |
| | | oldUser.setEntercode(tCompany.getEnterCode()); |
| | | oldUser.setEnterId(Long.valueOf(tCompany.getEnterCode())); |
| | | user.setEmpId(empId); |
| | | user.setEntercode(tCompany.getEnterCode()); |
| | | user.setEnterId(Long.valueOf(tCompany.getEnterCode())); |
| | | |
| | | if (ShiroExtUtil.getUser().isAdmin) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | | assertAuth(user.getId()); |
| | | ShiroUser shiroUser = ShiroKit.getUser(); |
| | | ShiroUser shiroUser = ShiroExtUtil.getUser(); |
| | | if (shiroUser.getId().equals(user.getId())) { |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return SUCCESS_TIP; |
| | |
| | | */ |
| | | @RequestMapping("/delete") |
| | | @BussinessLog(value = "删除管理员", key = "userId", dict = UserDict.class) |
| | | @Permission |
| | | @ResponseBody |
| | | public Tip delete(@RequestParam Integer userId) { |
| | | if (ToolUtil.isEmpty(userId)) { |
| | |
| | | if (userId.equals(Const.ADMIN_ID)) { |
| | | throw new GunsException(BizExceptionEnum.CANT_DELETE_ADMIN); |
| | | } |
| | | |
| | | |
| | | assertAuth(userId); |
| | | User user = userService.selectById(userId); |
| | | ShiroUser user1 = ShiroExtUtil.getUser(); |
| | | User user2 = userService.selectById(user1.getId()); |
| | | TCompany tCompany = companyService.selectById(user2.getObjectId()); |
| | | //调用中台接口 |
| | | GetStaffNodeRequest request = new GetStaffNodeRequest(); |
| | | request.setEmpId(user.getEmpId()); |
| | | request.setMobile(user2.getPhone()); |
| | | request.setEntercode(tCompany.getEnterCode()); |
| | | StaffNodeInfo staffNode = EmployeeUtil.getStaffNode(request); |
| | | if (null != staffNode && "1".equals(staffNode.getIsValid())) { |
| | | DeleteStafNodeRequest request1 = new DeleteStafNodeRequest(); |
| | | request1.setEmpId(user.getEnterId()); |
| | | request1.setMobile(user2.getPhone()); |
| | | request1.setEntercode(tCompany.getEnterCode()); |
| | | EmployeeUtil.ecrmDeleteStafNode(request1); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | |
| | | */ |
| | | @RequestMapping("/reset") |
| | | @BussinessLog(value = "重置管理员密码", key = "userId", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip reset(@RequestParam Integer 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())); |
| | |
| | | */ |
| | | @RequestMapping("/freeze") |
| | | @BussinessLog(value = "冻结用户", key = "userId", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip freeze(@RequestParam Integer userId) { |
| | | if (ToolUtil.isEmpty(userId)) { |
| | |
| | | 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); |
| | |
| | | */ |
| | | @RequestMapping("/unfreeze") |
| | | @BussinessLog(value = "解除冻结用户", key = "userId", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip unfreeze(@RequestParam Integer 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); |
| | |
| | | */ |
| | | @RequestMapping("/setRole") |
| | | @BussinessLog(value = "分配角色", key = "userId,roleIds", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip setRole(@RequestParam("userId") Integer userId, @RequestParam("roleIds") String roleIds) { |
| | | if (ToolUtil.isOneEmpty(userId, roleIds)) { |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |