| | |
| | | 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.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 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; |
| | |
| | | @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)) { |
| | |
| | | * 查询管理员列表 |
| | | */ |
| | | @RequestMapping("/list") |
| | | @Permission |
| | | @ResponseBody |
| | | public Object list(@RequestParam(required = false) String name, @RequestParam(required = false) String createTime, @RequestParam(required = false) Integer deptid) { |
| | | //创建日期 |
| | |
| | | */ |
| | | @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; |
| | | } |
| | | |
| | |
| | | @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()); |
| | | //调用中台接口 |
| | | 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); |
| | | } |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | User oldUser = userService.selectById(user.getId()); |
| | | 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 { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | |
| | | */ |
| | | @RequestMapping("/reset") |
| | | @BussinessLog(value = "重置管理员密码", key = "userId", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip reset(@RequestParam Integer userId) { |
| | | if (ToolUtil.isEmpty(userId)) { |
| | |
| | | */ |
| | | @RequestMapping("/freeze") |
| | | @BussinessLog(value = "冻结用户", key = "userId", dict = UserDict.class) |
| | | @Permission(Const.ADMIN_NAME) |
| | | @ResponseBody |
| | | public Tip freeze(@RequestParam Integer userId) { |
| | | if (ToolUtil.isEmpty(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)) { |
| | |
| | | */ |
| | | @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)) { |