| | |
| | | package com.dsh.guns.modular.system.controller.system; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dsh.course.mapper.UserMapper; |
| | | import com.dsh.guns.config.UserExt; |
| | |
| | | import com.dsh.guns.core.exception.GunsException; |
| | | import com.dsh.guns.core.log.LogObjectHolder; |
| | | import com.dsh.guns.core.util.SinataUtil; |
| | | import com.dsh.guns.core.util.ToolUtil; |
| | | import com.dsh.guns.modular.system.controller.util.MD5; |
| | | import com.dsh.guns.modular.system.factory.UserFactory; |
| | | import com.dsh.guns.modular.system.model.Role; |
| | |
| | | import com.dsh.guns.modular.system.service.IRoleService; |
| | | import com.dsh.guns.modular.system.service.IUserService; |
| | | import com.dsh.guns.modular.system.transfer.UserDto; |
| | | import com.dsh.guns.modular.system.util.OssUploadUtil; |
| | | import com.dsh.guns.modular.system.util.ResultUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.naming.NoPermissionException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.File; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 系统管理员控制器 |
| | |
| | | @RequestMapping("/user_add") |
| | | public String addView(Model model) { |
| | | model.addAttribute("language",UserExt.getLanguage()); |
| | | LambdaQueryWrapper<Role> roleLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if(UserExt.getUser().getObjectType()!=1){ |
| | | roleLambdaQueryWrapper.eq(Role::getObjId,UserExt.getUser().getObjectId()); |
| | | } |
| | | roleLambdaQueryWrapper.eq(Role::getObjType,UserExt.getUser().getObjectType()); |
| | | List<Role> list = roleService.list(roleLambdaQueryWrapper); |
| | | model.addAttribute("list",list); |
| | | return PREFIX + "user_add.html"; |
| | | } |
| | | |
| | |
| | | model.addAttribute("roleName", ConstantFactory.me().getRoleName(user.getRoleid())); |
| | | model.addAttribute("deptName", ConstantFactory.me().getDeptName(user.getDeptid())); |
| | | LogObjectHolder.me().set(user); |
| | | LambdaQueryWrapper<Role> roleLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if(UserExt.getUser().getObjectType()!=1){ |
| | | roleLambdaQueryWrapper.eq(Role::getObjId,UserExt.getUser().getObjectId()); |
| | | } |
| | | roleLambdaQueryWrapper.eq(Role::getObjType,UserExt.getUser().getObjectType()); |
| | | List<Role> list = roleService.list(roleLambdaQueryWrapper); |
| | | model.addAttribute("list",list); |
| | | model.addAttribute("language",UserExt.getLanguage()); |
| | | return PREFIX + "user_edit.html"; |
| | | } |
| | |
| | | if (user.getPassword().equals(oldMd5)) { |
| | | String newMd5 = MD5.md5(newPwd); |
| | | user.setPassword(newMd5); |
| | | user.setPassWordUpdate(new Date()); |
| | | user.updateById(); |
| | | return SUCCESS_TIP; |
| | | } else { |
| | |
| | | |
| | | // 判断账号是否重复 |
| | | //Check if the account is duplicated |
| | | User theUser = userService.getByAccount(user.getAccount()); |
| | | if (theUser != null) { |
| | | User theUser = new User(); |
| | | if (user.getAccount()!=""){ |
| | | theUser = userService.getByAccount(user.getAccount()); |
| | | |
| | | } |
| | | System.out.println("=====theUser======="+theUser); |
| | | if (theUser != null&&user.getAccount()!="") { |
| | | throw new GunsException(BizExceptionEnum.USER_ALREADY_REG); |
| | | } |
| | | |
| | |
| | | user.setCreatetime(new Date()); |
| | | |
| | | User objectUser = UserFactory.createUser(user); |
| | | objectUser.setObjectType(UserExt.getUser().getObjectType()); |
| | | objectUser.setObjectId(UserExt.getUser().getObjectId()); |
| | | objectUser.setRoleid(user.getRoleid()); |
| | | objectUser.setAccount(user.getPhone()); |
| | | objectUser.setPassword(SecureUtil.md5("a123456")); |
| | | //查找平台所属公司 |
| | | //Search for the company that owns the platform. |
| | | objectUser.setPassWordUpdate(new Date()); |
| | | this.userService.save(objectUser); |
| | | |
| | | return SUCCESS_TIP; |
| | |
| | | assertAuth(userId); |
| | | this.userService.setStatus(userId, ManagerStatus.FREEZED.getCode()); |
| | | |
| | | User user = userService.getById(userId); |
| | | if (user.getRoleType() == 2){ |
| | | |
| | | }else if (user.getRoleType() == 3){ |
| | | } |
| | | return SUCCESS_TIP; |
| | | } |
| | | |
| | |
| | | assertAuth(userId); |
| | | this.userService.setStatus(userId, ManagerStatus.OK.getCode()); |
| | | |
| | | User user = userService.getById(userId); |
| | | if (user.getRoleType() == 2){ |
| | | |
| | | }else if (user.getRoleType() == 3){ |
| | | } |
| | | return SUCCESS_TIP; |
| | | } |
| | | |
| | |
| | | /** |
| | | * 上传图片 |
| | | */ |
| | | @RequestMapping(method = RequestMethod.POST, path = "/upload") |
| | | @RequestMapping(method = RequestMethod.POST, path = "/uploadImg") |
| | | @ResponseBody |
| | | public String upload(@RequestPart("file") MultipartFile picture) { |
| | | |
| | | String pictureName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(picture.getOriginalFilename()); |
| | | public String uploadImg(@RequestPart("file") MultipartFile picture) { |
| | | String pictureName = ""; |
| | | try { |
| | | String fileSavePath = gunsProperties.getFileUploadPath(); |
| | | picture.transferTo(new File(fileSavePath + pictureName)); |
| | | } catch (Exception e) { |
| | | throw new GunsException(BizExceptionEnum.UPLOAD_ERROR); |
| | | pictureName = OssUploadUtil.ossUpload("img/", picture); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return pictureName; |
| | | } |
| | | |
| | | /** |
| | | * 上传图片 |
| | | */ |
| | | /** |
| | | * 上传图片Amis |
| | | */ |
| | | @RequestMapping(method = RequestMethod.POST, path = "/uploadImgAmis") |
| | | @ResponseBody |
| | | public ResultUtil uploadImgAmis(@RequestPart("file") MultipartFile picture, HttpServletResponse response) { |
| | | String value = ""; |
| | | try { |
| | | value = OssUploadUtil.ossUpload("img/", picture); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | System.out.println("图片返回地址-------"+value); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("value",value); |
| | | // return ResultUtil.success(0,map); |
| | | return ResultUtil.getResult(0,null,null,map); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @RequestMapping(method = RequestMethod.POST, path = "/uploadFile") |
| | | @ResponseBody |
| | | public String uploadFile(@RequestPart("file") MultipartFile picture) { |
| | | String pictureName = ""; |
| | | try { |
| | | pictureName = OssUploadUtil.ossUpload("video/", picture); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return pictureName; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断当前登录的用户是否有操作这个用户的权限 |
| | | */ |
| | | private void assertAuth(Integer userId) { |