|
@@ -4,27 +4,34 @@ import com.alibaba.excel.EasyExcel;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.sop.business.bean.dto.CrmDetailImportDto;
|
|
import com.qmth.sop.business.bean.dto.CrmDetailImportDto;
|
|
|
|
+import com.qmth.sop.business.entity.SysUser;
|
|
import com.qmth.sop.business.entity.TBCrmDetail;
|
|
import com.qmth.sop.business.entity.TBCrmDetail;
|
|
|
|
+import com.qmth.sop.business.entity.TFCustomFlow;
|
|
import com.qmth.sop.business.mapper.TBCrmDetailMapper;
|
|
import com.qmth.sop.business.mapper.TBCrmDetailMapper;
|
|
import com.qmth.sop.business.service.TBCrmDetailService;
|
|
import com.qmth.sop.business.service.TBCrmDetailService;
|
|
|
|
+import com.qmth.sop.business.service.TBCrmService;
|
|
|
|
+import com.qmth.sop.business.service.TFCustomFlowService;
|
|
|
|
+import com.qmth.sop.business.util.excel.BasicExcelListener;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
import com.qmth.sop.common.enums.FieldUniqueEnum;
|
|
import com.qmth.sop.common.enums.FieldUniqueEnum;
|
|
import com.qmth.sop.common.enums.ProductTypeEnum;
|
|
import com.qmth.sop.common.enums.ProductTypeEnum;
|
|
-import com.qmth.sop.common.util.JacksonUtil;
|
|
|
|
|
|
+import com.qmth.sop.common.enums.TFCustomTypeEnum;
|
|
import com.qmth.sop.common.util.ResultUtil;
|
|
import com.qmth.sop.common.util.ResultUtil;
|
|
|
|
+import com.qmth.sop.common.util.ServletUtil;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
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.util.LinkedMultiValueMap;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.StringJoiner;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -39,27 +46,74 @@ public class TBCrmDetailServiceImpl extends ServiceImpl<TBCrmDetailMapper, TBCrm
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(TBCrmDetailServiceImpl.class);
|
|
private final static Logger log = LoggerFactory.getLogger(TBCrmDetailServiceImpl.class);
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ TBCrmService tbCrmService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ TBCrmDetailService tbCrmDetailService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ TFCustomFlowService tfCustomFlowService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * @Description: 派单明细sop导入
|
|
|
|
- * @Param: [file, crmNo, type]
|
|
|
|
- * @return: java.util.Map<java.lang.String, java.lang.String>
|
|
|
|
- * @Author: wangliang
|
|
|
|
- * @Date: 2024/5/14
|
|
|
|
|
|
+ * 派单明细sop导入
|
|
|
|
+ *
|
|
|
|
+ * @param file
|
|
|
|
+ * @param crmNo
|
|
|
|
+ * @param processVar
|
|
|
|
+ * @param type
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public Map<String, String> sopExcelImport(MultipartFile file, String crmNo, ProductTypeEnum type)
|
|
|
|
|
|
+ public Map<String, String> sopExcelImport(MultipartFile file, String crmNo, String processVar, ProductTypeEnum type)
|
|
throws IOException {
|
|
throws IOException {
|
|
log.debug("导入Excel开始...");
|
|
log.debug("导入Excel开始...");
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
|
|
+
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+ tbCrmService.findByCrmNo(crmNo);
|
|
|
|
+ TFCustomFlow tfCustomFlow = null;
|
|
|
|
+ if (type == ProductTypeEnum.OFFICE) {
|
|
|
|
+ tfCustomFlow = tfCustomFlowService.findMaxVersion(null, null, TFCustomTypeEnum.OFFICE_SOP_FLOW);
|
|
|
|
+ }
|
|
|
|
+ Objects.requireNonNull(tfCustomFlow, "未找到教务处流程");
|
|
|
|
+
|
|
Map<String, String> messageMap = new LinkedHashMap<>();
|
|
Map<String, String> messageMap = new LinkedHashMap<>();
|
|
try {
|
|
try {
|
|
StringJoiner errorData = new StringJoiner("");
|
|
StringJoiner errorData = new StringJoiner("");
|
|
StringJoiner successData = new StringJoiner("");
|
|
StringJoiner successData = new StringJoiner("");
|
|
|
|
|
|
- List<CrmDetailImportDto> list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0)
|
|
|
|
- .doReadSync();
|
|
|
|
- log.info("list:{}", JacksonUtil.parseJson(list));
|
|
|
|
|
|
+ LinkedMultiValueMap<String, CrmDetailImportDto> crmDetailImportDtoLinkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
|
+ EasyExcel.read(file.getInputStream(), CrmDetailImportDto.class,
|
|
|
|
+ new BasicExcelListener<CrmDetailImportDto>() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void handle(LinkedMultiValueMap<String, CrmDetailImportDto> dataList,
|
|
|
|
+ StringJoiner errorDataSj, Exception exception) {
|
|
|
|
+ crmDetailImportDtoLinkedMultiValueMap.addAll(dataList);
|
|
|
|
+ errorData.add(errorDataSj.toString());
|
|
|
|
+ }
|
|
|
|
+ }).headRowNumber(2).sheet(0).doRead();
|
|
|
|
+
|
|
|
|
+ List<CrmDetailImportDto> crmDetailImportDtoList = crmDetailImportDtoLinkedMultiValueMap.get(
|
|
|
|
+ BasicExcelListener.SUCCESS);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(crmDetailImportDtoList)) {
|
|
|
|
+ if (crmDetailImportDtoList.size() > 1000) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("为效率着想,一次最多支持导入1000条");
|
|
|
|
+ }
|
|
|
|
+ List<TBCrmDetail> tbCrmDetailList = new ArrayList<>(crmDetailImportDtoList.size());
|
|
|
|
+ for (int i = 0; i < crmDetailImportDtoList.size(); i++) {
|
|
|
|
+ CrmDetailImportDto c = crmDetailImportDtoList.get(i);
|
|
|
|
+ tbCrmDetailList.add(
|
|
|
|
+ new TBCrmDetail(crmNo, tfCustomFlow.getFlowDeploymentId(), processVar, c, sysUser.getId()));
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(tbCrmDetailList)) {
|
|
|
|
+ successData.add("共导入").add(crmDetailImportDtoList.size() + "").add("条数据");
|
|
|
|
+ tbCrmDetailService.saveBatch(tbCrmDetailList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
|
|
messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
|
|
messageMap.put(SystemConstant.EXCEL_ERROR, errorData.length() > 0 ? errorData.toString() : "无");
|
|
messageMap.put(SystemConstant.EXCEL_ERROR, errorData.length() > 0 ? errorData.toString() : "无");
|
|
@@ -67,10 +121,10 @@ public class TBCrmDetailServiceImpl extends ServiceImpl<TBCrmDetailMapper, TBCrm
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
if (e instanceof DuplicateKeyException) {
|
|
if (e instanceof DuplicateKeyException) {
|
|
String errorColumn = e.getCause().toString();
|
|
String errorColumn = e.getCause().toString();
|
|
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length())
|
|
|
|
- .replaceAll("'", "");
|
|
|
|
|
|
+ String[] strs = StringUtils.split(errorColumn, "-");
|
|
|
|
+ String[] columns = StringUtils.split(strs[strs.length - 1], "\\'");
|
|
throw ExceptionResultEnum.SQL_ERROR.exception(
|
|
throw ExceptionResultEnum.SQL_ERROR.exception(
|
|
- "[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
|
|
|
+ FieldUniqueEnum.convertToTitle(columns[columns.length - 1]) + ":[" + columns[0] + "]数据不允许重复插入");
|
|
} else if (e instanceof ApiException) {
|
|
} else if (e instanceof ApiException) {
|
|
ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
} else {
|
|
} else {
|