|
@@ -44,7 +44,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
@@ -82,7 +81,7 @@ public class FactoryServiceImpl implements FactoryService {
|
|
|
//code不能重复
|
|
|
QueryWrapper<BaseFactory> factoryQw = new QueryWrapper<>();
|
|
|
factoryQw.eq("factory_code", req.getFactoryCode());
|
|
|
- factoryQw.eq("is_delete",0);
|
|
|
+ factoryQw.eq("is_delete", 0);
|
|
|
if (req.getId() != null) {
|
|
|
factoryQw.ne("id", req.getId());
|
|
|
}
|
|
@@ -90,16 +89,6 @@ public class FactoryServiceImpl implements FactoryService {
|
|
|
if (CollectionUtil.isNotEmpty(checkFactoryList)) {
|
|
|
throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "供应商ID已存在");
|
|
|
}
|
|
|
- //判断供应商名称是否存在
|
|
|
- if (req.getFactoryName() != null) {
|
|
|
- QueryWrapper<BaseFactory> qw = new QueryWrapper<>();
|
|
|
- qw.eq("factory_name", req.getFactoryName());
|
|
|
- qw.eq("is_delete",0);
|
|
|
- List<BaseFactory> checkNameList = baseFactoryMapper.selectList(qw);
|
|
|
- if (CollectionUtil.isNotEmpty(checkNameList)) {
|
|
|
- throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "供应商名称已存在");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//1-声明对象
|
|
|
BaseFactory factory = null;
|
|
@@ -131,8 +120,18 @@ public class FactoryServiceImpl implements FactoryService {
|
|
|
|
|
|
//3-新增or修改
|
|
|
if (req.getId() != null) {
|
|
|
+ //判断供应商名称是否存在
|
|
|
+ BaseFactory checkFactoryName = checkFactoryName(factory.getFactoryName());
|
|
|
+ if (!checkFactoryName.getId().equals(req.getId())) {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "供应商名称已存在");
|
|
|
+ }
|
|
|
baseFactoryMapper.updateById(factory);
|
|
|
} else {
|
|
|
+ //判断供应商名称是否存在
|
|
|
+ BaseFactory baseFactory = checkFactoryName(factory.getFactoryName());
|
|
|
+ if (Objects.nonNull(baseFactory)) {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), "供应商名称已存在");
|
|
|
+ }
|
|
|
baseFactoryMapper.insert(factory);
|
|
|
}
|
|
|
|
|
@@ -358,64 +357,33 @@ public class FactoryServiceImpl implements FactoryService {
|
|
|
if (StringUtils.isBlank(factoryProperty.getFactoryName())) {
|
|
|
errorMessage.append("供应商名称").append("为空,");
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(factoryProperty.getFactoryType())) {
|
|
|
- if(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()) == null){
|
|
|
- errorMessage.append("供应商类型").append("枚举值不正确,");
|
|
|
- }else {
|
|
|
- if (!FactoryTypeEnum.BEER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))) {
|
|
|
- if (StringUtils.isBlank(factoryProperty.getEmail())) {
|
|
|
- errorMessage.append("邮箱").append("为空,");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(factoryProperty.getProvince())) {
|
|
|
- errorMessage.append("省").append("为空,");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(factoryProperty.getCity())) {
|
|
|
- errorMessage.append("市").append("为空,");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(factoryProperty.getDistrict())) {
|
|
|
- errorMessage.append("区").append("为空,");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(factoryProperty.getAddress())) {
|
|
|
- errorMessage.append("详细地址").append("为空,");
|
|
|
- }
|
|
|
- }
|
|
|
- if (FactoryTypeEnum.TWO_COVER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))) {
|
|
|
- if (StringUtils.isBlank(factoryProperty.getKeymanName())) {
|
|
|
- errorMessage.append("联系人姓名").append("为空,");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(factoryProperty.getKeymanMobile())) {
|
|
|
- errorMessage.append("联系人手机号").append("为空,");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else {
|
|
|
+ if (StringUtils.isBlank(factoryProperty.getFactoryType())) {
|
|
|
errorMessage.append("供应商类型").append("为空,");
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(factoryProperty.getIsFirstFactory())) {
|
|
|
- if(FirstFactoryEnum.getCode(factoryProperty.getIsFirstFactory()) == null){
|
|
|
- errorMessage.append("是否一级供应商").append("枚举值不正确,");
|
|
|
- }
|
|
|
- }else {
|
|
|
- if (StringUtils.isNotBlank(factoryProperty.getFactoryType())
|
|
|
- && FactoryTypeEnum.COVER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))){
|
|
|
- errorMessage.append("是否一级供应商").append("为空,");
|
|
|
- }
|
|
|
+ if (StringUtils.isNotBlank(factoryProperty.getFactoryType())
|
|
|
+ && FactoryTypeEnum.getCode(factoryProperty.getFactoryType()) == null) {
|
|
|
+ errorMessage.append("供应商类型").append("枚举值不正确,");
|
|
|
}
|
|
|
- //验证手机号
|
|
|
- if (StringUtils.isNotBlank(factoryProperty.getKeymanMobile())){
|
|
|
- Pattern keymanMobileFormat = Pattern.compile("^1[0-9]{10}$");
|
|
|
- Matcher matcher = keymanMobileFormat.matcher(factoryProperty.getKeymanMobile());
|
|
|
- if (!matcher.matches()){
|
|
|
- errorMessage.append("联系人手机号").append("格式不正确,");
|
|
|
- }
|
|
|
+ if (StringUtils.isNotBlank(factoryProperty.getIsFirstFactory())
|
|
|
+ && FirstFactoryEnum.getCode(factoryProperty.getIsFirstFactory()) == null) {
|
|
|
+ errorMessage.append("是否一级供应商").append("枚举值不正确,");
|
|
|
}
|
|
|
- //验证邮箱
|
|
|
- if (StringUtils.isNotBlank(factoryProperty.getEmail())) {
|
|
|
- Pattern emailFormat = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
|
|
|
- Matcher matcher = emailFormat.matcher(factoryProperty.getEmail());
|
|
|
- if (!matcher.matches()) {
|
|
|
- errorMessage.append("邮箱").append("格式不正确,");
|
|
|
- }
|
|
|
+ if (StringUtils.isBlank(factoryProperty.getKeymanName())) {
|
|
|
+ errorMessage.append("联系人姓名").append("为空,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(factoryProperty.getKeymanMobile())) {
|
|
|
+ errorMessage.append("联系人手机号").append("为空,");
|
|
|
+ }
|
|
|
+ Pattern patternPhone = Pattern.compile("^[1]\\d{10}$");
|
|
|
+ if (!patternPhone.matcher(factoryProperty.getKeymanMobile()).matches()) {
|
|
|
+ errorMessage.append("联系人手机号").append("格式不正确,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(factoryProperty.getEmail())) {
|
|
|
+ errorMessage.append("邮箱").append("为空,");
|
|
|
+ }
|
|
|
+ Pattern patternEmail = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
|
|
|
+ if (!patternEmail.matcher(factoryProperty.getEmail()).matches()) {
|
|
|
+ errorMessage.append("邮箱").append("格式不正确,");
|
|
|
}
|
|
|
|
|
|
return errorMessage.toString();
|
|
@@ -439,6 +407,16 @@ public class FactoryServiceImpl implements FactoryService {
|
|
|
return factory;
|
|
|
}
|
|
|
|
|
|
+ private BaseFactory checkFactoryName(String factoryName) {
|
|
|
+
|
|
|
+ QueryWrapper<BaseFactory> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("factory_name", factoryName);
|
|
|
+ qw.eq("is_delete", 0);
|
|
|
+ BaseFactory baseFactory = baseFactoryMapper.selectOne(qw);
|
|
|
+
|
|
|
+ return baseFactory;
|
|
|
+ }
|
|
|
+
|
|
|
// 6.03已废弃
|
|
|
// @Override
|
|
|
// public ListFactorySelectRes listPackageFactorySelect(ListFactorySelectReq req) {
|