|
|
|
@ -1,19 +1,30 @@ |
|
|
|
package cc.hiver.mall.controller; |
|
|
|
|
|
|
|
import cc.hiver.core.common.utils.PageUtil; |
|
|
|
import cc.hiver.core.common.utils.ResultUtil; |
|
|
|
import cc.hiver.core.common.utils.StringUtils; |
|
|
|
import cc.hiver.core.common.vo.PageVo; |
|
|
|
import cc.hiver.core.common.vo.Result; |
|
|
|
import cc.hiver.core.entity.Role; |
|
|
|
import cc.hiver.core.entity.User; |
|
|
|
import cc.hiver.core.entity.UserRole; |
|
|
|
import cc.hiver.core.service.RoleService; |
|
|
|
import cc.hiver.core.service.UserRoleService; |
|
|
|
import cc.hiver.core.service.UserService; |
|
|
|
import cc.hiver.mall.entity.Customer; |
|
|
|
import cc.hiver.mall.pojo.dto.DebtCustomer; |
|
|
|
import cc.hiver.mall.service.mybatis.CustomerService; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
import org.springframework.data.domain.PageRequest; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
@ -32,10 +43,23 @@ public class CustomerController { |
|
|
|
@Autowired |
|
|
|
private UserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserRoleService userRoleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RoleService roleService; |
|
|
|
|
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST) |
|
|
|
@ApiOperation(value = "新增客户") |
|
|
|
@Transactional |
|
|
|
public Result save(Customer customer) { |
|
|
|
boolean result =true; |
|
|
|
|
|
|
|
User byUsername = userService.findByUsername(customer.getUserName()); |
|
|
|
User byMobile = userService.findByMobile(customer.getPhone()); |
|
|
|
if (!ObjectUtils.isEmpty(byUsername) || !ObjectUtils.isEmpty(byMobile)){ |
|
|
|
return ResultUtil.error("该账号或手机号已存在。"); |
|
|
|
} |
|
|
|
String encryptPass = new BCryptPasswordEncoder().encode("123456");//默认密码
|
|
|
|
User user = new User(); |
|
|
|
user.setUsername(customer.getUserName()); |
|
|
|
@ -47,8 +71,17 @@ public class CustomerController { |
|
|
|
user.setPassword(encryptPass); |
|
|
|
User saveUser = userService.save(user); |
|
|
|
customer.setUserId(saveUser.getId()); |
|
|
|
boolean result = customerService.save(customer); |
|
|
|
|
|
|
|
result = customerService.save(customer); |
|
|
|
UserRole userRole = new UserRole(); |
|
|
|
PageVo pageVo = new PageVo(); |
|
|
|
pageVo.setPageNumber(1); |
|
|
|
pageVo.setPageSize(1); |
|
|
|
Page<Role> rolePage = roleService.findByCondition("ROLE_CUSTOMER", PageUtil.initPage(pageVo)); |
|
|
|
Role role = rolePage.getContent().get(0); |
|
|
|
userRole.setRoleId(role.getId());//客户角色
|
|
|
|
userRole.setRoleName("客户"); |
|
|
|
userRole.setUserId(saveUser.getId()); |
|
|
|
userRoleService.save(userRole); |
|
|
|
if(result) { |
|
|
|
return ResultUtil.success("添加成功"); |
|
|
|
} else { |
|
|
|
@ -111,4 +144,11 @@ public class CustomerController { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/debt", method = RequestMethod.GET) |
|
|
|
@ApiOperation(value = "查询欠款客户列表") |
|
|
|
public Result debt(String shopId) { |
|
|
|
List<DebtCustomer> list = customerService.debt(shopId); |
|
|
|
return new ResultUtil<List<DebtCustomer>>().setData(list); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|