|
|
|
@ -56,20 +56,25 @@ import org.springblade.common.constant.RedisKeyConstant;
|
|
|
|
|
import org.springblade.common.constant.basiccode.BasicCodeShowConstant; |
|
|
|
|
import org.springblade.common.constant.basiccode.BasicCodeTypeConstant; |
|
|
|
|
import org.springblade.common.model.dto.NameDTO; |
|
|
|
|
import org.springblade.core.excel.util.ExcelUtil; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springblade.core.secure.BladeUser; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.system.cache.DictBizCache; |
|
|
|
|
import org.springblade.system.entity.DictBiz; |
|
|
|
|
import org.springblade.system.feign.IUserClient; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -206,7 +211,7 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
} |
|
|
|
|
//添加
|
|
|
|
|
boolean save = this.save(basicdataClient); |
|
|
|
|
if (save){ |
|
|
|
|
if (save) { |
|
|
|
|
//进行redis的设置
|
|
|
|
|
redis.set(RedisKeyConstant.FINAL_CLIENT_CODE + AuthUtil.getTenantId(), basicdataClient.getClientCode()); |
|
|
|
|
} |
|
|
|
@ -372,23 +377,29 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
|
|
|
|
|
// 处理下空格 换行
|
|
|
|
|
i.setClientName(i.getClientName().trim()); |
|
|
|
|
i.setClientCode(i.getClientCode().trim()); |
|
|
|
|
// i.setClientCode(i.getClientCode().trim());
|
|
|
|
|
|
|
|
|
|
log.info("导入数据《》《》{}", i); |
|
|
|
|
if (set.isEmpty()) { |
|
|
|
|
set.add(i.getClientCode()); |
|
|
|
|
} else { |
|
|
|
|
boolean b = set.stream().anyMatch(a -> a.equals(i.getClientCode())); |
|
|
|
|
if (b) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ObjectUtils.isNull(i.getClientCode()) || ObjectUtils.isNull(i.getClientName())) { |
|
|
|
|
// if (set.isEmpty()) {
|
|
|
|
|
// set.add(i.getClientCode());
|
|
|
|
|
// } else {
|
|
|
|
|
// boolean b = set.stream().anyMatch(a -> a.equals(i.getClientCode()));
|
|
|
|
|
// if (b) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (ObjectUtils.isNull(i.getClientCode()) || ObjectUtils.isNull(i.getClientName())) {
|
|
|
|
|
// throw new ServiceException("客户编码或客户名称不能为空!");
|
|
|
|
|
// }
|
|
|
|
|
if (ObjectUtils.isNull(i.getClientName())) { |
|
|
|
|
throw new ServiceException("客户编码或客户名称不能为空!"); |
|
|
|
|
} |
|
|
|
|
BasicdataClientEntity basicdataClient = new BasicdataClientEntity(); |
|
|
|
|
BeanUtil.copyProperties(i, basicdataClient); |
|
|
|
|
|
|
|
|
|
//系统生成码值
|
|
|
|
|
String finallyClientCode = this.getFinallyClientCode(); |
|
|
|
|
basicdataClient.setClientCode(finallyClientCode); |
|
|
|
|
//将这个最新的防止缓存中
|
|
|
|
|
|
|
|
|
|
log.info(">>>>>> basicdataClient.getClientCode() {}", basicdataClient.getClientCode()); |
|
|
|
|
//查询客户编码和客户名称是否存在
|
|
|
|
@ -397,15 +408,14 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
log.info(">>>>>>>>>>>>> 1{}", ii.getClientCode()); |
|
|
|
|
log.info(">>>>>>>>>>>>> 2{}", ii.getClientName()); |
|
|
|
|
|
|
|
|
|
return ii.getClientCode().equals(basicdataClient.getClientCode()) |
|
|
|
|
|| ii.getClientName().equals(basicdataClient.getClientName().trim()); |
|
|
|
|
return ii.getClientCode().equals(basicdataClient.getClientCode()) |
|
|
|
|
|| ii.getClientName().equals(basicdataClient.getClientName().trim()); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (b) { |
|
|
|
|
List<BasicdataClientEntity> basicdataClientEntities = basicdataClients.stream().filter(ii -> ii.getClientCode().equals(basicdataClient.getClientCode()) |
|
|
|
|
|| ii.getClientName().equals(basicdataClient.getClientName())).collect(Collectors.toList()); |
|
|
|
|
List<BasicdataClientEntity> basicdataClientEntities = basicdataClients.stream().filter(ii -> ii.getClientName().equals(basicdataClient.getClientName())).collect(Collectors.toList()); |
|
|
|
|
log.info("###############basicdataClientEntities重复客户:{}", basicdataClientEntities); |
|
|
|
|
throw new ServiceException("客户编码或客户名称已存在"); |
|
|
|
|
} |
|
|
|
@ -413,8 +423,10 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
Optional<DictBiz> clientFirst = clientBiz.stream().filter(ii -> ii.getDictValue().equals(i.getClientType())).findFirst(); |
|
|
|
|
// i.setTypeService(first.get().getDictValue());
|
|
|
|
|
basicdataClient.setClientType(clientFirst.get().getDictKey()); |
|
|
|
|
//查询是不是重复
|
|
|
|
|
List<BasicdataClientEntity> basicdataClientEntities = baseMapper.selectList(Wrappers.<BasicdataClientEntity>query().lambda().eq(BasicdataClientEntity::getClientCode, i.getClientCode())); |
|
|
|
|
//查询客户名称是不是重复
|
|
|
|
|
List<BasicdataClientEntity> basicdataClientEntities = baseMapper.selectList(Wrappers.<BasicdataClientEntity>query().lambda() |
|
|
|
|
.eq(BasicdataClientEntity::getClientName, i.getClientName()) |
|
|
|
|
); |
|
|
|
|
if (basicdataClientEntities.isEmpty()) { |
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
basicdataClient.setPid(0L); |
|
|
|
@ -430,6 +442,7 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
basicdataClient.setDefaultPaymentMethods(keyValue); |
|
|
|
|
|
|
|
|
|
baseMapper.insert(basicdataClient); |
|
|
|
|
redis.set(RedisKeyConstant.FINAL_CLIENT_CODE + AuthUtil.getTenantId(), basicdataClient.getClientCode()); |
|
|
|
|
if (ObjectUtils.isNull(basicdataClient.getId())) { |
|
|
|
|
throw new ServiceException("客户ID不存在"); |
|
|
|
|
} |
|
|
|
@ -678,21 +691,21 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
@Override |
|
|
|
|
public String getFinallyClientCode() { |
|
|
|
|
|
|
|
|
|
String tenantCode ="HT"; |
|
|
|
|
String tenantCode = "HT"; |
|
|
|
|
BasicTenantCodeEntity basicTenantCodeByCodeAndShowType = basicTenantCodeClient.findBasicTenantCodeByCodeAndShowType(BasicCodeTypeConstant.CLIENT_CODE.getValue(), BasicCodeShowConstant.QR_CODE.getValue()); |
|
|
|
|
if (ObjectUtils.isNull(basicTenantCodeByCodeAndShowType)) { |
|
|
|
|
log.error("获取货区码失败"); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
tenantCode = basicTenantCodeByCodeAndShowType.getCode(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String finaClientCode = redis.get(RedisKeyConstant.FINAL_CLIENT_CODE + AuthUtil.getTenantId()); |
|
|
|
|
if (StringUtils.isBlank(finaClientCode)) { |
|
|
|
|
List<String> str = baseMapper.getFinallyClientCode(tenantCode); |
|
|
|
|
if(!str.isEmpty()){ |
|
|
|
|
if (!str.isEmpty()) { |
|
|
|
|
finaClientCode = str.get(0); |
|
|
|
|
}else{ |
|
|
|
|
finaClientCode =tenantCode+"0000000"; |
|
|
|
|
} else { |
|
|
|
|
finaClientCode = tenantCode + "0000000"; |
|
|
|
|
} |
|
|
|
|
redis.set(RedisKeyConstant.FINAL_CLIENT_CODE + AuthUtil.getTenantId(), finaClientCode); |
|
|
|
|
|
|
|
|
@ -706,12 +719,54 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
@Override |
|
|
|
|
public boolean saveClient(BasicdataClientEntity basicdataClient) { |
|
|
|
|
boolean save = this.save(basicdataClient); |
|
|
|
|
if (save){ |
|
|
|
|
if (save) { |
|
|
|
|
//进行redis的设置
|
|
|
|
|
redis.set(RedisKeyConstant.FINAL_CLIENT_CODE + AuthUtil.getTenantId(), basicdataClient.getClientCode()); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R checkImportBasicDataClient(MultipartFile file) { |
|
|
|
|
List<BasicdataClientExcel> clientExcels = ExcelUtil.read(file, BasicdataClientExcel.class); |
|
|
|
|
if (!clientExcels.isEmpty()) { |
|
|
|
|
log.info("客户导入数据"); |
|
|
|
|
//查询仓库信息
|
|
|
|
|
QueryWrapper<BasicdataClientEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
List<BasicdataClientEntity> basicdataClients = baseMapper.selectList(queryWrapper); |
|
|
|
|
LambdaQueryWrapper<BasicdataBrandEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
lambdaQueryWrapper.eq(BasicdataBrandEntity::getIsDeleted, 0); |
|
|
|
|
List<BasicdataBrandEntity> basicdataBrandEntityList = basicdataBrandService.list(lambdaQueryWrapper); |
|
|
|
|
for (BasicdataClientExcel data : clientExcels) { |
|
|
|
|
if (!basicdataClients.isEmpty()) { |
|
|
|
|
//查询客户编码和客户名称是否存在
|
|
|
|
|
boolean b = basicdataClients.stream().anyMatch(ii -> { |
|
|
|
|
if (ii.getClientName() != null && !ii.getClientName().isEmpty()) { |
|
|
|
|
return ii.getClientName().equals(data.getClientName().trim()); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
}); |
|
|
|
|
if (b) { |
|
|
|
|
String repeatClientName = basicdataClients.stream().filter(ii -> ii.getClientName().equals(data.getClientName())).map(BasicdataClientEntity::getClientName).collect(Collectors.joining(",")); |
|
|
|
|
return R.fail(repeatClientName+"客户名称已存在"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//添加品牌
|
|
|
|
|
if (ObjectUtils.isNotNull(data.getBrandName())) { |
|
|
|
|
|
|
|
|
|
String[] ars = data.getBrandName().split(","); |
|
|
|
|
|
|
|
|
|
for (String ar : ars) { |
|
|
|
|
BasicdataBrandEntity one = matchBasicdataBrandEntityListValue(basicdataBrandEntityList, ar); |
|
|
|
|
if (ObjectUtils.isNull(one)) { |
|
|
|
|
return R.fail(data.getClientName()+"品牌信息不存在"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return R.success("校验成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|