|
|
@ -2,22 +2,31 @@ package cc.hiver.mall.controller; |
|
|
|
|
|
|
|
|
import cc.hiver.app.entity.Shop; |
|
|
import cc.hiver.app.entity.Shop; |
|
|
import cc.hiver.app.service.mybatis.IShopService; |
|
|
import cc.hiver.app.service.mybatis.IShopService; |
|
|
|
|
|
import cc.hiver.core.common.exception.HiverException; |
|
|
|
|
|
import cc.hiver.core.common.utils.PageUtil; |
|
|
import cc.hiver.core.common.utils.ResultUtil; |
|
|
import cc.hiver.core.common.utils.ResultUtil; |
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
|
|
|
import cc.hiver.core.common.vo.PageVo; |
|
|
import cc.hiver.core.common.vo.Result; |
|
|
import cc.hiver.core.common.vo.Result; |
|
|
import cc.hiver.core.entity.User; |
|
|
import cc.hiver.core.common.vo.SearchVo; |
|
|
|
|
|
import cc.hiver.core.entity.*; |
|
|
|
|
|
import cc.hiver.core.service.UserService; |
|
|
import cc.hiver.mall.pojo.vo.MallUserVo; |
|
|
import cc.hiver.mall.pojo.vo.MallUserVo; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
import javax.persistence.EntityManager; |
|
|
import javax.persistence.PersistenceContext; |
|
|
import javax.persistence.PersistenceContext; |
|
|
|
|
|
import javax.validation.Valid; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@ -26,6 +35,9 @@ import java.util.List; |
|
|
@RequestMapping(value = "/hiver/app/common/") |
|
|
@RequestMapping(value = "/hiver/app/common/") |
|
|
@Transactional |
|
|
@Transactional |
|
|
public class CommonController { |
|
|
public class CommonController { |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private UserService userService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private IShopService shopService; |
|
|
private IShopService shopService; |
|
|
|
|
|
|
|
|
@ -57,4 +69,56 @@ public class CommonController { |
|
|
List<Shop> result = shopService.findByUserId(u.getId()); |
|
|
List<Shop> result = shopService.findByUserId(u.getId()); |
|
|
return new ResultUtil<List<Shop>>().setData(result); |
|
|
return new ResultUtil<List<Shop>>().setData(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/user/add", method = RequestMethod.POST) |
|
|
|
|
|
@ApiOperation(value = "添加用户") |
|
|
|
|
|
public Result add(@Valid User user) { |
|
|
|
|
|
User u = securityUtil.getCurrUser(); |
|
|
|
|
|
// 清除持久上下文环境 避免后面语句导致持久化
|
|
|
|
|
|
entityManager.detach(u); |
|
|
|
|
|
if (userService.findByMobile(user.getMobile()) != null) { |
|
|
|
|
|
throw new HiverException("该手机号已被注册"); |
|
|
|
|
|
} |
|
|
|
|
|
if(userService.findByUsername(user.getUsername()) != null) { |
|
|
|
|
|
throw new HiverException(("该用户名已被注册")); |
|
|
|
|
|
} |
|
|
|
|
|
// Username/UID 邀请码
|
|
|
|
|
|
user.setInviteCode(u.getId()).setDepartmentId(null).setDepartmentTitle("").setDescription(""); |
|
|
|
|
|
String newEncryptPass = new BCryptPasswordEncoder().encode(user.getPassword()); |
|
|
|
|
|
user.setPassword(newEncryptPass); |
|
|
|
|
|
User result = userService.save(user); |
|
|
|
|
|
return ResultUtil.success("添加成功"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/user/edit", method = RequestMethod.POST) |
|
|
|
|
|
@ApiOperation(value = "管理员修改资料") |
|
|
|
|
|
public Result edit(User u) { |
|
|
|
|
|
User old = userService.get(u.getId()); |
|
|
|
|
|
old.setNickname(u.getNickname()).setEmail(u.getEmail()).setAddress(u.getAddress()) |
|
|
|
|
|
.setStreet(u.getStreet()).setSex(u.getSex()).setAvatar(u.getAvatar()); |
|
|
|
|
|
userService.update(old); |
|
|
|
|
|
return ResultUtil.success("修改成功"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/user/delByIds", method = RequestMethod.POST) |
|
|
|
|
|
@ApiOperation(value = "批量通过ids删除") |
|
|
|
|
|
public Result delAllByIds(@RequestParam String[] ids) { |
|
|
|
|
|
for (String id : ids) { |
|
|
|
|
|
userService.delete(id); |
|
|
|
|
|
} |
|
|
|
|
|
return ResultUtil.success("批量通过id删除数据成功"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/user/getByCondition", method = RequestMethod.GET) |
|
|
|
|
|
@ApiOperation(value = "多条件分页获取用户列表") |
|
|
|
|
|
public Result<Page<User>> getByCondition(User user, |
|
|
|
|
|
SearchVo searchVo, |
|
|
|
|
|
PageVo pageVo) { |
|
|
|
|
|
User u = securityUtil.getCurrUser(); |
|
|
|
|
|
// 清除持久上下文环境 避免后面语句导致持久化
|
|
|
|
|
|
entityManager.detach(u); |
|
|
|
|
|
user.setInviteCode(u.getId()); // 设置关联条件
|
|
|
|
|
|
Page<User> page = userService.findByConditionForMobile(user, searchVo, PageUtil.initPage(pageVo)); |
|
|
|
|
|
return new ResultUtil<Page<User>>().setData(page); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|