|
|
@@ -0,0 +1,204 @@
|
|
|
+package com.pavis.app.saasbacken.excel.org;
|
|
|
+
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.pavis.app.saasbacken.excel.OnAllAnalysedListener;
|
|
|
+import com.pavis.app.saasbacken.exception.ExcelHeadException;
|
|
|
+import com.pavis.app.saasbacken.http.ErrorCode;
|
|
|
+import com.pavis.app.saasbacken.utils.CheckUtils;
|
|
|
+import com.pavis.app.saasbacken.utils.ExcelPatternMsgUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author guanhuijuan
|
|
|
+ * @create 2020-06-22 13:20
|
|
|
+ * @desc RecommendedInfoExcelDataListener
|
|
|
+ **/
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class EnterpriseBasicInfoExcelDataListener extends AnalysisEventListener<EnterpriseBasicInfoExcelData> {
|
|
|
+ private OnAllAnalysedListener<EnterpriseBasicInfoExcelData> onAllAnalysedListener;
|
|
|
+
|
|
|
+ private List<EnterpriseBasicInfoExcelData> enterpriseBasicInfoExcelDataList = Lists.newArrayList();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结果标记 默认错误
|
|
|
+ */
|
|
|
+ private boolean isCorrectFormat = true;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结果信息
|
|
|
+ */
|
|
|
+ private String resultMessage = "";
|
|
|
+
|
|
|
+ private Map<String,String> errorMap = new HashMap<>();
|
|
|
+ private List<Map<String,String>> errorList = new ArrayList<>();
|
|
|
+ /**
|
|
|
+ * 格式验证。
|
|
|
+ */
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+
|
|
|
+ public EnterpriseBasicInfoExcelDataListener(OnAllAnalysedListener<EnterpriseBasicInfoExcelData> onAllAnalysedListener) {
|
|
|
+ this.onAllAnalysedListener = onAllAnalysedListener;
|
|
|
+ }
|
|
|
+
|
|
|
+ public EnterpriseBasicInfoExcelDataListener() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(EnterpriseBasicInfoExcelData enterpriseBasicInfoExcelData, AnalysisContext analysisContext) {
|
|
|
+ // Map<Integer, Map<Integer, String>> map = new HashMap<>();
|
|
|
+ // Map<Integer, JSONObject> map = new HashMap<>();
|
|
|
+ // map.put(analysisContext.readRowHolder().getRowIndex(), checkError(enterpriseBasicInfoExcelData));
|
|
|
+ // System.out.println("***********map:" + JSON.toJSONString(map));
|
|
|
+ if (resultMessage.equals(ExcelPatternMsgUtils.HEAD_NULL_ERROR)
|
|
|
+ || resultMessage.equals(ExcelPatternMsgUtils.HEAD_ERROR)) {
|
|
|
+ try {
|
|
|
+ throw new ExcelHeadException(ErrorCode.ERROR_EXCEL_HEAD.getCode(), ErrorCode.ERROR_EXCEL_HEAD.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ js = checkError(enterpriseBasicInfoExcelData);
|
|
|
+ enterpriseBasicInfoExcelData.setErrorRemark(js.toJSONString().equals("{}") ? "" : js.toJSONString());
|
|
|
+ System.out.println("***>" + JSON.toJSONString(enterpriseBasicInfoExcelData));
|
|
|
+ enterpriseBasicInfoExcelDataList.add(enterpriseBasicInfoExcelData);
|
|
|
+ js.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+ onAllAnalysedListener.onAllAnalysed(enterpriseBasicInfoExcelDataList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 这里会一行行的返回头
|
|
|
+ *
|
|
|
+ * @param headMap
|
|
|
+ * @param context
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
|
|
|
+ log.info("解析到一条头数据:{}", JSON.toJSONString(headMap));
|
|
|
+ Map<String, Map<Integer, String>> map = new HashMap<>();
|
|
|
+ map.put(String.valueOf(context.readRowHolder().getRowIndex()), headMap);
|
|
|
+ System.out.println("head map:"+ JSON.toJSONString(map));
|
|
|
+ String basicStr = ExcelPatternMsgUtils.BASIC_TL_HEAD;
|
|
|
+ if (map.containsKey("1")) {
|
|
|
+ if (!JSON.toJSONString(map.get("1")).equals(basicStr)) {
|
|
|
+ log.info("head:{}",basicStr);
|
|
|
+ log.info("excel head:{}",map.get("1"));
|
|
|
+ resultMessage = ExcelPatternMsgUtils.HEAD_ERROR;
|
|
|
+ enterpriseBasicInfoExcelDataList.clear();
|
|
|
+ isCorrectFormat = false;
|
|
|
+ log.info("head:{}",resultMessage);
|
|
|
+ // throw new ExcelHeadException(ErrorCode.ERROR.getCode(), ErrorCode.ERROR.getMessage());
|
|
|
+ // try {
|
|
|
+ // throw new ExcelHeadException(ErrorCode.ERROR.getCode(), ErrorCode.ERROR.getMessage());
|
|
|
+ // // throw new Exception("文件类型不匹配,请上传正确类型的文件后再试!");
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // e.printStackTrace();
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // if (map.containsKey(0)) {
|
|
|
+ // resultMessage = ExcelPatternMsgUtils.HEAD_NULL_ERROR;
|
|
|
+ // log.info("none head:{}",resultMessage);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析各字段是否符合要求。
|
|
|
+ * @param excelData
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject checkError(EnterpriseBasicInfoExcelData excelData){
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+ System.out.println(excelData.getName());
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getRegistrationcapital()) && !CheckUtils.isNumeric(excelData.getRegistrationcapital())) {
|
|
|
+ log.info("注册资本(万元):{}",excelData.getRegistrationcapital());
|
|
|
+ js.put("registrationcapital", "注册资本(万元)格式有误," + ExcelPatternMsgUtils.NUMBER_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getPracticalcapital()) && !CheckUtils.isTaxNum(excelData.getPracticalcapital())) {
|
|
|
+ log.info("实缴资本(万元):{}", excelData.getPracticalcapital());
|
|
|
+ js.put("practicalcapital", "实缴资本(万元)格式有误," + ExcelPatternMsgUtils.TAX_NUM_MSG);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(excelData.getRegistrationdate()) && !CheckUtils.isDate(excelData.getRegistrationdate())){
|
|
|
+ System.out.println("getRegistrationdate");
|
|
|
+ js.put("registrationdate", "成立日期格式有误,"+ ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getOperatingperiod()) && !CheckUtils.isDate(excelData.getOperatingperiod())) {
|
|
|
+ log.info("营业期限:{}",excelData.getOperatingperiod());
|
|
|
+ js.put("operatingperiod", "营业期限格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getApprovaltime()) && !CheckUtils.isDate(excelData.getApprovaltime())) {
|
|
|
+ log.info("营业期限:{}",excelData.getApprovaltime());
|
|
|
+ js.put("approvaltime", "核准日期格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getEmphasisdate()) && !CheckUtils.isDate(excelData.getEmphasisdate())) {
|
|
|
+ log.info("省级重点企业研究院认定年份:{}",excelData.getEyasdate());
|
|
|
+ js.put("emphasisdate","省级重点企业研究院认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getProvincialdate()) && !CheckUtils.isDate(excelData.getProvincialdate())) {
|
|
|
+ log.info("省级企业研究院认定年份:{}",excelData.getProvincialdate());
|
|
|
+ js.put("provincialdate:{}","省级企业研究院认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getHighandnewdate()) && !CheckUtils.isDate(excelData.getHighandnewdate())) {
|
|
|
+ js.put("highandnewdate","浙江省高新技术研究开发中心认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getProvincesciencesmalldate()) && !CheckUtils.isDate(excelData.getProvincesciencesmalldate())) {
|
|
|
+ js.put("provincesciencesmalldate","省科小认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getEyasdate()) && !CheckUtils.isDate(excelData.getEyasdate())) {
|
|
|
+ js.put("eyasdate","雏鹰计划认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getMunicipalresearchdate()) && !CheckUtils.isDate(excelData.getMunicipalresearchdate())) {
|
|
|
+ js.put("municipalresearchdate","市级研发中心认定年份格式有误," + ExcelPatternMsgUtils.DATE2_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getLegalrepresentativetel()) && !CheckUtils.isTelephone(excelData.getLegalrepresentativetel())) {
|
|
|
+ log.info("企业法定代表人联系电话," + excelData.getLegalrepresentativetel());
|
|
|
+ js.put("legalrepresentativetel","企业法定代表人联系电话格式有误," + ExcelPatternMsgUtils.TEL_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getTechnologycontactphone()) && !CheckUtils.isTelephone(excelData.getTechnologycontactphone())) {
|
|
|
+ log.info("技术负责人联系电话," + excelData.getTechnologycontactphone());
|
|
|
+ js.put("technologycontactphone","技术负责人联系电话格式有误," + ExcelPatternMsgUtils.TEL_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getFinancialcontactphone()) && !CheckUtils.isTelephone(excelData.getFinancialcontactphone())) {
|
|
|
+ log.info("财务负责人联系电话," + excelData.getFinancialcontactphone());
|
|
|
+ js.put("financialcontactphone","财务负责人联系电话格式有误," + ExcelPatternMsgUtils.TEL_MSG);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(excelData.getSciencecontactphone()) && !CheckUtils.isTelephone(excelData.getSciencecontactphone())) {
|
|
|
+ log.info("科技联络人联系电话," + excelData.getSciencecontactphone());
|
|
|
+ js.put("sciencecontactphone","财务联络人联系电话格式有误," + ExcelPatternMsgUtils.TEL_MSG);
|
|
|
+ }
|
|
|
+ System.out.println(js.toJSONString());
|
|
|
+ list.add(js);
|
|
|
+ System.out.println("企业基本信息,listttt>" + JSON.toJSONString(list));
|
|
|
+ return js;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析出现错误会进入该方法 具体看源代码或文档
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onException(Exception exception, AnalysisContext context) throws Exception {
|
|
|
+ throw exception;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|