forked from rongchao/epmet-cloud-rizhao
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
5.9 KiB
172 lines
5.9 KiB
/**
|
|
* Copyright 2018 人人开源 https://www.renren.io
|
|
* <p>
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
* <p>
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
* <p>
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.epmet.controller;
|
|
|
|
import com.epmet.commons.tools.annotation.LoginUser;
|
|
import com.epmet.commons.tools.constant.AppClientConstant;
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode;
|
|
import com.epmet.commons.tools.exception.EpmetException;
|
|
import com.epmet.commons.tools.page.PageData;
|
|
import com.epmet.commons.tools.security.dto.TokenDto;
|
|
import com.epmet.commons.tools.utils.ConvertUtils;
|
|
import com.epmet.commons.tools.utils.ExcelUtils;
|
|
import com.epmet.commons.tools.utils.RSASignature;
|
|
import com.epmet.commons.tools.utils.Result;
|
|
import com.epmet.commons.tools.validator.AssertUtils;
|
|
import com.epmet.commons.tools.validator.ValidatorUtils;
|
|
import com.epmet.commons.tools.validator.group.AddGroup;
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup;
|
|
import com.epmet.commons.tools.validator.group.UpdateGroup;
|
|
import com.epmet.dto.OperUserDTO;
|
|
import com.epmet.dto.PasswordDTO;
|
|
import com.epmet.dto.result.QueryOperUserResultDto;
|
|
import com.epmet.excel.OperUserExcel;
|
|
import com.epmet.service.OperUserService;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
* 运营人员表
|
|
*
|
|
* @author generator generator@elink-cn.com
|
|
* @since v1.0.0 2020-03-18
|
|
*/
|
|
@RestController
|
|
@RequestMapping("operuser")
|
|
public class OperUserController {
|
|
@Value("${epmet.login.privateKey}")
|
|
private String privateKey;
|
|
|
|
@Autowired
|
|
private OperUserService operUserService;
|
|
|
|
@GetMapping("page")
|
|
public Result<PageData<OperUserDTO>> page(@RequestParam Map<String, Object> params) {
|
|
PageData<OperUserDTO> page = operUserService.page(params);
|
|
return new Result<PageData<OperUserDTO>>().ok(page);
|
|
}
|
|
|
|
@GetMapping("{id}")
|
|
public Result<OperUserDTO> get(@PathVariable("id") String id) {
|
|
OperUserDTO data = operUserService.get(id);
|
|
|
|
return new Result<OperUserDTO>().ok(data);
|
|
}
|
|
|
|
@PostMapping
|
|
public Result save(@RequestBody OperUserDTO dto) throws Exception {
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
//解密密码
|
|
if (dto.getPassword().length() > 50) {
|
|
String password = RSASignature.decryptByPrivateKey(dto.getPassword(), privateKey);
|
|
String email = RSASignature.decryptByPrivateKey(dto.getEmail(), privateKey);
|
|
String phone = RSASignature.decryptByPrivateKey(dto.getPhone(), privateKey);
|
|
dto.setPassword(password);
|
|
dto.setEmail(email);
|
|
dto.setPhone(phone);
|
|
}
|
|
operUserService.save(dto);
|
|
return new Result();
|
|
}
|
|
|
|
@PutMapping
|
|
public Result update(@RequestBody OperUserDTO dto) {
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
operUserService.update(dto);
|
|
return new Result();
|
|
}
|
|
|
|
/**
|
|
* desc:修改运营端用户 密码
|
|
* @param tokenDto
|
|
* @param dto
|
|
* @return
|
|
*/
|
|
@PostMapping(value = "updatePwd")
|
|
public Result updatePwd(@LoginUser TokenDto tokenDto,@RequestBody PasswordDTO dto) throws Exception {
|
|
if (StringUtils.isBlank(dto.getNewPassword()) && AppClientConstant.APP_OPER.equals(tokenDto.getClient())){
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"参数错误","参数错误");
|
|
}
|
|
//解密密码
|
|
if (dto.getPassword().length() > 50) {
|
|
String confirmNewPassWord = RSASignature.decryptByPrivateKey(dto.getPassword(), privateKey);
|
|
String newPassword = RSASignature.decryptByPrivateKey(dto.getNewPassword(), privateKey);
|
|
dto.setPassword(confirmNewPassWord);
|
|
dto.setNewPassword(newPassword);
|
|
if (StringUtils.isNotBlank(dto.getOldPassword())){
|
|
String oldPassWord = RSASignature.decryptByPrivateKey(dto.getOldPassword(), privateKey);
|
|
dto.setOldPassword(oldPassWord);
|
|
}
|
|
}
|
|
//校验长度和 密码是否一致。
|
|
operUserService.updatePwd(tokenDto.getUserId(),dto);
|
|
return new Result();
|
|
}
|
|
|
|
|
|
@DeleteMapping
|
|
public Result delete(@RequestBody String[] ids) {
|
|
//效验数据
|
|
AssertUtils.isArrayEmpty(ids, "id");
|
|
operUserService.delete(ids);
|
|
return new Result();
|
|
}
|
|
|
|
@GetMapping("export")
|
|
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
|
List<OperUserDTO> list = operUserService.list(params);
|
|
ExcelUtils.exportExcelToTarget(response, null, list, OperUserExcel.class);
|
|
}
|
|
|
|
/**
|
|
* 获取运营人员信息
|
|
*
|
|
* @param tokenDto token
|
|
* @return OperUserDTO
|
|
* @author zhaoqifeng
|
|
*/
|
|
@GetMapping("queryOperUserDto")
|
|
public Result<QueryOperUserResultDto> queryOperUserDto(@LoginUser TokenDto tokenDto) {
|
|
OperUserDTO data = operUserService.getOperUserInfoById(tokenDto.getUserId());
|
|
QueryOperUserResultDto dto = ConvertUtils.sourceToTarget(data, QueryOperUserResultDto.class);
|
|
return new Result<QueryOperUserResultDto>().ok(dto);
|
|
}
|
|
|
|
/**
|
|
* 获取运营人员信息
|
|
*
|
|
* @param operUserId oper_user表主键
|
|
* @return OperUserDTO
|
|
* @author zhaoqifeng
|
|
*/
|
|
@GetMapping("queryOperUserDtoById/{operUserId}")
|
|
public Result<OperUserDTO> queryOperUserDtoById(@PathVariable("operUserId") String operUserId) {
|
|
OperUserDTO data = operUserService.getOperUserInfoById(operUserId);
|
|
return new Result<OperUserDTO>().ok(data);
|
|
}
|
|
|
|
}
|
|
|