|
|
|
|
@@ -8,11 +8,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.gxwebsoft.common.core.annotation.OperationLog;
|
|
|
|
|
import com.gxwebsoft.common.core.config.ConfigProperties;
|
|
|
|
|
import com.gxwebsoft.common.core.security.JwtSubject;
|
|
|
|
|
import com.gxwebsoft.common.core.security.JwtUtil;
|
|
|
|
|
import com.gxwebsoft.common.core.utils.CommonUtil;
|
|
|
|
|
import com.gxwebsoft.common.core.web.*;
|
|
|
|
|
import com.gxwebsoft.common.system.entity.*;
|
|
|
|
|
import com.gxwebsoft.common.system.param.UserImportParam;
|
|
|
|
|
import com.gxwebsoft.common.system.param.UserParam;
|
|
|
|
|
import com.gxwebsoft.common.system.result.LoginResult;
|
|
|
|
|
import com.gxwebsoft.common.system.service.DictionaryDataService;
|
|
|
|
|
import com.gxwebsoft.common.system.service.OrganizationService;
|
|
|
|
|
import com.gxwebsoft.common.system.service.RoleService;
|
|
|
|
|
@@ -51,8 +55,10 @@ public class UserController extends BaseController {
|
|
|
|
|
private OrganizationService organizationService;
|
|
|
|
|
@Resource
|
|
|
|
|
private DictionaryDataService dictionaryDataService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ConfigProperties configProperties;
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
|
|
|
|
@ApiOperation("分页查询用户")
|
|
|
|
|
@GetMapping("/page")
|
|
|
|
|
public ApiResult<PageResult<User>> page(UserParam param) {
|
|
|
|
|
@@ -63,7 +69,7 @@ public class UserController extends BaseController {
|
|
|
|
|
@ApiOperation("查询全部用户")
|
|
|
|
|
@GetMapping()
|
|
|
|
|
public ApiResult<List<User>> list(UserParam param) {
|
|
|
|
|
return success(userService.listRel(param));
|
|
|
|
|
return success(userService.listRel(param));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
|
|
|
|
@@ -77,7 +83,17 @@ public class UserController extends BaseController {
|
|
|
|
|
@ApiOperation("根据手机号码查询用户")
|
|
|
|
|
@GetMapping("/getByPhone/{phone}")
|
|
|
|
|
public ApiResult<User> getByPhone(@PathVariable("phone") String phone) {
|
|
|
|
|
return success(userService.getByPhone(phone));
|
|
|
|
|
return success(userService.getByPhone(phone));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("手机号登录(测试用)")
|
|
|
|
|
@PostMapping("/loginByPhoneForTest")
|
|
|
|
|
public ApiResult<?> loginByPhoneForTest(@RequestBody User user) {
|
|
|
|
|
User getLoginUser = userService.getByPhone(user.getPhone());
|
|
|
|
|
if (!user.getPhoneLoginCode().equals("1700083")) return fail("验证码错误");
|
|
|
|
|
String access_token = JwtUtil.buildToken(new JwtSubject(getLoginUser.getUsername(), getLoginUser.getTenantId()),
|
|
|
|
|
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
|
|
|
|
return success("登录成功", new LoginResult(access_token, user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:user:save')")
|
|
|
|
|
@@ -88,11 +104,11 @@ public class UserController extends BaseController {
|
|
|
|
|
user.setPassword(userService.encodePassword(user.getPassword()));
|
|
|
|
|
// 排重
|
|
|
|
|
final User byPhone = userService.getByPhone(user.getPhone());
|
|
|
|
|
if(ObjectUtil.isNotEmpty(byPhone)){
|
|
|
|
|
return fail("该手机号码已存在");
|
|
|
|
|
if (ObjectUtil.isNotEmpty(byPhone)) {
|
|
|
|
|
return fail("该手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
if (userService.saveUser(user)) {
|
|
|
|
|
return success("添加成功",user.getUserId());
|
|
|
|
|
return success("添加成功", user.getUserId());
|
|
|
|
|
}
|
|
|
|
|
return fail("添加失败");
|
|
|
|
|
}
|
|
|
|
|
@@ -101,48 +117,48 @@ public class UserController extends BaseController {
|
|
|
|
|
@ApiOperation("批量添加用户")
|
|
|
|
|
@PostMapping("/batch")
|
|
|
|
|
public ApiResult<?> saveBatch(@RequestBody List<User> userList) {
|
|
|
|
|
userList.forEach(d -> {
|
|
|
|
|
d.setStatus(0);
|
|
|
|
|
if (d.getPassword() != null) {
|
|
|
|
|
d.setPassword(userService.encodePassword(d.getPassword()));
|
|
|
|
|
userList.forEach(d -> {
|
|
|
|
|
d.setStatus(0);
|
|
|
|
|
if (d.getPassword() != null) {
|
|
|
|
|
d.setPassword(userService.encodePassword(d.getPassword()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final Set<String> collect = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
|
|
|
|
final List<User> list = userService.list(new LambdaQueryWrapper<User>().in(User::getPhone, collect).select(User::getPhone));
|
|
|
|
|
System.out.println("list = " + list);
|
|
|
|
|
final Map<String, List<User>> phoneCollect = list.stream().collect(Collectors.groupingBy(User::getPhone));
|
|
|
|
|
System.out.println("phoneCollect = " + phoneCollect);
|
|
|
|
|
userList.removeIf(d -> phoneCollect.containsKey(d.getPhone()));
|
|
|
|
|
System.out.println("phoneCollect = " + phoneCollect);
|
|
|
|
|
|
|
|
|
|
if (userService.saveBatch(userList)) {
|
|
|
|
|
return success("添加成功");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final Set<String> collect = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
|
|
|
|
final List<User> list = userService.list(new LambdaQueryWrapper<User>().in(User::getPhone, collect).select(User::getPhone));
|
|
|
|
|
System.out.println("list = " + list);
|
|
|
|
|
final Map<String, List<User>> phoneCollect = list.stream().collect(Collectors.groupingBy(User::getPhone));
|
|
|
|
|
System.out.println("phoneCollect = " + phoneCollect);
|
|
|
|
|
userList.removeIf(d -> phoneCollect.containsKey(d.getPhone()));
|
|
|
|
|
System.out.println("phoneCollect = " + phoneCollect);
|
|
|
|
|
|
|
|
|
|
if (userService.saveBatch(userList)) {
|
|
|
|
|
return success("添加成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("添加失败");
|
|
|
|
|
return fail("添加失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:user:save')")
|
|
|
|
|
@ApiOperation("批量添加用户并返回userId")
|
|
|
|
|
@PostMapping("/batchBackUserId")
|
|
|
|
|
public ApiResult<?> saveBatchBackUserId(@RequestBody List<User> userList) {
|
|
|
|
|
userList.forEach(d -> {
|
|
|
|
|
d.setStatus(0);
|
|
|
|
|
d.setPassword(userService.encodePassword(d.getPassword()));
|
|
|
|
|
});
|
|
|
|
|
final Set<String> phones = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
|
|
|
|
if (userService.saveBatch(userList)) {
|
|
|
|
|
final UserParam userParam = new UserParam();
|
|
|
|
|
userParam.setPhones(phones);
|
|
|
|
|
userParam.setLimit(500L);
|
|
|
|
|
final PageResult<User> result = userService.pageRel(userParam);
|
|
|
|
|
final Set<Integer> collect = result.getList().stream().map(User::getUserId).collect(Collectors.toSet());
|
|
|
|
|
return success("添加成功",collect);
|
|
|
|
|
}
|
|
|
|
|
return fail("添加失败");
|
|
|
|
|
userList.forEach(d -> {
|
|
|
|
|
d.setStatus(0);
|
|
|
|
|
d.setPassword(userService.encodePassword(d.getPassword()));
|
|
|
|
|
});
|
|
|
|
|
final Set<String> phones = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
|
|
|
|
if (userService.saveBatch(userList)) {
|
|
|
|
|
final UserParam userParam = new UserParam();
|
|
|
|
|
userParam.setPhones(phones);
|
|
|
|
|
userParam.setLimit(500L);
|
|
|
|
|
final PageResult<User> result = userService.pageRel(userParam);
|
|
|
|
|
final Set<Integer> collect = result.getList().stream().map(User::getUserId).collect(Collectors.toSet());
|
|
|
|
|
return success("添加成功", collect);
|
|
|
|
|
}
|
|
|
|
|
return fail("添加失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @PreAuthorize("hasAuthority('sys:user:update')")
|
|
|
|
|
// @PreAuthorize("hasAuthority('sys:user:update')")
|
|
|
|
|
@OperationLog
|
|
|
|
|
@ApiOperation("修改用户")
|
|
|
|
|
@PutMapping()
|
|
|
|
|
@@ -188,7 +204,7 @@ public class UserController extends BaseController {
|
|
|
|
|
@DeleteMapping("/batch")
|
|
|
|
|
public ApiResult<?> deleteBatch(@RequestBody List<Integer> ids) {
|
|
|
|
|
if (userService.removeByIds(ids)) {
|
|
|
|
|
return success("删除成功");
|
|
|
|
|
return success("删除成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("删除失败");
|
|
|
|
|
}
|
|
|
|
|
@@ -215,16 +231,16 @@ public class UserController extends BaseController {
|
|
|
|
|
@ApiOperation("修改推荐状态")
|
|
|
|
|
@PutMapping("/recommend")
|
|
|
|
|
public ApiResult<?> updateRecommend(@RequestBody User user) {
|
|
|
|
|
if (user.getUserId() == null || user.getRecommend() == null || !Arrays.asList(0, 1).contains(user.getRecommend())) {
|
|
|
|
|
return fail("参数不正确");
|
|
|
|
|
}
|
|
|
|
|
User u = new User();
|
|
|
|
|
u.setUserId(user.getUserId());
|
|
|
|
|
u.setRecommend(user.getRecommend());
|
|
|
|
|
if (userService.updateById(u)) {
|
|
|
|
|
return success("修改成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("修改失败");
|
|
|
|
|
if (user.getUserId() == null || user.getRecommend() == null || !Arrays.asList(0, 1).contains(user.getRecommend())) {
|
|
|
|
|
return fail("参数不正确");
|
|
|
|
|
}
|
|
|
|
|
User u = new User();
|
|
|
|
|
u.setUserId(user.getUserId());
|
|
|
|
|
u.setRecommend(user.getRecommend());
|
|
|
|
|
if (userService.updateById(u)) {
|
|
|
|
|
return success("修改成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("修改失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:user:update')")
|
|
|
|
|
@@ -364,36 +380,55 @@ public class UserController extends BaseController {
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
|
|
|
|
@PostMapping("/getAvatarByMpWx")
|
|
|
|
|
@ApiOperation("更新微信头像")
|
|
|
|
|
public ApiResult<?> getAvatarByMpWx(@RequestBody User user){
|
|
|
|
|
user.setAvatar("https://oa.gxwebsoft.com/assets/logo.7ccfefb9.svg");
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("更新成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("更新失败");
|
|
|
|
|
public ApiResult<?> getAvatarByMpWx(@RequestBody User user) {
|
|
|
|
|
user.setAvatar("https://oa.gxwebsoft.com/assets/logo.7ccfefb9.svg");
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("更新成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("更新失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/updatePointsBySign")
|
|
|
|
|
@ApiOperation("签到成功累加积分")
|
|
|
|
|
public ApiResult<?> updatePointsBySign(){
|
|
|
|
|
final User loginUser = getLoginUser();
|
|
|
|
|
loginUser.setPoints(loginUser.getPoints() + 1);
|
|
|
|
|
if (userService.updateUser(loginUser)) {
|
|
|
|
|
return success("签到成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("签到失败");
|
|
|
|
|
public ApiResult<?> updatePointsBySign() {
|
|
|
|
|
final User loginUser = getLoginUser();
|
|
|
|
|
loginUser.setPoints(loginUser.getPoints() + 1);
|
|
|
|
|
if (userService.updateUser(loginUser)) {
|
|
|
|
|
return success("签到成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("签到失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
|
|
|
|
@PutMapping("/updateUserBalance")
|
|
|
|
|
@ApiOperation("更新用户余额")
|
|
|
|
|
public ApiResult<?> updateUserBalance(@RequestBody User user){
|
|
|
|
|
if (getLoginUser() == null) {
|
|
|
|
|
return fail("请先登录");
|
|
|
|
|
}
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("操作成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("操作失败");
|
|
|
|
|
public ApiResult<?> updateUserBalance(@RequestBody User user) {
|
|
|
|
|
if (getLoginUser() == null) {
|
|
|
|
|
return fail("请先登录");
|
|
|
|
|
}
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("操作成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("操作失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/updateUserBalanceWithoutLogin")
|
|
|
|
|
@ApiOperation("更新用户余额(无需登陆)")
|
|
|
|
|
public ApiResult<?> updateUserBalanceWithoutLogin(@RequestBody User user) {
|
|
|
|
|
if (user.getAuthCode() == null || !user.getAuthCode().equals("1700083"))
|
|
|
|
|
return fail("参数错误");
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("操作成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("操作失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("获取用户(无需登陆)")
|
|
|
|
|
@PostMapping("/getUserWithoutLogin")
|
|
|
|
|
public ApiResult<?> getUserWithoutLogin(@RequestBody User user) {
|
|
|
|
|
if (user.getAuthCode() == null || !user.getAuthCode().equals("1700083"))
|
|
|
|
|
return fail("参数错误");
|
|
|
|
|
return success(userService.getByIdRel(user.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAuthority('sys:user:list')")
|
|
|
|
|
@@ -401,24 +436,24 @@ public class UserController extends BaseController {
|
|
|
|
|
@ApiOperation("统计用户余额")
|
|
|
|
|
@GetMapping("/countUserBalance")
|
|
|
|
|
public ApiResult<?> countUserBalance(User param) {
|
|
|
|
|
final LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
wrapper.gt(User::getBalance, 0);
|
|
|
|
|
if (!param.getOrganizationId().equals(0)) {
|
|
|
|
|
wrapper.eq(User::getOrganizationId,param.getOrganizationId());
|
|
|
|
|
}
|
|
|
|
|
final List<User> list = userService.list(wrapper);
|
|
|
|
|
final BigDecimal totalBalance = list.stream().map(User::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
// System.out.println("统计用户余额 = " + totalBalance);
|
|
|
|
|
return success("统计成功",totalBalance);
|
|
|
|
|
final LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
wrapper.gt(User::getBalance, 0);
|
|
|
|
|
if (!param.getOrganizationId().equals(0)) {
|
|
|
|
|
wrapper.eq(User::getOrganizationId, param.getOrganizationId());
|
|
|
|
|
}
|
|
|
|
|
final List<User> list = userService.list(wrapper);
|
|
|
|
|
final BigDecimal totalBalance = list.stream().map(User::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
// System.out.println("统计用户余额 = " + totalBalance);
|
|
|
|
|
return success("统计成功", totalBalance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("更新商户ID")
|
|
|
|
|
@PutMapping("/updateUserMerchantId")
|
|
|
|
|
public ApiResult<?> updateUserMerchantId(@RequestBody User user){
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("更新成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("更新失败");
|
|
|
|
|
public ApiResult<?> updateUserMerchantId(@RequestBody User user) {
|
|
|
|
|
if (userService.updateUser(user)) {
|
|
|
|
|
return success("更新成功");
|
|
|
|
|
}
|
|
|
|
|
return fail("更新失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|