|  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IUserService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.dto.Role; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.dto.User; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.security.sasl.AuthenticationException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Api(tags = "用户管理") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IRoleService roleService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation("登录") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping("/changePassword") | 
|---|
|  |  |  | public String changePassword(@RequestParam String oldPassword, @RequestParam String password){ | 
|---|
|  |  |  | // 获取当前登录用户id | 
|---|
|  |  |  | String username = SecurityUtils.getUserInfo().getUsername(); | 
|---|
|  |  |  | LoginUser userInfo = SecurityUtils.getUserInfo(); | 
|---|
|  |  |  | if (userInfo== null) { | 
|---|
|  |  |  | return "fail"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String username = userInfo.getUsername(); | 
|---|
|  |  |  | LoginUser user = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | user = SecurityUtils.login(username, oldPassword, authenticationManager); | 
|---|
|  |  |  | 
|---|
|  |  |  | return new ResponseEntity<>(result, HttpStatus.OK); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | user.setRole(role); | 
|---|
|  |  |  | user.setCreateTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | user.setUpdateTime(format.format(System.currentTimeMillis())); | 
|---|
|  |  |  | user.setCreateTime(DateUtil.getNow()); | 
|---|
|  |  |  | user.setUpdateTime(DateUtil.getNow()); | 
|---|
|  |  |  | int addResult = userService.addUser(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | result.setCode(addResult > 0 ? 0 : -1); | 
|---|