2021-07-12 14:51:34 +08:00
|
|
|
|
package com.xkrs.controller;
|
|
|
|
|
|
|
|
|
|
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
|
|
|
|
import com.xkrs.common.tool.TokenUtil;
|
2022-07-06 17:46:57 +08:00
|
|
|
|
import com.xkrs.dao.AgentOrgDao;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import com.xkrs.dao.SysUserDao;
|
2022-07-06 17:46:57 +08:00
|
|
|
|
import com.xkrs.model.entity.AgentOrgEntity;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import com.xkrs.model.entity.SysUserEntity;
|
|
|
|
|
import com.xkrs.model.qo.SysUserQo;
|
2022-06-02 20:50:49 +08:00
|
|
|
|
import com.xkrs.model.qo.SysUserReceiveSmsQo;
|
2022-06-06 11:45:46 +08:00
|
|
|
|
import com.xkrs.model.qo.SysUserRemarkQo;
|
2022-06-02 20:50:49 +08:00
|
|
|
|
import com.xkrs.model.qo.SysUserVipLevelQo;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import com.xkrs.model.validation.SysUserQoInsert;
|
|
|
|
|
import com.xkrs.model.validation.SysUserQoUpdate;
|
|
|
|
|
import com.xkrs.model.vo.SysUserVo;
|
2021-08-03 18:03:44 +08:00
|
|
|
|
import com.xkrs.service.RedisService;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import com.xkrs.service.SysUserService;
|
2022-07-06 17:46:57 +08:00
|
|
|
|
import com.xkrs.sms.SMSHelper;
|
|
|
|
|
import com.xkrs.utils.FirePointCodeUtils;
|
2022-10-08 11:11:02 +08:00
|
|
|
|
import com.xkrs.utils.ListUtils;
|
2021-08-03 18:03:44 +08:00
|
|
|
|
import com.xkrs.utils.RandomUtil;
|
2022-07-06 17:46:57 +08:00
|
|
|
|
import org.apache.hc.core5.util.TextUtils;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2022-07-07 08:57:51 +08:00
|
|
|
|
import org.springframework.data.domain.Sort;
|
2021-12-06 15:55:27 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
2022-05-19 10:13:26 +08:00
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2022-06-02 20:50:49 +08:00
|
|
|
|
import java.util.*;
|
2021-08-03 18:03:44 +08:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
|
|
|
|
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationErrorList;
|
|
|
|
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
2021-12-06 15:55:27 +08:00
|
|
|
|
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 系统用户Controller
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(value = "/api/user")
|
|
|
|
|
public class SysUserController {
|
|
|
|
|
|
2022-07-07 08:57:51 +08:00
|
|
|
|
private final Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
|
|
2021-07-12 14:51:34 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private SysUserService sysUserService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SysUserDao sysUserDao;
|
|
|
|
|
|
2021-08-03 18:03:44 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private RedisService redisService;
|
|
|
|
|
|
2022-07-06 17:46:57 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private AgentOrgDao agentOrgDao;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SMSHelper smsHelper;
|
|
|
|
|
|
2023-01-30 13:57:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询Vip用户
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/selectVipUser")
|
|
|
|
|
public String selectVipUser() {
|
|
|
|
|
return sysUserService.selectVipUser();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 11:11:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 更新(批量)系统用户信息
|
|
|
|
|
*
|
|
|
|
|
* @param paramMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@RequestMapping(value = "/updateSysUser", method = RequestMethod.POST)
|
|
|
|
|
public String updateSysUser(@RequestBody Map<String, String> paramMap) {
|
|
|
|
|
String userIdArray = paramMap.get("userIdArray");
|
|
|
|
|
String overTime = paramMap.get("overTime");
|
|
|
|
|
String remark = paramMap.get("remark");
|
|
|
|
|
List<String> userIdList = ListUtils.toStringList(userIdArray, ",");//解析的ID集合
|
|
|
|
|
if (userIdList.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,请输入正确的ID", locale);
|
|
|
|
|
}
|
|
|
|
|
List<String> successIdList = new ArrayList<>();//操作成功的ID集合
|
|
|
|
|
List<String> failureIdList = new ArrayList<>();//操作失败的ID集合
|
|
|
|
|
for (String userId : userIdList) {
|
|
|
|
|
try {
|
|
|
|
|
Optional<SysUserEntity> targetEntityOptional = sysUserDao.findById(Integer.parseInt(userId));
|
|
|
|
|
if (targetEntityOptional.isPresent()) {
|
|
|
|
|
SysUserEntity targetEntity = targetEntityOptional.get();
|
|
|
|
|
if (!TextUtils.isEmpty(overTime)) {
|
|
|
|
|
targetEntity.setOverTime(overTime);
|
|
|
|
|
}
|
|
|
|
|
if (!TextUtils.isEmpty(remark)) {
|
|
|
|
|
targetEntity.setRemark(remark);
|
|
|
|
|
}
|
|
|
|
|
sysUserDao.save(targetEntity);
|
|
|
|
|
successIdList.add(userId);
|
|
|
|
|
} else {
|
|
|
|
|
failureIdList.add(userId);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
failureIdList.add(userId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (userIdList.size() == successIdList.size()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
|
|
|
|
}
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
if (successIdList.size() > 0) {
|
|
|
|
|
builder.append("ID:").append(ListUtils.fromStringList(successIdList, "、")).append("修改成功,");
|
|
|
|
|
}
|
|
|
|
|
builder.append("ID:").append(ListUtils.fromStringList(failureIdList, "、")).append("修改失败");
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败," + builder, locale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 20:50:49 +08:00
|
|
|
|
/**
|
|
|
|
|
* 修改vip等级
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@RequestMapping(value = "/updateviplevel", method = RequestMethod.POST)
|
|
|
|
|
public String updateVipLevel(@RequestBody SysUserVipLevelQo sysUserVipLevelQo) {
|
|
|
|
|
String ids = sysUserVipLevelQo.getIds();
|
|
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
|
|
if (ids.contains(",")) {
|
|
|
|
|
String[] splits = ids.split(",");
|
|
|
|
|
if (splits != null && splits.length > 0) {
|
|
|
|
|
for (String split : splits) {
|
|
|
|
|
idList.add(Integer.parseInt(split));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
idList.add(Integer.parseInt(ids));
|
|
|
|
|
}
|
|
|
|
|
for (Integer id : idList) {
|
|
|
|
|
sysUserDao.updateVipLevel(id, sysUserVipLevelQo.getVipLevel());
|
|
|
|
|
}
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改是否接收短信
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@RequestMapping(value = "/updatereceivesms", method = RequestMethod.POST)
|
|
|
|
|
public String updateReceiveSms(@RequestBody SysUserReceiveSmsQo sysUserReceiveSmsQo) {
|
|
|
|
|
String ids = sysUserReceiveSmsQo.getIds();
|
|
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
|
|
if (ids.contains(",")) {
|
|
|
|
|
String[] splits = ids.split(",");
|
|
|
|
|
if (splits != null && splits.length > 0) {
|
|
|
|
|
for (String split : splits) {
|
|
|
|
|
idList.add(Integer.parseInt(split));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
idList.add(Integer.parseInt(ids));
|
|
|
|
|
}
|
|
|
|
|
for (Integer id : idList) {
|
|
|
|
|
sysUserDao.updateReceiveSms(id, sysUserReceiveSmsQo.getReceiveSms());
|
|
|
|
|
}
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 11:45:46 +08:00
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@RequestMapping(value = "/updateremark", method = RequestMethod.POST)
|
|
|
|
|
public String updateRemark(@RequestBody SysUserRemarkQo sysUserRemarkQo) {
|
|
|
|
|
Integer id = sysUserRemarkQo.getId();
|
|
|
|
|
Optional<SysUserEntity> optionalById = sysUserDao.findById(id);
|
|
|
|
|
if (optionalById.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "修改失败,用户找不到", locale);
|
|
|
|
|
}
|
|
|
|
|
sysUserDao.updateRemark(id, sysUserRemarkQo.getRemark());
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:51:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* 登录用户Token验证
|
|
|
|
|
*/
|
2022-05-06 17:49:37 +08:00
|
|
|
|
@RequestMapping(value = "/logged/check", method = RequestMethod.POST)
|
|
|
|
|
public String loginUserTokenCheck() {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/check/duplicate", method = RequestMethod.POST)
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String checkDuplicate(@RequestParam(value = "userName", required = false) String userName) {
|
2022-07-07 08:57:51 +08:00
|
|
|
|
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 验证用户名是否重复
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (!sysUserService.checkUserName(userName)) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OK", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 08:57:51 +08:00
|
|
|
|
@GetMapping("/selectAgentOrgList")
|
|
|
|
|
public String selectAgentOrgList() {
|
2022-10-08 11:11:02 +08:00
|
|
|
|
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll(Sort.by(Sort.Direction.ASC, "id"));
|
2022-07-07 08:57:51 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, agentOrgList, locale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:46:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 注册系统用户
|
|
|
|
|
*/
|
2021-07-12 14:51:34 +08:00
|
|
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
2022-05-19 10:13:26 +08:00
|
|
|
|
public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult, HttpServletRequest servletRequest) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 验证数据合法性
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
|
|
return outputEncapsulationErrorList(bindingResult.getFieldErrors(), locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
// 验证用户名是否重复
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (!sysUserService.checkUserName(userQo.getUserName())) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
// 添加新用户
|
2022-05-19 10:13:26 +08:00
|
|
|
|
return sysUserService.addUser(userQo, servletRequest);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 17:18:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除系统用户
|
|
|
|
|
*/
|
2022-05-12 09:04:50 +08:00
|
|
|
|
@RequestMapping(value = "/general/deletesysuser", method = RequestMethod.DELETE)
|
|
|
|
|
public String deleteSysUser(@RequestParam(value = "userName") String userName) {
|
|
|
|
|
return sysUserService.deleteSysUser(userName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:51:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* 软删除指定id的普通用户
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "/general/delete", method = RequestMethod.DELETE)
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String deleteCustomUser(@RequestParam(value = "userId", required = false) int id) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 验证数据合法性
|
|
|
|
|
int res = sysUserService.softDeleteGeneralUser(id);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (res == 1) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
} else {
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String updateUser(@Validated({SysUserQoUpdate.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 验证数据合法性
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
|
|
return outputEncapsulationErrorList(bindingResult.getFieldErrors(), locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
// 修改用户
|
|
|
|
|
sysUserService.updateSysUser(userQo);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OK", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断用户名是否存在
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/booleanUserName")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String booleanUserName(@RequestParam("userName") String userName) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
Map map = new HashMap(3);
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(userName);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
map.put("status", 0);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
|
|
|
|
|
} else {
|
|
|
|
|
map.put("status", 1);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查看用户信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/selectAllUser")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String selectAllUser(@RequestHeader(value = "Authorization") String token) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 验证token
|
|
|
|
|
String tokenUserName = TokenUtil.getTokenUserName(token);
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
List<SysUserVo> sysUserVos = sysUserService.selectAllUser();
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserVos == null || sysUserVos.size() == 0) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有任何用户数据", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserVos, locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员进行启用禁用的操作
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/operateActiveFlag")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String operateActiveFlag(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
Integer userId = (Integer) map.get("userId");
|
|
|
|
|
String keepType = (String) map.get("keepType");
|
|
|
|
|
// 验证token
|
|
|
|
|
String tokenUserName = TokenUtil.getTokenUserName(token);
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
// 如果keepType等于1进行启用操作
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if ("1".equals(keepType)) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
sysUserService.updateEnable(userId);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "启用成功", locale);
|
|
|
|
|
} else {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
sysUserService.updateDisable(userId);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "禁用成功", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户修改密码
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updatePassword")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String updatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
String oldPassword = (String) map.get("oldPassword");
|
|
|
|
|
String newPassword = (String) map.get("newPassword");
|
|
|
|
|
String confirmPassword = (String) map.get("confirmPassword");
|
|
|
|
|
// 验证token
|
|
|
|
|
String tokenUserName = TokenUtil.getTokenUserName(token);
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return sysUserService.updatePassword(oldPassword, newPassword, confirmPassword, sysUserEntity);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员修改用户的密码
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/adminUpdatePassword")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String adminUpdatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
2021-07-12 14:51:34 +08:00
|
|
|
|
// 要修改的用户的id
|
|
|
|
|
Integer userId = (Integer) map.get("userId");
|
|
|
|
|
String newPassword = (String) map.get("newPassword");
|
|
|
|
|
String confirmPassword = (String) map.get("confirmPassword");
|
|
|
|
|
// 验证token
|
|
|
|
|
String tokenUserName = TokenUtil.getTokenUserName(token);
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return sysUserService.adminUpdatePassword(userId, newPassword, confirmPassword);
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 15:55:27 +08:00
|
|
|
|
/**
|
|
|
|
|
* 用户忘记密码
|
|
|
|
|
*/
|
2022-05-06 17:49:37 +08:00
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
2021-12-06 15:55:27 +08:00
|
|
|
|
@PostMapping("/userUnRememberPassword")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String userUnRememberPassword(@RequestBody Map map) {
|
2021-12-06 15:55:27 +08:00
|
|
|
|
String phone = (String) map.get("phone");
|
|
|
|
|
String newPassword = (String) map.get("newPassword");
|
|
|
|
|
String confirmPassword = (String) map.get("confirmPassword");
|
|
|
|
|
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(phone);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserEntity == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (!newPassword.equals(confirmPassword)) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "两次密码输入不一致", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
|
|
|
|
String newAfterPassword = encry256(newPassword + sysUserEntity.getSalt());
|
2022-05-06 17:49:37 +08:00
|
|
|
|
sysUserDao.updatePassword(sysUserEntity.getId(), newAfterPassword);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "密码修改成功", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 09:30:48 +08:00
|
|
|
|
/**
|
2022-07-06 17:46:57 +08:00
|
|
|
|
* 发送验证码
|
2021-08-04 09:30:48 +08:00
|
|
|
|
*/
|
2021-08-03 18:03:44 +08:00
|
|
|
|
@GetMapping("/verificationCode")
|
2022-07-06 17:46:57 +08:00
|
|
|
|
public String verificationCode(@RequestParam("phone") String phone, @RequestParam(value = "agentOrgId", required = false) String agentOrgId) throws Exception {
|
|
|
|
|
Long finalAgentOrgId = Long.parseLong(TextUtils.isEmpty(agentOrgId) ? "1" : agentOrgId);
|
|
|
|
|
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
|
|
|
|
String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(finalAgentOrgId, agentOrgList);
|
2021-08-03 18:03:44 +08:00
|
|
|
|
String optCode = String.valueOf(RandomUtil.returnCode());
|
2022-05-06 17:49:37 +08:00
|
|
|
|
redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
|
2022-07-06 17:46:57 +08:00
|
|
|
|
smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
|
2021-08-03 18:03:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 15:55:27 +08:00
|
|
|
|
/**
|
|
|
|
|
* 填写手机号发送验证码,用于用户忘记密码
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/verificationCodeUpdate")
|
2022-07-06 17:46:57 +08:00
|
|
|
|
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws Exception {
|
2021-12-06 15:55:27 +08:00
|
|
|
|
SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (sysUserVo == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
2022-07-06 17:46:57 +08:00
|
|
|
|
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
|
|
|
|
String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(sysUserVo.getAgentOrgId(), agentOrgList);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
String optCode = String.valueOf(RandomUtil.returnCode());
|
2022-05-06 17:49:37 +08:00
|
|
|
|
redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
|
2022-07-06 17:46:57 +08:00
|
|
|
|
smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入验证码进行判断
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/getVerificationCode")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode) {
|
2021-12-06 15:55:27 +08:00
|
|
|
|
String o = (String) redisService.get(phone);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if ("".equals(o) || o == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "请先发送验证码!", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if (!redisService.get(phone).equals(verificationCode)) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "验证码错误,请重新输入!", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "true", locale);
|
2021-12-06 15:55:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 16:17:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* 更改账号过期时间
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updateExpireDate")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String updateExpireDate(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
2021-08-04 16:17:58 +08:00
|
|
|
|
Integer userId = (Integer) map.get("userId");
|
|
|
|
|
Integer timeNum = (Integer) map.get("timeNum");
|
|
|
|
|
String keepType = (String) map.get("keepType");
|
2022-05-06 17:49:37 +08:00
|
|
|
|
if ("1".equals(keepType)) {
|
2021-08-04 16:17:58 +08:00
|
|
|
|
return sysUserService.updateExpireDateDay(userId, timeNum);
|
2022-05-06 17:49:37 +08:00
|
|
|
|
} else if ("2".equals(keepType)) {
|
|
|
|
|
return sysUserService.updateExpireDateMonth(userId, timeNum);
|
|
|
|
|
} else if ("3".equals(keepType)) {
|
|
|
|
|
return sysUserService.updateExpireDateYear(userId, timeNum);
|
|
|
|
|
} else {
|
2021-08-04 16:17:58 +08:00
|
|
|
|
return sysUserService.updatePermanent(userId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 16:32:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 修改账号到期时间
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updateOverTime")
|
2022-05-06 17:49:37 +08:00
|
|
|
|
public String updateOverTime(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
2021-08-06 16:32:57 +08:00
|
|
|
|
Integer userId = (Integer) map.get("userId");
|
|
|
|
|
String overTime = (String) map.get("overTime");
|
2022-05-06 17:49:37 +08:00
|
|
|
|
return sysUserService.updateOverTime(userId, overTime);
|
2021-08-06 16:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:51:34 +08:00
|
|
|
|
}
|