| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | e.printStackTrace(); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | @PostMapping("/getSysUserAll") |
| | | public R<List<SysUser>> getSysUserAll() { |
| | | List<SysUser> list = userService.list(); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | @PostMapping("/updateSysUser") |
| | |
| | | userRoleService.insertSysUserRole(sysUserRole); |
| | | return R.ok(user.getUserId()); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/addSysUserSite") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<Long> addSysUserSite(@RequestBody SysUser user) { |
| | | if(StringUtils.isEmpty(user.getUserName())){ |
| | | user.setUserName(user.getPhonenumber()); |
| | | } |
| | | if(!org.springframework.util.StringUtils.hasLength(user.getNickName())){ |
| | | user.setNickName(user.getPhonenumber()); |
| | | } |
| | | // if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | // throw new RuntimeException("手机号已开通账号"); |
| | | // } |
| | | if (StringUtils.isNotEmpty(user.getUserName()) && !userService.checkUserNameUnique(user)) { |
| | | throw new RuntimeException("登录账号已存在"); |
| | | } |
| | | user.setCreateBy(SecurityUtils.getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(MD5Generator.generateMD5(user.getPassword()))); |
| | | user.setRoleType(2); |
| | | userService.insertUser(user); |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setRoleId(user.getRoleId()); |
| | | sysUserRole.setUserId(user.getUserId()); |
| | | userRoleService.insertSysUserRole(sysUserRole); |
| | | return R.ok(user.getUserId()); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String s = SecurityUtils.encryptPassword(MD5Generator.generateMD5("123456")); |
| | | System.err.println("加密"+s); |
| | | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); |
| | | |
| | | System.err.println(passwordEncoder.matches(MD5Generator.generateMD5("123456"), "$2a$10$yxHB49D.WQOKiZvh8SHHv.1/MxHZzriuVA99sIIiHKmsjI.EQC9yC")); |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | |
| | | userService.deleteUserById(userId); |
| | | return R.ok(); |
| | | } |
| | | @GetMapping("/queryUserBySiteId") |
| | | public R queryUserBySiteId(@RequestParam("siteId") Integer siteId){ |
| | | SysUser user = userService.selectUserBySiteId(siteId); |
| | | return R.ok(user); |
| | | } |
| | | } |