新增客户
This commit is contained in:
@ -3,6 +3,8 @@ package com.fuyuanshen.fyscustomer.domain;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.core.constant.SystemConstants;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -25,7 +27,7 @@ public class Customer extends TenantEntity {
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId(value = "user_id")
|
||||
private Long userId;
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 父id
|
||||
@ -40,13 +42,18 @@ public class Customer extends TenantEntity {
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@NotNull
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@NotNull
|
||||
private String nickName;
|
||||
|
||||
@TableField(value = "user_level")
|
||||
private Byte userLevel;
|
||||
|
||||
/**
|
||||
* 用户类型(sys_user系统用户)
|
||||
*/
|
||||
@ -110,11 +117,11 @@ public class Customer extends TenantEntity {
|
||||
|
||||
|
||||
public Customer(Long userId) {
|
||||
this.userId = userId;
|
||||
this.customerId = userId;
|
||||
}
|
||||
|
||||
public boolean isSuperAdmin() {
|
||||
return SystemConstants.SUPER_ADMIN_ID.equals(this.userId);
|
||||
return SystemConstants.SUPER_ADMIN_ID.equals(this.customerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -75,4 +75,10 @@ public class UserQueryCriteria implements Serializable {
|
||||
@Schema(name = "APP/小程序账号")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
@Schema(name = "客户名称")
|
||||
private String customerName;
|
||||
|
||||
}
|
||||
|
@ -24,4 +24,13 @@ public interface CustomerMapper extends BaseMapper<Customer> {
|
||||
List<Customer> queryAllCustomers(@Param("criteria") UserQueryCriteria criteria);
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件查询客户
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<Customer> queryCustomers(@Param("criteria") UserQueryCriteria criteria);
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.fuyuanshen.fyscustomer.service;
|
||||
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
import io.undertow.util.BadRequestException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -25,7 +26,7 @@ public interface CustomerService {
|
||||
*
|
||||
* @param customer /
|
||||
*/
|
||||
void addCustomer(Customer customer);
|
||||
void addCustomer(Customer customer) throws BadRequestException;
|
||||
|
||||
/**
|
||||
* 修改客户
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.fuyuanshen.fyscustomer.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.fyscustomer.domain.Customer;
|
||||
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
|
||||
import com.fuyuanshen.fyscustomer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.fyscustomer.service.CustomerService;
|
||||
import io.undertow.util.BadRequestException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -43,8 +46,20 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addCustomer(Customer customer) {
|
||||
public void addCustomer(Customer customer) throws BadRequestException {
|
||||
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
|
||||
UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
|
||||
userQueryCriteria.setCustomerName(customer.getUserName());
|
||||
List<Customer> customers = customerMapper.queryCustomers(userQueryCriteria);
|
||||
if (!customers.isEmpty()) {
|
||||
throw new BadRequestException("用户名已存在!!!");
|
||||
}
|
||||
customer.setUserLevel((byte) (loginUser.getUserLevel() + 1));
|
||||
customer.setPid(loginUser.getUserId());
|
||||
|
||||
save(customer);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user