|
@@ -0,0 +1,179 @@
|
|
|
+package com.yonge.cooleshow.biz.dal.execl.analysis;
|
|
|
+
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.enums.CellExtraTypeEnum;
|
|
|
+import com.alibaba.excel.metadata.Sheet;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.microsvc.toolkit.middleware.excel.analysis.AnalysisContext;
|
|
|
+import com.microsvc.toolkit.middleware.excel.analysis.DataAnalysis;
|
|
|
+import com.microsvc.toolkit.middleware.excel.util.DownloadManager;
|
|
|
+import com.yonge.cooleshow.biz.dal.execl.entity.TeacherImportWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.execl.listener.TeacherImportListener;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.EasyExcelService;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.Setter;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Getter
|
|
|
+@Setter
|
|
|
+public class TeacherImportAnalysis extends DataAnalysis<TeacherImportAnalysis> {
|
|
|
+
|
|
|
+
|
|
|
+ private List<TeacherImportWrapper.TeacherImport> teacherImportWrappers;
|
|
|
+
|
|
|
+ // Excel解析服务
|
|
|
+ private EasyExcelService easyExcelService;
|
|
|
+
|
|
|
+ private final Map<String, TeacherImportWrapper.TeacherImport> recordMap = Maps.newHashMap();
|
|
|
+ private final Map<String, Long> subjectMap = Maps.newHashMap();
|
|
|
+ private final Map<String, Long> tenantMap = Maps.newHashMap();
|
|
|
+ public TeacherImportAnalysis(AnalysisContext context) {
|
|
|
+ super(context);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static TeacherImportAnalysis build(EasyExcelService easyExcelService) {
|
|
|
+ TeacherImportAnalysis analysis = new TeacherImportAnalysis(AnalysisContext.builder().build());
|
|
|
+ analysis.setEasyExcelService(easyExcelService);
|
|
|
+ analysis.setTeacherImportWrappers(Lists.newArrayList());
|
|
|
+ return analysis;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取文件数据到内存
|
|
|
+ *
|
|
|
+ * @param path 本地文件地址
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void read(String path) {
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+ List<Sheet> sheets = EasyExcel.read(file).build().getSheets();
|
|
|
+ if (CollectionUtils.isNotEmpty(sheets)) {
|
|
|
+
|
|
|
+ sheets.forEach(item -> {
|
|
|
+ // 读取数据
|
|
|
+ EasyExcel.read(file, TeacherImportWrapper.TeacherImport.class, new TeacherImportListener(getTeacherImportWrappers(), item.getSheetName()))
|
|
|
+ .extraRead(CellExtraTypeEnum.MERGE).sheet(item.getSheetName()).doRead();
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除本地缓存文件
|
|
|
+ DownloadManager.getInstance().deleteOnExit(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验数据合法
|
|
|
+ *
|
|
|
+ * @return Map<Integer, String>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<Integer, String> verify() {
|
|
|
+
|
|
|
+ // 加载校验数据参数
|
|
|
+ if (Objects.nonNull(getTeacherImportWrappers())) {
|
|
|
+ loadVerifyParamData();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Integer, String> verifyDataMap = Maps.newLinkedHashMap();
|
|
|
+
|
|
|
+ // 校验每条入库记录数据合法性
|
|
|
+ StringBuffer ret = new StringBuffer();
|
|
|
+ for (TeacherImportWrapper.TeacherImport item : getTeacherImportWrappers()) {
|
|
|
+
|
|
|
+ // 检测机构编号,金额,订单号,结算状态
|
|
|
+ if (StringUtils.isEmpty(item.getUsername())) {
|
|
|
+ ret.append("用户昵称不能为空;");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(item.getRealName())) {
|
|
|
+ ret.append("真实姓名不能为空;");
|
|
|
+ }else {
|
|
|
+ if(!item.getRealName().matches("^[\\u4e00-\\u9fa5]{2,10}$")){
|
|
|
+ ret.append("真实姓名格式不正确;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(item.getPhone())) {
|
|
|
+ ret.append("手机号不能为空;");
|
|
|
+ }else {
|
|
|
+ //手机号校验
|
|
|
+ if (!item.getPhone().matches("^1[3-9]\\d{9}$")) {
|
|
|
+ ret.append("手机号格式不正确;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(item.getIdCardNo())) {
|
|
|
+ //身份证校验
|
|
|
+ if (!item.getIdCardNo().matches("(^\\d{6}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}(\\d|X|x)$)|(^\\d{6}\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}$)")) {
|
|
|
+ ret.append("身份证格式不正确;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(item.getSubjectName())) {
|
|
|
+ ret.append("老师声部不能为空;");
|
|
|
+ }else {
|
|
|
+ if (!subjectMap.containsKey(item.getSubjectName())) {
|
|
|
+ ret.append("声部无效:").append(item.getSubjectName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.getIsTestUser() == null) {
|
|
|
+ ret.append("是否测试用户不能为空;");
|
|
|
+ }
|
|
|
+ if (item.getSettlementFrom() == null) {
|
|
|
+ ret.append("结算方式不能为空;");
|
|
|
+ }
|
|
|
+ if (item.getCustomerService() == null) {
|
|
|
+ ret.append("是否客服不能为空;");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(ret)) {
|
|
|
+ verifyDataMap.put(item.getRowIndex(), ret.toString());
|
|
|
+ ret = new StringBuffer(); // 重置数据状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据校验记录信息
|
|
|
+ getContext().total(getTeacherImportWrappers().size()).failure(verifyDataMap.size())
|
|
|
+ .setSuccess(getContext().getTotal() - getContext().getFailure());
|
|
|
+
|
|
|
+ return verifyDataMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据转换
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void convert() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载校验数据参数
|
|
|
+ */
|
|
|
+ private void loadVerifyParamData() {
|
|
|
+ //校验数据
|
|
|
+ //获取所有手机号
|
|
|
+
|
|
|
+ subjectMap.putAll(easyExcelService.getSubjectMap());
|
|
|
+ tenantMap.putAll(easyExcelService.getTenantMap());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据对象
|
|
|
+ * @return RoomInfoAnalysis
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TeacherImportAnalysis get() {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|