|
|
|
@ -24,21 +24,26 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.logpm.basicdata.entity.*; |
|
|
|
|
import com.logpm.basicdata.excel.BasicdataClientExcel; |
|
|
|
|
import com.logpm.basicdata.excel.BasicdataStorageServicesExcel; |
|
|
|
|
import com.logpm.basicdata.mapper.BasicdataClientMapper; |
|
|
|
|
import com.logpm.basicdata.service.*; |
|
|
|
|
import com.logpm.basicdata.vo.BasicdataClientVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.common.constant.DictBizConstant; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.system.cache.DictBizCache; |
|
|
|
|
import org.springblade.system.entity.DictBiz; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springblade.system.feign.IUserClient; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 基础客户表 服务实现类 |
|
|
|
@ -53,9 +58,12 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final IBasicdataHistoricalContractService basicdataHistoricalContractService; |
|
|
|
|
private final IBasicdataStoreContactService basicdataStoreContactService; |
|
|
|
|
private final IBasicdataStoreContactService basicdataStoreContactService; //联系人
|
|
|
|
|
private final IBasicdataStoreBusinessService basicdataStoreBusinessService; |
|
|
|
|
private final IBasicdataTripartiteMallService basicdataTripartiteMallService; |
|
|
|
|
private final IBasicdataTripartiteMallService basicdataTripartiteMallService; //三方商场
|
|
|
|
|
private final IBasicdataStorageServicesService basicdataStorageServicesService; //服务仓
|
|
|
|
|
private final IBasicdataBrandService basicdataBrandService; //品牌
|
|
|
|
|
private final IBasicdataStoreBrandService basicdataStoreBrandService; //品牌
|
|
|
|
|
private final IBasicdataWarehouseService warehouseService; |
|
|
|
|
// private final IBasicdataClientUserService basicdataClientUserService;
|
|
|
|
|
|
|
|
|
@ -255,4 +263,225 @@ public class BasicdataClientServiceImpl extends BaseServiceImpl<BasicdataClientM
|
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 导入数据 |
|
|
|
|
* @param data |
|
|
|
|
* @param isCovered |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void importClient(List<BasicdataClientExcel> data, Boolean isCovered) { |
|
|
|
|
log.info("客户导入数据"); |
|
|
|
|
List<BasicdataStoreContactEntity> storeContactEntities = new ArrayList<>(); // 联系人
|
|
|
|
|
List<BasicdataTripartiteMallEntity> tripartiteMallEntities = new ArrayList<>(); // 三方商场
|
|
|
|
|
List<BasicdataStoreBrandEntity> storeBrandEntities = new ArrayList<>(); // 品牌
|
|
|
|
|
List<BasicdataStorageServicesEntity> storageServicesEntities = new ArrayList<>(); // 服务仓
|
|
|
|
|
List<BasicdataStoreBusinessEntity> storeBusinessEntities = new ArrayList<>(); // 服务类型
|
|
|
|
|
//查询仓库信息
|
|
|
|
|
List<BasicdataWarehouseEntity> list1 = warehouseService.warehouseListqx(); |
|
|
|
|
List<DictBiz> dictBizs = DictBizCache.getList(DictBizConstant.DISTRIBUTION_TYPE);//商 市 自
|
|
|
|
|
List<DictBiz> clientBiz = DictBizCache.getList(DictBizConstant.CLIENT_TYPE); //客 工
|
|
|
|
|
List<DictBiz> freightBiz = DictBizCache.getList(DictBizConstant.BASIC_FREIGHT_TYPE); //客 工
|
|
|
|
|
Set<String> set =new HashSet<>(); |
|
|
|
|
for (BasicdataClientExcel i : data) { |
|
|
|
|
log.info("导入数据《》《》{}",i); |
|
|
|
|
if(set.isEmpty()){ |
|
|
|
|
set.add(i.getClientCode()); |
|
|
|
|
}else{ |
|
|
|
|
boolean b = set.stream().anyMatch(a -> a.equals(i.getClientCode())); |
|
|
|
|
if(b){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BasicdataClientEntity basicdataClient = new BasicdataClientEntity(); |
|
|
|
|
BeanUtil.copyProperties(i,basicdataClient); |
|
|
|
|
|
|
|
|
|
// Optional<DictBiz> first = dictBizs.stream().filter(ii -> ii.getDictValue().equals(i.getTypeService())).findFirst();
|
|
|
|
|
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())); |
|
|
|
|
if(basicdataClientEntities.isEmpty()){ |
|
|
|
|
basicdataClient.setPid("0"); |
|
|
|
|
basicdataClient.setCargoControl(false); |
|
|
|
|
basicdataClient.setStatus(0); |
|
|
|
|
basicdataClient.setIsDeleted(0); |
|
|
|
|
basicdataClient.setCreateTime(new Date()); |
|
|
|
|
baseMapper.insert(basicdataClient); |
|
|
|
|
if(ObjectUtils.isNull(basicdataClient.getId())){ |
|
|
|
|
throw new ServiceException("客户ID不存在"); |
|
|
|
|
} |
|
|
|
|
//添加服务类型
|
|
|
|
|
if(ObjectUtils.isNotNull(i.getTypeService())){ |
|
|
|
|
BasicdataStoreBusinessEntity storeBusinessEntity = new BasicdataStoreBusinessEntity(); |
|
|
|
|
storeBusinessEntity.setClientId(basicdataClient.getId().toString()); |
|
|
|
|
storeBusinessEntity.setTypeService(i.getTypeService()); |
|
|
|
|
storeBusinessEntity.setMold(i.getMold()); |
|
|
|
|
storeBusinessEntities.add(storeBusinessEntity); |
|
|
|
|
} |
|
|
|
|
//添加服务仓
|
|
|
|
|
if(ObjectUtils.isNotNull(i.getServeWarehouseName())){ |
|
|
|
|
BasicdataStorageServicesEntity servicesEntity = new BasicdataStorageServicesEntity(); |
|
|
|
|
servicesEntity.setClientId(basicdataClient.getId()); |
|
|
|
|
servicesEntity.setDistinguish(2); |
|
|
|
|
if(ObjectUtils.isNotNull(i.getSendWarehouseName())){ |
|
|
|
|
// Long id = list1.stream().filter(q -> q.getName().equals(i.getSendWarehouseName())).findFirst().get().getId();
|
|
|
|
|
// servicesEntity.setSendWarehouseId(String.valueOf(id));
|
|
|
|
|
servicesEntity.setSendWarehouseName(i.getSendWarehouseName()); |
|
|
|
|
} |
|
|
|
|
Long id = list1.stream().filter(q -> q.getName().equals(i.getServeWarehouseName())).findFirst().get().getId(); |
|
|
|
|
servicesEntity.setServeWarehouseId(id); |
|
|
|
|
servicesEntity.setServeWarehouseName(i.getServeWarehouseName()); |
|
|
|
|
storageServicesEntities.add(servicesEntity); |
|
|
|
|
} |
|
|
|
|
//添加品牌
|
|
|
|
|
if(ObjectUtils.isNotNull(i.getBrandName())){ |
|
|
|
|
BasicdataStoreBrandEntity storeBrandEntity= new BasicdataStoreBrandEntity(); |
|
|
|
|
storeBrandEntity.setClientId(basicdataClient.getId()); |
|
|
|
|
storeBrandEntity.setShopId(basicdataClient.getId().toString()); |
|
|
|
|
BasicdataBrandEntity one = basicdataBrandService.getOne(Wrappers.<BasicdataBrandEntity>query().lambda().eq(BasicdataBrandEntity::getBrandName, i.getBrandName())); |
|
|
|
|
if(ObjectUtils.isNull(one)){ |
|
|
|
|
throw new ServiceException("品牌不存在"); |
|
|
|
|
} |
|
|
|
|
storeBrandEntity.setBrandId(String.valueOf(one.getId())); |
|
|
|
|
storeBrandEntity.setBrandName(i.getBrandName()); |
|
|
|
|
storeBrandEntities.add(storeBrandEntity); |
|
|
|
|
} |
|
|
|
|
//添加联系人
|
|
|
|
|
if(ObjectUtils.isNotNull(i.getLinkman())){ |
|
|
|
|
BasicdataStoreContactEntity storeContactEntity = new BasicdataStoreContactEntity(); |
|
|
|
|
storeContactEntity.setShopId(basicdataClient.getId()); |
|
|
|
|
storeContactEntity.setPhone(i.getPhone()); |
|
|
|
|
storeContactEntity.setLinkman(i.getLinkman()); |
|
|
|
|
storeContactEntities.add(storeContactEntity); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//添加三方商场
|
|
|
|
|
if(ObjectUtils.isNotNull(i.getTripartiteMall())){ |
|
|
|
|
BasicdataTripartiteMallEntity tripartiteMallEntity = new BasicdataTripartiteMallEntity(); |
|
|
|
|
tripartiteMallEntity.setClientId(basicdataClient.getId()); |
|
|
|
|
tripartiteMallEntity.setTripartiteMall(i.getTripartiteMall()); |
|
|
|
|
tripartiteMallEntity.setTripartiteCoding(i.getTripartiteCoding()); |
|
|
|
|
tripartiteMallEntities.add(tripartiteMallEntity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//品牌
|
|
|
|
|
if(!storeBrandEntities.isEmpty()){ |
|
|
|
|
List<BasicdataStoreBrandEntity> list = new ArrayList<>(); |
|
|
|
|
storeBrandEntities.stream().forEach(i ->{ |
|
|
|
|
if(i.getBrandName().contains(",")){ |
|
|
|
|
String[] split = i.getBrandName().split(","); |
|
|
|
|
for (int j = 0; j < split.length; j++) { |
|
|
|
|
BasicdataStoreBrandEntity business = new BasicdataStoreBrandEntity(); |
|
|
|
|
BeanUtil.copyProperties(i,business); |
|
|
|
|
List<BasicdataBrandEntity> list2 = basicdataBrandService.list(Wrappers.<BasicdataBrandEntity>query().lambda() |
|
|
|
|
.eq(BasicdataBrandEntity::getBrandName, i.getBrandName()) |
|
|
|
|
); |
|
|
|
|
business.setBrandName(split[j]); |
|
|
|
|
business.setBrandId(list2.get(0).getId().toString()); |
|
|
|
|
list.add(business); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
List<BasicdataBrandEntity> list2 = basicdataBrandService.list(Wrappers.<BasicdataBrandEntity>query().lambda() |
|
|
|
|
.eq(BasicdataBrandEntity::getBrandName, i.getBrandName()) |
|
|
|
|
); |
|
|
|
|
i.setBrandName(i.getBrandName()); |
|
|
|
|
i.setBrandId(list2.get(0).getId().toString()); |
|
|
|
|
list.add(i); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
basicdataStoreBrandService.saveBatch(list); |
|
|
|
|
} |
|
|
|
|
//服务类型
|
|
|
|
|
if(!storeBusinessEntities.isEmpty()){ |
|
|
|
|
List<BasicdataStoreBusinessEntity> list = new ArrayList<>(); |
|
|
|
|
storeBusinessEntities.stream().forEach(i ->{ |
|
|
|
|
// List<DictBiz> dictBizs = DictBizCache.getList(DictBizConstant.DISTRIBUTION_TYPE);
|
|
|
|
|
if(i.getTypeService().contains(",")){ |
|
|
|
|
String[] split = i.getTypeService().split(","); |
|
|
|
|
for (int j = 0; j < split.length; j++) { |
|
|
|
|
BasicdataStoreBusinessEntity business = new BasicdataStoreBusinessEntity(); |
|
|
|
|
BeanUtil.copyProperties(i,business); |
|
|
|
|
int finalJ = j; |
|
|
|
|
if(split[j].equals("配送")){ |
|
|
|
|
switch ( business.getMold()){ |
|
|
|
|
case "商配": |
|
|
|
|
business.setMold("1"); |
|
|
|
|
break; |
|
|
|
|
case "市配": |
|
|
|
|
business.setMold("2"); |
|
|
|
|
break; |
|
|
|
|
case "自提": |
|
|
|
|
business.setMold("3"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
business.setMold(null); |
|
|
|
|
} |
|
|
|
|
String dictValue = freightBiz.stream().filter(q -> q.getDictValue().equals(split[finalJ])).findFirst().get().getDictKey(); |
|
|
|
|
business.setTypeService(dictValue); |
|
|
|
|
list.add(business); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
String dictValue = freightBiz.stream().filter(q -> q.getDictValue().equals(i.getTypeService())).findFirst().get().getDictKey(); |
|
|
|
|
i.setTypeService(dictValue); |
|
|
|
|
if(i.getTypeService().equals("配送")){ |
|
|
|
|
String mold = i.getMold(); |
|
|
|
|
switch (mold){ |
|
|
|
|
case "商配": |
|
|
|
|
i.setMold("1"); |
|
|
|
|
break; |
|
|
|
|
case "市配": |
|
|
|
|
i.setMold("2"); |
|
|
|
|
break; |
|
|
|
|
case "自提": |
|
|
|
|
i.setMold("3"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
i.setMold(null); |
|
|
|
|
} |
|
|
|
|
list.add(i); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
basicdataStoreBusinessService.saveBatch(list); |
|
|
|
|
} |
|
|
|
|
//服务仓
|
|
|
|
|
if(!storageServicesEntities.isEmpty()){ |
|
|
|
|
List<BasicdataStorageServicesEntity> servicesEntityList = new ArrayList<>(); |
|
|
|
|
storageServicesEntities.stream().forEach(i ->{ |
|
|
|
|
if(i.getSendWarehouseName().contains(",")){ |
|
|
|
|
String[] split = i.getSendWarehouseName().split(","); |
|
|
|
|
for (int j = 0; j < split.length; j++) { |
|
|
|
|
BasicdataStorageServicesEntity servicesEntity = new BasicdataStorageServicesEntity(); |
|
|
|
|
Long id = list1.stream().filter(q -> q.getName().equals(i.getSendWarehouseName())).findFirst().get().getId(); |
|
|
|
|
BeanUtil.copyProperties(i,servicesEntity); |
|
|
|
|
servicesEntity.setSendWarehouseId(id.toString()); |
|
|
|
|
servicesEntity.setSendWarehouseName(split[j]); |
|
|
|
|
servicesEntityList.add(servicesEntity); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
Long id = list1.stream().filter(q -> q.getName().equals(i.getSendWarehouseName())).findFirst().get().getId(); |
|
|
|
|
i.setSendWarehouseId(id.toString()); |
|
|
|
|
servicesEntityList.add(i); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
basicdataStorageServicesService.saveBatch(servicesEntityList); |
|
|
|
|
} |
|
|
|
|
//联系人
|
|
|
|
|
if(!storeContactEntities.isEmpty()){ |
|
|
|
|
basicdataStoreContactService.saveBatch(storeContactEntities); |
|
|
|
|
} |
|
|
|
|
//三方
|
|
|
|
|
if(!tripartiteMallEntities.isEmpty()){ |
|
|
|
|
basicdataTripartiteMallService.saveBatch(tripartiteMallEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|