|
@ -17,13 +17,16 @@ |
|
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
|
|
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
@ -31,29 +34,42 @@ import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.commons.tools.utils.ExcelPoiUtils; |
|
|
import com.epmet.commons.tools.utils.ExcelPoiUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
import com.epmet.dao.IcPartyActivityDao; |
|
|
import com.epmet.dao.IcPartyActivityDao; |
|
|
import com.epmet.dto.IcPartyActivityDTO; |
|
|
import com.epmet.dto.IcPartyActivityDTO; |
|
|
import com.epmet.dto.IcPartyUnitDTO; |
|
|
import com.epmet.dto.IcPartyUnitDTO; |
|
|
|
|
|
import com.epmet.dto.form.ImportTaskCommonFormDTO; |
|
|
import com.epmet.dto.form.PartyActivityFormDTO; |
|
|
import com.epmet.dto.form.PartyActivityFormDTO; |
|
|
import com.epmet.dto.result.ActivityStatisticsDTO; |
|
|
import com.epmet.dto.result.ActivityStatisticsDTO; |
|
|
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
import com.epmet.dto.result.demand.OptionDTO; |
|
|
import com.epmet.dto.result.demand.OptionDTO; |
|
|
import com.epmet.entity.IcActivityServiceRelationEntity; |
|
|
import com.epmet.entity.IcActivityServiceRelationEntity; |
|
|
import com.epmet.entity.IcActivityUnitRelationEntity; |
|
|
import com.epmet.entity.IcActivityUnitRelationEntity; |
|
|
import com.epmet.entity.IcPartyActivityEntity; |
|
|
import com.epmet.entity.IcPartyActivityEntity; |
|
|
import com.epmet.excel.IcPartyActivityImportExcel; |
|
|
import com.epmet.excel.IcPartyActivityImportExcel; |
|
|
|
|
|
import com.epmet.excel.IcPartyActivityImportFailedExcel; |
|
|
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.service.*; |
|
|
import com.epmet.service.*; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
|
|
import org.apache.commons.fileupload.FileItemFactory; |
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.OutputStream; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
@ -76,7 +92,10 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD |
|
|
private IcActivityUnitRelationService icActivityUnitRelationService; |
|
|
private IcActivityUnitRelationService icActivityUnitRelationService; |
|
|
@Resource |
|
|
@Resource |
|
|
private IcActivityServiceRelationService icActivityServiceRelationService; |
|
|
private IcActivityServiceRelationService icActivityServiceRelationService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -233,16 +252,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD |
|
|
* @Date 2021/11/29 11:01 |
|
|
* @Date 2021/11/29 11:01 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public Result importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException { |
|
|
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException { |
|
|
|
|
|
List<IcPartyActivityImportFailedExcel> fileList = new ArrayList<>(); |
|
|
ExcelImportResult<IcPartyActivityImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyActivityImportExcel.class); |
|
|
ExcelImportResult<IcPartyActivityImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyActivityImportExcel.class); |
|
|
List<IcPartyActivityImportExcel> failList = importResult.getFailList(); |
|
|
List<IcPartyActivityImportExcel> failList = importResult.getFailList(); |
|
|
//存放错误数据行号
|
|
|
//存放错误数据行号
|
|
|
List<Integer> numList = new ArrayList<>(); |
|
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { |
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { |
|
|
for (IcPartyActivityImportExcel entity : failList) { |
|
|
for (IcPartyActivityImportExcel entity : failList) { |
|
|
//打印失败的行 和失败的信息
|
|
|
//打印失败的行 和失败的信息
|
|
|
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); |
|
|
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); |
|
|
numList.add(entity.getRowNum()); |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(entity, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo(entity.getErrorMsg()); |
|
|
|
|
|
fileList.add(failed); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
List<IcPartyActivityImportExcel> result = importResult.getList(); |
|
|
List<IcPartyActivityImportExcel> result = importResult.getList(); |
|
@ -262,14 +283,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD |
|
|
IcPartyActivityImportExcel obj = iterator.next(); |
|
|
IcPartyActivityImportExcel obj = iterator.next(); |
|
|
//单位名称校验
|
|
|
//单位名称校验
|
|
|
if (StringUtils.isBlank(obj.getUnitName())) { |
|
|
if (StringUtils.isBlank(obj.getUnitName())) { |
|
|
numList.add(obj.getRowNum()); |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("单位名称为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum())); |
|
|
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum())); |
|
|
iterator.remove(); |
|
|
iterator.remove(); |
|
|
} else { |
|
|
} else { |
|
|
List<String> unitList = Arrays.asList(obj.getUnitName().split(StrConstant.COMMA)); |
|
|
List<String> unitList = Arrays.asList(obj.getUnitName().split(StrConstant.COMMA)); |
|
|
unitList.forEach(unit -> { |
|
|
unitList.forEach(unit -> { |
|
|
if (null == option.get(unit)) { |
|
|
if (null == option.get(unit)) { |
|
|
numList.add(obj.getRowNum()); |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("单位名称不存在"); |
|
|
|
|
|
fileList.add(failed); |
|
|
log.warn(String.format("单位名称不存在,行号->%s", obj.getRowNum())); |
|
|
log.warn(String.format("单位名称不存在,行号->%s", obj.getRowNum())); |
|
|
iterator.remove(); |
|
|
iterator.remove(); |
|
|
} |
|
|
} |
|
@ -277,14 +302,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD |
|
|
} |
|
|
} |
|
|
//服务事项校验
|
|
|
//服务事项校验
|
|
|
if (StringUtils.isBlank(obj.getServiceMatter())) { |
|
|
if (StringUtils.isBlank(obj.getServiceMatter())) { |
|
|
numList.add(obj.getRowNum()); |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("服务事项为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
log.warn(String.format("服务事项为空,行号->%s", obj.getRowNum())); |
|
|
log.warn(String.format("服务事项为空,行号->%s", obj.getRowNum())); |
|
|
iterator.remove(); |
|
|
iterator.remove(); |
|
|
} else { |
|
|
} else { |
|
|
List<String> serviceList = Arrays.asList(obj.getServiceMatter().split(StrConstant.SEMICOLON)); |
|
|
List<String> serviceList = Arrays.asList(obj.getServiceMatter().split(StrConstant.SEMICOLON)); |
|
|
serviceList.forEach(service -> { |
|
|
serviceList.forEach(service -> { |
|
|
if (null == categoryMap.get(service)) { |
|
|
if (null == categoryMap.get(service)) { |
|
|
numList.add(obj.getRowNum()); |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("服务事项不存在"); |
|
|
|
|
|
fileList.add(failed); |
|
|
log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum())); |
|
|
log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum())); |
|
|
iterator.remove(); |
|
|
iterator.remove(); |
|
|
} |
|
|
} |
|
@ -292,79 +321,163 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
//活动标题 活动目标 活动内容 活动时间 活动地址 活动地址经度 活动地址纬度 活动结果
|
|
|
//活动标题 活动目标 活动内容 活动时间 活动地址 活动地址经度 活动地址纬度 活动结果
|
|
|
if(StringUtils.isBlank(obj.getTitle()) || StringUtils.isBlank(obj.getTarget()) || |
|
|
if(StringUtils.isBlank(obj.getTitle())) { |
|
|
StringUtils.isBlank(obj.getContent()) || |
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
StringUtils.isBlank(obj.getActivityTime()) || |
|
|
failed.setErrorInfo("活动标题为空"); |
|
|
StringUtils.isBlank(obj.getAddress()) || |
|
|
fileList.add(failed); |
|
|
StringUtils.isBlank(obj.getLatitude()) || |
|
|
log.warn(String.format("活动标题为空,行号->%s", obj.getRowNum())); |
|
|
StringUtils.isBlank(obj.getLongitude()) || |
|
|
|
|
|
StringUtils.isBlank(obj.getResult())) { |
|
|
|
|
|
numList.add(obj.getRowNum()); |
|
|
|
|
|
log.warn(String.format("活动标题、活动目标、活动内容、活动时间、活动地址、活动地址经度、活动地址纬度、活动结果为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
iterator.remove(); |
|
|
iterator.remove(); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getTarget())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动目标为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动目标为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getContent())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动内容为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动内容为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getActivityTime())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动时间为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动时间为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getAddress())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动地址为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动地址为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getLatitude())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动地址纬度为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动地址纬度为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getLongitude())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动地址经度为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动地址经度为空,行号->%s", obj.getRowNum())); |
|
|
|
|
|
} else if(StringUtils.isBlank(obj.getResult())) { |
|
|
|
|
|
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); |
|
|
|
|
|
failed.setErrorInfo("活动结果为空"); |
|
|
|
|
|
fileList.add(failed); |
|
|
|
|
|
log.warn(String.format("活动结果为空,行号->%s", obj.getRowNum())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (CollectionUtils.isEmpty(result)) { |
|
|
if (CollectionUtils.isNotEmpty(result)) { |
|
|
Collections.sort(numList); |
|
|
result.forEach(item -> { |
|
|
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、")); |
|
|
IcPartyActivityEntity entity = new IcPartyActivityEntity(); |
|
|
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!"); |
|
|
entity.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
|
|
entity.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
|
|
entity.setPids(staffInfoCache.getAgencyPIds()); |
|
|
|
|
|
entity.setTitle(item.getTitle()); |
|
|
|
|
|
entity.setTarget(item.getTarget()); |
|
|
|
|
|
entity.setContent(item.getContent()); |
|
|
|
|
|
entity.setPeopleCount(item.getPeopleCount()); |
|
|
|
|
|
entity.setActivityTime(DateUtils.parse(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN)); |
|
|
|
|
|
entity.setAddress(item.getAddress()); |
|
|
|
|
|
entity.setLatitude(item.getLatitude()); |
|
|
|
|
|
entity.setLongitude(item.getLongitude()); |
|
|
|
|
|
entity.setResult(item.getResult()); |
|
|
|
|
|
insert(entity); |
|
|
|
|
|
|
|
|
|
|
|
//保存活动与单位关系
|
|
|
|
|
|
icActivityUnitRelationService.deleteByActivity(entity.getId()); |
|
|
|
|
|
AtomicInteger i = new AtomicInteger(NumConstant.ONE); |
|
|
|
|
|
List<IcActivityUnitRelationEntity> unitRelationList = Arrays.stream(item.getUnitName().split(StrConstant.COMMA)).map(unit -> { |
|
|
|
|
|
IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity(); |
|
|
|
|
|
relation.setCustomerId(entity.getCustomerId()); |
|
|
|
|
|
relation.setAgencyId(entity.getAgencyId()); |
|
|
|
|
|
relation.setPids(entity.getPids()); |
|
|
|
|
|
relation.setActivityId(entity.getId()); |
|
|
|
|
|
relation.setUnitId(option.get(unit)); |
|
|
|
|
|
relation.setSort(i.getAndIncrement()); |
|
|
|
|
|
return relation; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
icActivityUnitRelationService.insertBatch(unitRelationList); |
|
|
|
|
|
|
|
|
|
|
|
//保存活动与服务关系
|
|
|
|
|
|
icActivityServiceRelationService.deleteByActivity(entity.getId()); |
|
|
|
|
|
AtomicInteger j = new AtomicInteger(NumConstant.ONE); |
|
|
|
|
|
List<IcActivityServiceRelationEntity> serviceRelationList = Arrays.stream(item.getServiceMatter().split(StrConstant.SEMICOLON)).map(service -> { |
|
|
|
|
|
IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity(); |
|
|
|
|
|
relation.setCustomerId(entity.getCustomerId()); |
|
|
|
|
|
relation.setAgencyId(entity.getAgencyId()); |
|
|
|
|
|
relation.setPids(entity.getPids()); |
|
|
|
|
|
relation.setActivityId(entity.getId()); |
|
|
|
|
|
relation.setServiceMatter(categoryMap.get(service)); |
|
|
|
|
|
relation.setSort(j.getAndIncrement()); |
|
|
|
|
|
return relation; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
icActivityServiceRelationService.insertBatch(serviceRelationList); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
String str = String.format("共%s条,成功导入%s条。", fileList.size() + result.size(), fileList.size() + result.size() - fileList.size()); |
|
|
|
|
|
|
|
|
result.forEach(item -> { |
|
|
if (fileList.size() > NumConstant.ZERO) { |
|
|
IcPartyActivityEntity entity = new IcPartyActivityEntity(); |
|
|
List<Integer> numList = fileList.stream().map(IcPartyActivityImportFailedExcel::getRowNum).sorted().collect(Collectors.toList()); |
|
|
entity.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
|
|
entity.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
|
|
entity.setPids(staffInfoCache.getAgencyPIds()); |
|
|
|
|
|
entity.setTitle(item.getTitle()); |
|
|
|
|
|
entity.setTarget(item.getTarget()); |
|
|
|
|
|
entity.setContent(item.getContent()); |
|
|
|
|
|
entity.setPeopleCount(item.getPeopleCount()); |
|
|
|
|
|
entity.setActivityTime(DateUtils.parse(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN)); |
|
|
|
|
|
entity.setAddress(item.getAddress()); |
|
|
|
|
|
entity.setLatitude(item.getLatitude()); |
|
|
|
|
|
entity.setLongitude(item.getLongitude()); |
|
|
|
|
|
entity.setResult(item.getResult()); |
|
|
|
|
|
insert(entity); |
|
|
|
|
|
|
|
|
|
|
|
//保存活动与单位关系
|
|
|
|
|
|
icActivityUnitRelationService.deleteByActivity(entity.getId()); |
|
|
|
|
|
AtomicInteger i = new AtomicInteger(NumConstant.ONE); |
|
|
|
|
|
List<IcActivityUnitRelationEntity> unitRelationList = Arrays.stream(item.getUnitName().split(StrConstant.COMMA)).map(unit -> { |
|
|
|
|
|
IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity(); |
|
|
|
|
|
relation.setCustomerId(entity.getCustomerId()); |
|
|
|
|
|
relation.setAgencyId(entity.getAgencyId()); |
|
|
|
|
|
relation.setPids(entity.getPids()); |
|
|
|
|
|
relation.setActivityId(entity.getId()); |
|
|
|
|
|
relation.setUnitId(option.get(unit)); |
|
|
|
|
|
relation.setSort(i.getAndIncrement()); |
|
|
|
|
|
return relation; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
icActivityUnitRelationService.insertBatch(unitRelationList); |
|
|
|
|
|
|
|
|
|
|
|
//保存活动与服务关系
|
|
|
|
|
|
icActivityServiceRelationService.deleteByActivity(entity.getId()); |
|
|
|
|
|
AtomicInteger j = new AtomicInteger(NumConstant.ONE); |
|
|
|
|
|
List<IcActivityServiceRelationEntity> serviceRelationList = Arrays.stream(item.getServiceMatter().split(StrConstant.SEMICOLON)).map(service -> { |
|
|
|
|
|
IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity(); |
|
|
|
|
|
relation.setCustomerId(entity.getCustomerId()); |
|
|
|
|
|
relation.setAgencyId(entity.getAgencyId()); |
|
|
|
|
|
relation.setPids(entity.getPids()); |
|
|
|
|
|
relation.setActivityId(entity.getId()); |
|
|
|
|
|
relation.setServiceMatter(categoryMap.get(service)); |
|
|
|
|
|
relation.setSort(j.getAndIncrement()); |
|
|
|
|
|
return relation; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
icActivityServiceRelationService.insertBatch(serviceRelationList); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
String str = String.format("共%s条,成功导入%s条。", numList.size() + result.size(), numList.size() + result.size() - numList.size()); |
|
|
|
|
|
if (numList.size() > NumConstant.ZERO) { |
|
|
|
|
|
Collections.sort(numList); |
|
|
|
|
|
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、")); |
|
|
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、")); |
|
|
log.warn(str + "第" + subList + "行未成功!"); |
|
|
log.warn(str + "第" + subList + "行未成功!"); |
|
|
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), str + "第" + subList + "行未成功!"); |
|
|
|
|
|
} |
|
|
} |
|
|
return new Result().ok(str); |
|
|
|
|
|
|
|
|
//错误数据生成文件,修改导入任务状态
|
|
|
|
|
|
erroeImport(fileList, taskId, tokenDto.getUserId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void erroeImport(List<IcPartyActivityImportFailedExcel> fileList, String importTaskId, String staffId) throws IOException { |
|
|
|
|
|
String url = ""; |
|
|
|
|
|
//1.有错误数据则生成错误数据存放文件传到阿里云服务
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(fileList)) { |
|
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"), |
|
|
|
|
|
IcPartyActivityImportFailedExcel.class, fileList); |
|
|
|
|
|
// 文件名
|
|
|
|
|
|
String resultDescFileName = UUID.randomUUID().toString().concat(".xlsx"); |
|
|
|
|
|
FileItemFactory factory = new DiskFileItemFactory(16, null); |
|
|
|
|
|
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName); |
|
|
|
|
|
OutputStream os = fileItem.getOutputStream(); |
|
|
|
|
|
Result<UploadImgResultDTO> uploadResult = null; |
|
|
|
|
|
try { |
|
|
|
|
|
workbook.write(os); |
|
|
|
|
|
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("【联建活动信息导入】上传错误描述文件:{}", errormsg); |
|
|
|
|
|
} finally { |
|
|
|
|
|
try { |
|
|
|
|
|
os.close(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("【联建活动信息导入】上传错误描述文件关闭输出流:{}", errormsg); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
fileItem.delete(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("【联建活动信息导入】上传错误描述文件删除临时文件:{}", errormsg); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (uploadResult == null || !uploadResult.success()) { |
|
|
|
|
|
log.error("【联建活动信息导入】调用OSS上传结果描述文件失败"); |
|
|
|
|
|
} else { |
|
|
|
|
|
url = uploadResult.getData().getUrl(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//2.更新导入任务数据
|
|
|
|
|
|
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); |
|
|
|
|
|
importTaskForm.setOperatorId(staffId); |
|
|
|
|
|
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_ACTIVITY); |
|
|
|
|
|
importTaskForm.setTaskId(importTaskId); |
|
|
|
|
|
importTaskForm.setResultDescFilePath(url); |
|
|
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(fileList)) { |
|
|
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); |
|
|
|
|
|
importTaskForm.setResultDesc("联建活动导入存在错误数据"); |
|
|
|
|
|
} |
|
|
|
|
|
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm); |
|
|
|
|
|
if (!result.success()) { |
|
|
|
|
|
throw new RenException(result.getInternalMsg()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|