客户管理导入
This commit is contained in:
parent
1c90c9f62d
commit
2302448a9e
|
|
@ -9,8 +9,10 @@ import com.nflg.mobilebroken.admin.pojo.dto.BaseAreaEditDTO;
|
|||
import com.nflg.mobilebroken.admin.pojo.dto.CustomerDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.CustomerQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.ComstomerImportTemplate;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.CustomerExcelVO;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.DeviceExcelVO;
|
||||
import com.nflg.mobilebroken.admin.service.AdminCustomerService;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
|
|
@ -47,6 +49,9 @@ public class CustomerController {
|
|||
@Resource
|
||||
ITBaseCustomerService baseCustomerService;
|
||||
|
||||
@Resource
|
||||
AdminCustomerService adminCustomerService;
|
||||
|
||||
|
||||
@PostMapping("getList")
|
||||
@MethodInfoMark(value = "获取客户列表" ,menuName = "客户管理")
|
||||
|
|
@ -70,7 +75,7 @@ public class CustomerController {
|
|||
VUtils.trueThrow(CollUtil.isNotEmpty(existCompany)).throwMessage(STATE.PageError,customerDTO.getAgencyCompanyName()+"公司名称已存在");
|
||||
TBaseCustomer ent = Convert.convert(TBaseCustomer.class, customerDTO);
|
||||
ent.setId(null);
|
||||
ent.setAgencyCompanyCode(new UniqueSequenceGenerator().generateCode(Constant.CustomerCodePrefix));
|
||||
ent.setAgencyCompanyCode(UniqueSequenceGenerator.generateCode(Constant.CustomerCodePrefix));
|
||||
ent.setDataCreateUserNo(TokenUtil.getUserNo());
|
||||
ent.setDataCreateUserName(TokenUtil.getUserName());
|
||||
ent.setDataCreateTime(LocalDateTime.now());
|
||||
|
|
@ -125,9 +130,9 @@ public class CustomerController {
|
|||
public void downTemplate(HttpServletResponse response) throws IOException {
|
||||
EecExcelUtil.setResponseExcelHeader(response,"客户导入模板");
|
||||
|
||||
final ListSheet<CustomerExcelVO> listSheet = new ListSheet<CustomerExcelVO>() {
|
||||
final ListSheet<ComstomerImportTemplate> listSheet = new ListSheet<ComstomerImportTemplate>() {
|
||||
@Override
|
||||
protected List<CustomerExcelVO> more() {
|
||||
protected List<ComstomerImportTemplate> more() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
@ -163,16 +168,15 @@ public class CustomerController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("importData")
|
||||
@MethodInfoMark(value = "导入客户",menuName = "客户列表")
|
||||
public ApiResult<Boolean> importData( @RequestParam(value = "file") MultipartFile file){
|
||||
|
||||
// try {
|
||||
// List<DeviceExcelVO> data = EecExcelUtil.getExcelContext(file.getInputStream(), DeviceExcelVO.class);
|
||||
// VUtils.trueThrowBusinessError(CollUtil.isEmpty(data)).throwMessage("导入文件内容为空");
|
||||
// adminDeviceService.importData(data);
|
||||
// } catch (IOException e) {
|
||||
// throw new NflgException(STATE.BusinessError, "导出失败:"+e.getMessage());
|
||||
// }
|
||||
try {
|
||||
List<CustomerExcelVO> data = EecExcelUtil.getExcelContext(file.getInputStream(), CustomerExcelVO.class);
|
||||
VUtils.trueThrowBusinessError(CollUtil.isEmpty(data)).throwMessage("导入文件内容为空");
|
||||
adminCustomerService.importData(data);
|
||||
} catch (IOException e) {
|
||||
throw new NflgException(STATE.BusinessError, "导出失败:"+e.getMessage());
|
||||
}
|
||||
return ApiResult.success(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,6 @@ public class DeviceController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("importData")
|
||||
@MethodInfoMark(value = "导入设备",menuName = "设备管理")
|
||||
public ApiResult<Boolean> importData( @RequestParam(value = "file") MultipartFile file){
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.nflg.mobilebroken.admin.pojo.vo;
|
||||
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
public class ComstomerImportTemplate {
|
||||
|
||||
@ExcelColumn( "代理公司名称")
|
||||
private String agencyCompanyName;
|
||||
|
||||
/**
|
||||
* 代理负责人
|
||||
*/
|
||||
@ExcelColumn( "代理负责人")
|
||||
private String agencyManager;
|
||||
|
||||
/**
|
||||
* sap客户号
|
||||
*/
|
||||
@ExcelColumn("sap客户号")
|
||||
private String sapCustomerNo;
|
||||
|
||||
/**
|
||||
* 销售授权信息
|
||||
*/
|
||||
@ExcelColumn("销售授权信息")
|
||||
private String salesAuthorizationInfo;
|
||||
|
||||
/**
|
||||
* 区域编码
|
||||
*/
|
||||
@ExcelColumn("区域编码")
|
||||
private String areaCode;
|
||||
|
||||
/**
|
||||
* 区域
|
||||
*/
|
||||
@ExcelColumn("区域名称")
|
||||
private String areaName;
|
||||
|
||||
/**
|
||||
* 服务主管
|
||||
*/
|
||||
@ExcelColumn("服务主管")
|
||||
private String serviceSupervisor;
|
||||
|
||||
/**
|
||||
* 销售主管
|
||||
*/
|
||||
@ExcelColumn("销售主管")
|
||||
private String salesSupervisor;
|
||||
|
||||
|
||||
|
||||
@ExcelColumn("状态")
|
||||
private String enableStateName;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,12 +5,13 @@ import org.ttzero.excel.annotation.ExcelColumn;
|
|||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 客户管理导出模板
|
||||
*/
|
||||
@Data
|
||||
public class CustomerExcelVO {
|
||||
public class CustomerExcelVO implements Serializable {
|
||||
|
||||
@ExcelColumn( "代理公司名称")
|
||||
private String agencyCompanyName;
|
||||
|
|
@ -63,6 +64,13 @@ public class CustomerExcelVO {
|
|||
|
||||
private Integer enableState;
|
||||
|
||||
public Integer getEnableState() {
|
||||
if(enableState==null){
|
||||
return enableStateName=="禁用"?0:1;
|
||||
}
|
||||
return enableState;
|
||||
}
|
||||
|
||||
@ExcelColumn("状态")
|
||||
private String enableStateName;
|
||||
|
||||
|
|
@ -73,6 +81,6 @@ public class CustomerExcelVO {
|
|||
@ExcelColumn("创建人")
|
||||
private String dataCreateUserName;
|
||||
|
||||
@ExcelColumn(value = "创建人" ,format = "yyyy-MM-dd")
|
||||
@ExcelColumn(value = "创建时间" ,format = "yyyy-MM-dd")
|
||||
private String dataCreateTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
package com.nflg.mobilebroken.admin.service;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.admin.constant.Constant;
|
||||
import com.nflg.mobilebroken.admin.pojo.vo.CustomerExcelVO;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.util.TokenUtil;
|
||||
import com.nflg.mobilebroken.common.util.UniqueSequenceGenerator;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
import com.nflg.mobilebroken.repository.entity.TBaseCustomer;
|
||||
import com.nflg.mobilebroken.repository.service.ITBaseCustomerService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class AdminCustomerService {
|
||||
|
||||
@Resource
|
||||
ITBaseCustomerService baseCustomerService;
|
||||
|
||||
/**
|
||||
* 导入
|
||||
* @param data
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importData(List<CustomerExcelVO> data){
|
||||
|
||||
//检查EXCEL中代理公司名是否重复
|
||||
Map<String, List<CustomerExcelVO>> duplicateCompany = data.stream()
|
||||
.collect(Collectors.groupingBy(CustomerExcelVO::getAgencyCompanyName))
|
||||
.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().size() > 1)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
if(CollUtil.isNotEmpty(duplicateCompany)) {
|
||||
VUtils.trueThrow(true).throwMessage(STATE.ParamErr,"Excel中以下代理公司名重复:"+StrUtil.join(",",duplicateCompany.keySet()) ) ;
|
||||
}
|
||||
//检查公司名称是否已存在数据库中
|
||||
List<String> companyNames = data.stream().map(u -> u.getAgencyCompanyName()).collect(Collectors.toList());
|
||||
|
||||
List<TBaseCustomer> existCompany= baseCustomerService.lambdaQuery().in(TBaseCustomer::getAgencyCompanyName, companyNames).list();
|
||||
if(CollUtil.isNotEmpty(existCompany)){
|
||||
Set<String> existCompanyNames = existCompany.stream().map(u -> u.getAgencyCompanyName()).collect(Collectors.toSet());
|
||||
VUtils.trueThrow(true).throwMessage(STATE.ParamErr,StrUtil.join(",",existCompanyNames)+" 已存在数据库中");
|
||||
}
|
||||
List<TBaseCustomer> result = Convert.toList(TBaseCustomer.class, data);
|
||||
result.forEach(k->{
|
||||
k.setDataCreateUserNo(TokenUtil.getUserNo());
|
||||
k.setDataCreateUserName(TokenUtil.getUserName());
|
||||
k.setDataCreateTime(LocalDateTime.now());
|
||||
k.setDataModifyUserNo(TokenUtil.getUserNo());
|
||||
k.setDataModifyUserName(TokenUtil.getUserName());
|
||||
k.setDataModifyTime(LocalDateTime.now());
|
||||
k.setAgencyCompanyCode(UniqueSequenceGenerator.generateCode(Constant.CustomerCodePrefix) );
|
||||
|
||||
});
|
||||
baseCustomerService.saveBatch(result);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,6 @@ public class AdminDeviceTypeService {
|
|||
@Resource
|
||||
ITBaseDeviceTypeService baseDeviceTypeService;
|
||||
|
||||
UniqueSequenceGenerator uniqueSequenceGenerator=new UniqueSequenceGenerator();
|
||||
|
||||
public void batchAddDeviceType(List<String> deviceTypeList){
|
||||
List<TBaseDeviceType> existDeviceTypes = baseDeviceTypeService.lambdaQuery().in(TBaseDeviceType::getDeviceType, deviceTypeList).select(TBaseDeviceType::getDeviceType).list();
|
||||
|
|
@ -34,7 +33,7 @@ public class AdminDeviceTypeService {
|
|||
for (String deviceType:needAddTypes) {
|
||||
TBaseDeviceType ent=new TBaseDeviceType();
|
||||
ent.setId(null);
|
||||
ent.setDeviceTypeCode(uniqueSequenceGenerator.generateCode(Constant.DeviceTypeCodePrefix));
|
||||
ent.setDeviceTypeCode(UniqueSequenceGenerator.generateCode(Constant.DeviceTypeCodePrefix));
|
||||
ent.setDeviceType(deviceType);
|
||||
ent.setDeviceState(Boolean.TRUE);
|
||||
ent.setDataCreateUserNo(TokenUtil.getUserNo());
|
||||
|
|
|
|||
|
|
@ -7,14 +7,15 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
public class UniqueSequenceGenerator {
|
||||
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
private AtomicInteger sequence = new AtomicInteger(0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成唯一顺序编码
|
||||
* @return 唯一顺序编码字符串
|
||||
*/
|
||||
public synchronized String generateCode(String prefix) {
|
||||
public static synchronized String generateCode(String prefix) {
|
||||
AtomicInteger sequence = new AtomicInteger(0);
|
||||
// 获取当前时间戳,精确到毫秒
|
||||
String timestamp = sdf.format(new Date());
|
||||
// 获取序列号,并在达到9999时重置为0
|
||||
|
|
|
|||
Loading…
Reference in New Issue