Browse Source

导出导入渠道

v1.0
15989082884@163.com 2 years ago
parent
commit
9ad7f6045c
  1. 214
      src/main/java/com/qs/serve/modules/bms/controller/BmsChannelController.java
  2. 7
      src/main/java/com/qs/serve/modules/bms/entity/BmsChannel.java
  3. 53
      src/main/java/com/qs/serve/modules/bms/entity/bo/BmsChannel4ExcelBo.java
  4. 1
      src/main/java/com/qs/serve/modules/bms/service/BmsSupplierChannelService.java
  5. 7
      src/main/java/com/qs/serve/modules/bms/service/impl/BmsSupplierChannelServiceImpl.java

214
src/main/java/com/qs/serve/modules/bms/controller/BmsChannelController.java

@ -1,23 +1,25 @@
package com.qs.serve.modules.bms.controller; package com.qs.serve.modules.bms.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.qs.serve.common.model.annotation.SysLog; import com.qs.serve.common.model.annotation.SysLog;
import com.qs.serve.common.model.dto.PageVo; import com.qs.serve.common.model.dto.PageVo;
import com.qs.serve.common.model.dto.R; import com.qs.serve.common.model.dto.R;
import com.qs.serve.common.model.enums.BizType; import com.qs.serve.common.model.enums.BizType;
import com.qs.serve.common.model.enums.SystemModule; import com.qs.serve.common.model.enums.SystemModule;
import com.qs.serve.common.util.CollectionUtil; import com.qs.serve.common.util.CollectionUtil;
import com.qs.serve.common.util.CopierUtil;
import com.qs.serve.common.util.PageUtil; import com.qs.serve.common.util.PageUtil;
import com.qs.serve.common.util.StringUtils; import com.qs.serve.common.util.StringUtils;
import com.qs.serve.modules.bms.common.MasterUserType; import com.qs.serve.modules.bms.common.MasterUserType;
import com.qs.serve.modules.bms.controller.my.BmsChannelMyController; import com.qs.serve.modules.bms.controller.my.BmsChannelMyController;
import com.qs.serve.modules.bms.entity.BmsChannelPoint; import com.qs.serve.modules.bms.entity.*;
import com.qs.serve.modules.bms.entity.BmsMasterUser; import com.qs.serve.modules.bms.entity.bo.BmsChannel4ExcelBo;
import com.qs.serve.modules.bms.entity.BmsSupplierVisitType;
import com.qs.serve.modules.bms.entity.bo.BmsSupplierChannelBo; import com.qs.serve.modules.bms.entity.bo.BmsSupplierChannelBo;
import com.qs.serve.modules.bms.mapper.BmsMasterUserMapper; import com.qs.serve.modules.bms.mapper.BmsMasterUserMapper;
import com.qs.serve.modules.bms.service.BmsChannelPointService; import com.qs.serve.modules.bms.service.BmsChannelPointService;
import com.qs.serve.modules.bms.service.BmsSupplierChannelService; import com.qs.serve.modules.bms.service.BmsSupplierChannelService;
import com.qs.serve.modules.bms.service.BmsSupplierService;
import com.qs.serve.modules.his.entity.HisUserChannelPoint; import com.qs.serve.modules.his.entity.HisUserChannelPoint;
import com.qs.serve.modules.his.service.HisUserChannelPointService; import com.qs.serve.modules.his.service.HisUserChannelPointService;
import com.qs.serve.modules.tbs.entity.TbsActivityChannel; import com.qs.serve.modules.tbs.entity.TbsActivityChannel;
@ -27,12 +29,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.qs.serve.modules.bms.entity.BmsChannel;
import com.qs.serve.modules.bms.service.BmsChannelService; import com.qs.serve.modules.bms.service.BmsChannelService;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Arrays; import java.util.*;
import java.util.List; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -54,6 +55,8 @@ public class BmsChannelController {
private BmsSupplierChannelService bmsSupplierChannelService; private BmsSupplierChannelService bmsSupplierChannelService;
private BmsChannelMyController bmsChannelMyController; private BmsChannelMyController bmsChannelMyController;
private BmsSupplierChannelController bmsSupplierChannelController; private BmsSupplierChannelController bmsSupplierChannelController;
private BmsSupplierService bmsSupplierService;
/** /**
* 导出列表 * 导出列表
@ -68,15 +71,34 @@ public class BmsChannelController {
channelWrapper.orderByDesc(BmsChannel::getCreateTime); channelWrapper.orderByDesc(BmsChannel::getCreateTime);
if(param.getSelectStartTime()!=null) { if(param.getSelectStartTime()!=null) {
channelWrapper.ge(BmsChannel::getCreateTime, param.getSelectStartTime()); channelWrapper.ge(BmsChannel::getCreateTime, param.getSelectStartTime());
channelWrapper.isNotNull(BmsChannel::getCreateBy);
} }
if(param.getSelectEndTime()!=null) { if(param.getSelectEndTime()!=null) {
channelWrapper.le(BmsChannel::getCreateTime, param.getSelectEndTime()); channelWrapper.le(BmsChannel::getCreateTime, param.getSelectEndTime());
channelWrapper.isNotNull(BmsChannel::getCreateBy);
} }
if(CollectionUtil.isNotEmpty(param.getSelectIds())){ if(CollectionUtil.isNotEmpty(param.getSelectIds())){
channelWrapper.in(BmsChannel::getId, param.getSelectIds()); channelWrapper.in(BmsChannel::getId, param.getSelectIds());
} }
channelWrapper.isNotNull(BmsChannel::getCreateBy);
List<BmsChannel> list = bmsChannelService.list(channelWrapper); List<BmsChannel> list = bmsChannelService.list(channelWrapper);
List<Long> channelIds = list.stream().map(a->a.getId()).collect(Collectors.toList());
if(channelIds.size()>0) {
LambdaQueryWrapper<BmsSupplierChannel> supplierChannelLambdaQueryWrapper = new LambdaQueryWrapper<>();
supplierChannelLambdaQueryWrapper.in(BmsSupplierChannel::getChannelId, channelIds);
List<BmsSupplierChannel> supplierChannelList = bmsSupplierChannelService.list(supplierChannelLambdaQueryWrapper);
List<String> supplierIds = supplierChannelList.stream().map(a->a.getSupplierId().toString()).distinct().collect(Collectors.toList());
if(supplierIds.size()>0){
LambdaQueryWrapper<BmsSupplier> supplierLqw = new LambdaQueryWrapper();
supplierLqw.in(BmsSupplier::getId,supplierIds);
List<BmsSupplier> supplierList = bmsSupplierService.list(supplierLqw);
list.forEach(a->{
List<String> supplierIdList = supplierChannelList.stream().filter(b->b.getChannelId().equals(a.getId())).map(b->b.getSupplierId()+"").collect(Collectors.toList());
List<String> supplierNames = supplierList.stream().filter(b->supplierIdList.contains(b.getId())).map(b->b.getName()).collect(Collectors.toList());
a.setSupplierNames(supplierNames);
});
}
}
return R.ok(list); return R.ok(list);
} }
@ -166,6 +188,170 @@ public class BmsChannelController {
return R.ok(); return R.ok();
} }
/**
* 新增
* @param param
* @return
*/
@PostMapping("/importExcel")
@SysLog(module = SystemModule.BASE, title = "渠道", biz = BizType.INSERT)
@PreAuthorize("hasRole('bms:channel:insert')")
public R<?> importExcel(@RequestBody @Valid List<BmsChannel4ExcelBo> param){
param.forEach(a->{
a.setErrorInfo("");
if(!StringUtils.hasText(a.getChannelName())){
a.setErrorInfo(a.getErrorInfo()+"渠道名称不能为空;");
}
if(!StringUtils.hasText(a.getChannelType())){
a.setErrorInfo(a.getErrorInfo()+"渠道类型不能为空;");
}
if(!StringUtils.hasText(a.getCostFlag())){
a.setErrorInfo(a.getErrorInfo()+"是否可投放费用不能为空;");
}
});
List<BmsChannel4ExcelBo> saveList = param.stream().filter(a->a.getType().equals("1")).collect(Collectors.toList());
List<BmsChannel4ExcelBo> updateList = param.stream().filter(a->a.getType().equals("2")).collect(Collectors.toList());
List<BmsChannel4ExcelBo> deleteList = param.stream().filter(a->a.getType().equals("3")).collect(Collectors.toList());
/** ------------------------------- 查客户列表 ------------------------------------------------ */
List<String> supplierNames = new ArrayList<>();
supplierNames.addAll(saveList.stream().filter(a->a.getSupplierNames()!=null).map(a->a.getSupplierNames()).flatMap(List::stream).collect(Collectors.toList()));
supplierNames.addAll(updateList.stream().filter(a->a.getSupplierNames()!=null).map(a->a.getSupplierNames()).flatMap(List::stream).collect(Collectors.toList()));
supplierNames = supplierNames.stream().distinct().collect(Collectors.toList());
List<BmsSupplier> supplierList = new ArrayList<>();
if(supplierNames.size()>0) {
LambdaQueryWrapper<BmsSupplier> supplierLambdaQueryWrapper = new LambdaQueryWrapper<>();
supplierLambdaQueryWrapper.in(BmsSupplier::getCode, supplierNames);
supplierList = bmsSupplierService.list(supplierLambdaQueryWrapper);
List<String> existSupplierName = supplierList.stream().map(a -> a.getName()).collect(Collectors.toList());
if (supplierList.size() < supplierNames.size()) {
param.forEach(a -> {
List<String> noExistName = a.getSupplierNames().stream().filter(b -> !existSupplierName.contains(b)).collect(Collectors.toList());
if (noExistName.size() > 0) {
a.setErrorInfo(a.getErrorInfo() + "不存在客户" + noExistName.stream().collect(Collectors.joining(",")) + ";");
}
});
}
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 校验新增 ------------------------------------------------ */
if(saveList.size()>0) {
List<String> saveCodes = saveList.stream().filter(a -> StringUtils.hasText(a.getChannelCode())).map(a -> a.getChannelCode()).distinct().collect(Collectors.toList());
LambdaQueryWrapper<BmsChannel> checkSaveChannelCode = new LambdaQueryWrapper<>();
checkSaveChannelCode.in(BmsChannel::getChannelCode, saveCodes);
List<BmsChannel> checkSaveChannelList = bmsChannelService.list(checkSaveChannelCode);
if (checkSaveChannelList.size() > 0) {
List<String> existSaveCodes = checkSaveChannelList.stream().map(a -> a.getChannelCode()).collect(Collectors.toList());
param.forEach(a -> {
if (a.getType().equals("1")) {
if (existSaveCodes.contains(a.getChannelCode())) {
a.setErrorInfo(a.getErrorInfo() + "新增已存在网点编码;");
}
}
});
}
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 校验更新 ------------------------------------------------ */
if(updateList.size()>0) {
List<String> updateCheckCodes = updateList.stream().filter(a -> StringUtils.hasText(a.getChannelCode())).map(a -> a.getChannelCode()).distinct().collect(Collectors.toList());
LambdaQueryWrapper<BmsChannel> checkUpdateChannelCode = new LambdaQueryWrapper<>();
checkUpdateChannelCode.in(BmsChannel::getChannelCode, updateCheckCodes);
List<BmsChannel> checkUpdateChannelList = bmsChannelService.list(checkUpdateChannelCode);
if (checkUpdateChannelList.size() > 0) {
List<String> existSaveCodes = checkUpdateChannelList.stream().map(a -> a.getChannelCode()).collect(Collectors.toList());
param.forEach(a -> {
if (a.getType().equals("2")) {
if (!existSaveCodes.contains(a.getChannelCode())) {
a.setErrorInfo(a.getErrorInfo() + "更新不存在网点编码;");
}
}
});
}
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 删除更新 ------------------------------------------------ */
if(deleteList.size()>0) {
List<String> deleteCheckCodes = deleteList.stream().filter(a -> StringUtils.hasText(a.getChannelCode())).map(a -> a.getChannelCode()).distinct().collect(Collectors.toList());
LambdaQueryWrapper<BmsChannel> checkdeleteChannelCode = new LambdaQueryWrapper<>();
checkdeleteChannelCode.in(BmsChannel::getChannelCode, deleteCheckCodes);
List<BmsChannel> checkdeleteChannelList = bmsChannelService.list(checkdeleteChannelCode);
if (checkdeleteChannelList.size() > 0) {
List<String> existSaveCodes = checkdeleteChannelList.stream().map(a -> a.getChannelCode()).collect(Collectors.toList());
param.forEach(a -> {
if (a.getType().equals("3")) {
if (!existSaveCodes.contains(a.getChannelCode())) {
a.setErrorInfo(a.getErrorInfo() + "删除不存在网点编码;");
}
}
});
}
}
if(param.stream().filter(a->a.getErrorInfo().length()>0).count()>0) {
return R.ok(param, "导入失败,请打开EXCEL查询错误详情!");
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 保存新增 ------------------------------------------------ */
if(saveList.size()>0) {
List<BmsChannel> saveBmsChannels = saveList.stream().map(a -> {
BmsChannel bmsChannel = new BmsChannel();
CopierUtil.copy(a, bmsChannel);
if (!StringUtils.hasText(bmsChannel.getChannelCode())) {
bmsChannel.setChannelCode("D" + StringUtils.genShortId());
}
return bmsChannel;
}).collect(Collectors.toList());
bmsChannelService.saveBatch(saveBmsChannels);
this.batchHandleChannelSupplier(saveBmsChannels, supplierList);
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 更新数据 ------------------------------------------------ */
if(updateList.size()>0) {
List<BmsChannel> updateBmsChannels = updateList.stream().map(a -> {
BmsChannel bmsChannel = new BmsChannel();
CopierUtil.copy(a, bmsChannel);
return bmsChannel;
}).collect(Collectors.toList());
List<String> updateCodes = updateBmsChannels.stream().map(a -> a.getChannelCode()).collect(Collectors.toList());
LambdaQueryWrapper<BmsChannel> bmsChannelLambdaQueryWrapper = new LambdaQueryWrapper<>();
bmsChannelLambdaQueryWrapper.in(BmsChannel::getChannelCode, updateCodes);
List<BmsChannel> oriBmsChannelList = bmsChannelService.list(bmsChannelLambdaQueryWrapper);
Map<String, Long> codeToChannelId = oriBmsChannelList.stream().collect(Collectors.toMap(BmsChannel::getChannelCode, BmsChannel::getId));
updateBmsChannels = updateBmsChannels.stream().map(a -> {
a.setId(codeToChannelId.get(a.getChannelCode()));
return a;
}).collect(Collectors.toList());
bmsChannelService.updateBatchById(updateBmsChannels);
this.batchHandleChannelSupplier(updateBmsChannels, supplierList);
}
/** ----------------------------------------------------------------------------------- */
/** ------------------------------- 删除数据 ------------------------------------------------ */
if(deleteList.size()>0) {
List<BmsChannel> deleteBmsChannels = deleteList.stream().map(a -> {
BmsChannel bmsChannel = new BmsChannel();
CopierUtil.copy(a, bmsChannel);
return bmsChannel;
}).collect(Collectors.toList());
List<String> deleteCodes = deleteBmsChannels.stream().map(a -> a.getChannelCode()).collect(Collectors.toList());
LambdaQueryWrapper<BmsChannel> deleteBmsChannelLambdaQueryWrapper = new LambdaQueryWrapper<>();
deleteBmsChannelLambdaQueryWrapper.in(BmsChannel::getChannelCode, deleteCodes);
List<BmsChannel> oriDeleteBmsChannelList = bmsChannelService.list(deleteBmsChannelLambdaQueryWrapper);
Map<String, Long> deleteCodeToChannelId = oriDeleteBmsChannelList.stream().collect(Collectors.toMap(BmsChannel::getChannelCode, BmsChannel::getId));
deleteBmsChannels = deleteBmsChannels.stream().map(a -> {
a.setId(deleteCodeToChannelId.get(a.getChannelCode()));
return a;
}).collect(Collectors.toList());
List<Long> deleteIds = deleteBmsChannels.stream().map(a -> a.getId()).collect(Collectors.toList());
bmsChannelService.removeBatchByIds(deleteIds);
LambdaQueryWrapper<BmsSupplierChannel> supplierChannelLambdaQueryWrapper = new LambdaQueryWrapper<>();
supplierChannelLambdaQueryWrapper.in(BmsSupplierChannel::getChannelId, deleteIds);
bmsSupplierChannelService.remove(supplierChannelLambdaQueryWrapper);
/** ----------------------------------------------------------------------------------- */
}
return R.ok();
}
/** /**
* 删除 * 删除
* @param id * @param id
@ -202,5 +388,19 @@ public class BmsChannelController {
return R.isTrue(result); return R.isTrue(result);
} }
private void batchHandleChannelSupplier(List<BmsChannel> saveBmsChannels, List<BmsSupplier> supplierList){
List<BmsSupplierChannel> bmsSupplierChannelList = saveBmsChannels.stream().map(a->{
List<Long> supplierIds = supplierList.stream().filter(b->a.getSupplierNames().contains(b.getName())).map(b->Long.parseLong(b.getId())).collect(Collectors.toList());
List<BmsSupplierChannel> bmsSupplierChannels = supplierIds.stream().map(b->{
BmsSupplierChannel supplierChannel = new BmsSupplierChannel();
supplierChannel.setChannelId(a.getId());
supplierChannel.setSupplierId(b);
return supplierChannel;
}).collect(Collectors.toList());
return bmsSupplierChannels;
}).flatMap(List::stream).collect(Collectors.toList());
bmsSupplierChannelService.deleteBatchByChannelIds(saveBmsChannels.stream().map(a->a.getId()).distinct().collect(Collectors.toList()));
bmsSupplierChannelService.saveBatch(bmsSupplierChannelList);
}
} }

7
src/main/java/com/qs/serve/modules/bms/entity/BmsChannel.java

@ -108,5 +108,12 @@ public class BmsChannel implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private List<Long> supplierIds; private List<Long> supplierIds;
/** 用于导入 */
// @TableField(exist = false)
// private List<String> supplierCodes;
@TableField(exist = false)
private List<String> supplierNames;
} }

53
src/main/java/com/qs/serve/modules/bms/entity/bo/BmsChannel4ExcelBo.java

@ -0,0 +1,53 @@
package com.qs.serve.modules.bms.entity.bo;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* 渠道 实体类
* @author YenHex
* @since 2022-11-07
*/
@Data
public class BmsChannel4ExcelBo implements Serializable {
/** type */
/** 增加 修改 删除 */
private String type;
/** 渠道编码 */
private String channelCode;
/** 渠道名称 */
private String channelName;
/** 渠道类型(读取数据字典) */
private String channelType;
/** 备注 */
private String remark;
private String costFlag;
/** 所属租户 */
private String tenantId;
// private List<String> supplierCodes;
private List<String> supplierNames;
private String errorInfo;
}

1
src/main/java/com/qs/serve/modules/bms/service/BmsSupplierChannelService.java

@ -18,5 +18,6 @@ public interface BmsSupplierChannelService extends IService<BmsSupplierChannel>
void deleteBySupplierId(String id); void deleteBySupplierId(String id);
void deleteByChannelId(String id); void deleteByChannelId(String id);
void deleteBatchByChannelIds(List<Long> ids);
} }

7
src/main/java/com/qs/serve/modules/bms/service/impl/BmsSupplierChannelServiceImpl.java

@ -34,6 +34,13 @@ public class BmsSupplierChannelServiceImpl extends ServiceImpl<BmsSupplierChanne
this.remove(lqw); this.remove(lqw);
} }
@Override
public void deleteBatchByChannelIds(List<Long> ids) {
LambdaQueryWrapper<BmsSupplierChannel> lqw = new LambdaQueryWrapper<>();
lqw.in(BmsSupplierChannel::getChannelId,ids);
this.remove(lqw);
}
@Override @Override
public void deleteBySupplierId(String id) { public void deleteBySupplierId(String id) {
LambdaQueryWrapper<BmsSupplierChannel> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BmsSupplierChannel> lqw = new LambdaQueryWrapper<>();

Loading…
Cancel
Save