package jnpf.onlinedev.util.onlineDevUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import jnpf.base.*; import jnpf.base.entity.DictionaryDataEntity; import jnpf.base.entity.ProvinceEntity; import jnpf.base.entity.VisualdevEntity; import jnpf.base.model.OnlineImport.ExcelImportModel; import jnpf.base.model.OnlineImport.ImportFormCheckUniqueModel; import jnpf.base.model.OnlineImport.VisualdevModelDataInfoVO; import jnpf.base.model.VisualDevJsonModel; import jnpf.base.model.VisualErrInfo; import jnpf.base.model.flow.DataModel; import jnpf.base.util.FormCheckUtils; import jnpf.base.util.FormPublicUtils; import jnpf.constant.DataInterfaceVarConst; import jnpf.constant.MsgCode; import jnpf.constant.PermissionConst; import jnpf.database.model.entity.DbLinkEntity; import jnpf.database.util.DynamicDataSourceUtil; import jnpf.emnus.SysParamEnum; import jnpf.exception.DataException; import jnpf.exception.WorkFlowException; import jnpf.flowable.WorkFlowApi; import jnpf.flowable.entity.TaskEntity; import jnpf.flowable.entity.TemplateJsonEntity; import jnpf.model.visualJson.FieLdsModel; import jnpf.model.visualJson.OnlineCusCheckModel; import jnpf.model.visualJson.TemplateJsonModel; import jnpf.model.visualJson.UploaderTemplateModel; import jnpf.model.visualJson.config.RegListModel; import jnpf.onlinedev.model.OnlineDevEnum.OnlineDataTypeEnum; import jnpf.onlinedev.model.VisualParamModel; import jnpf.onlinedev.service.VisualdevModelDataService; import jnpf.permission.OrganizeApi; import jnpf.permission.PositionApi; import jnpf.permission.UserApi; import jnpf.permission.UserRelationApi; import jnpf.permission.entity.OrganizeEntity; import jnpf.permission.entity.PositionEntity; import jnpf.permission.entity.UserEntity; import jnpf.permission.entity.UserRelationEntity; import jnpf.util.*; import jnpf.util.visiual.JnpfKeyConsts; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @Slf4j @Component public class OnlineExcelUtil { @Autowired private DictionaryDataApi dictionaryDataApi; @Autowired private UserApi userApi; @Autowired private PositionApi positionApi; @Autowired private AreaApi areaApi; @Autowired private OrganizeApi organizeApi; @Autowired private VisualdevModelDataService visualdevModelDataService; @Autowired private DataInterFaceApi dataInterFaceApi; @Autowired private DataSourceApi dataSourceApi; @Autowired private UserRelationApi userRelationApi; @Autowired private FormCheckUtils formCheckUtils; @Autowired private WorkFlowApi workFlowApi; @Autowired private OnlineSwapDataUtils onlineSwapDataUtils; public ExcelImportModel createExcelData(List> dataList, VisualDevJsonModel visualJsonModel, VisualdevEntity visualdevEntity) throws WorkFlowException { ExcelImportModel excelImportModel = new ExcelImportModel(); Integer primaryKeyPolicy = visualJsonModel.getFormData().getPrimaryKeyPolicy(); String uploaderTemplateJson = visualJsonModel.getColumnData().getUploaderTemplateJson(); UploaderTemplateModel uploaderTemplateModel = JsonUtil.getJsonToBean(uploaderTemplateJson, UploaderTemplateModel.class); String dataType = uploaderTemplateModel.getDataType(); ImportFormCheckUniqueModel uniqueModel = new ImportFormCheckUniqueModel(); uniqueModel.setMain(true); uniqueModel.setDbLinkId(visualJsonModel.getDbLinkId()); uniqueModel.setUpdate(dataType.equals("2")); uniqueModel.setPrimaryKeyPolicy(primaryKeyPolicy); uniqueModel.setLogicalDelete(visualJsonModel.getFormData().getLogicalDelete()); uniqueModel.setTableModelList(visualJsonModel.getVisualTables()); DbLinkEntity linkEntity = dataSourceApi.getInfo(visualJsonModel.getDbLinkId()); uniqueModel.setLinkEntity(linkEntity); //流程表单导入,传流程大id查询小idlist用于过滤数据 String mainFlowID = null; if (StringUtil.isNotEmpty(visualJsonModel.getFlowId())) { List flowVersionIds = workFlowApi.getFlowIdsByTemplate(visualJsonModel.getFlowId()); uniqueModel.setFlowId(visualJsonModel.getFlowId()); uniqueModel.setFlowIdList(flowVersionIds.stream().map(TemplateJsonEntity::getId).distinct().collect(Collectors.toList())); mainFlowID = flowVersionIds.stream().filter(t -> Objects.equals(t.getState(), 1)).findFirst().orElse(new TemplateJsonEntity()).getId(); } //获取缓存 Map localCache = onlineSwapDataUtils.getlocalCache(); List> failResult = new ArrayList<>(); List dataInfo = new ArrayList<>(); try { for (int i = 0, len = dataList.size(); i < len; i++) { Map data = dataList.get(i); //导入时默认第一个流程 data.put(FlowFormConstant.FLOWID, mainFlowID); Map resultMap = new HashMap<>(data); StringJoiner errInfo = new StringJoiner(","); Map errorMap = new HashMap<>(data); List errList = this.checkExcelData(visualJsonModel.getFormListModels(), data, localCache, resultMap, errorMap, uniqueModel); //业务主键判断--导入新增或者跟新 VisualErrInfo visualErrInfo; try { DynamicDataSourceUtil.switchToDataSource(linkEntity); visualErrInfo = formCheckUtils.checkBusinessKey(visualJsonModel.getFormListModels(), resultMap, visualJsonModel.getVisualTables(), visualJsonModel.getFormData(), null); } finally { DynamicDataSourceUtil.clearSwitchDataSource(); } if (uniqueModel.isUpdate()) { if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getId())) { uniqueModel.setId(visualErrInfo.getId()); //判断流程是否已发起 if (StringUtil.isNotEmpty(visualErrInfo.getFlowTaskId())) { String finalTaskId = visualErrInfo.getFlowTaskId(); List flowIdList = new ArrayList<>(); flowIdList.add(finalTaskId); List tasks = workFlowApi.getInfosSubmit(flowIdList.toArray(new String[]{})); if (tasks.size() > 0) { boolean errorMsg = tasks.stream().filter(t -> Objects.equals(t.getStatus(), 0)).count() == 0; String msg = "已发起流程,导入失败"; if (errorMsg) { errorMap.put("errorsInfo", msg); failResult.add(errorMap); continue; } } } } } else { if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getErrMsg())) { errorMap.put("errorsInfo", visualErrInfo.getErrMsg()); failResult.add(errorMap); continue; } } onlineSwapDataUtils.checkUnique(visualJsonModel.getFormListModels(), data, errList, uniqueModel); errList.stream().forEach(t -> { if (StringUtil.isNotEmpty(t)) { errInfo.add(t); } }); if (errInfo.length() > 0) { errorMap.put("errorsInfo", errInfo.toString()); failResult.add(errorMap); } else { VisualdevModelDataInfoVO infoVO = new VisualdevModelDataInfoVO(); if (StringUtil.isNotEmpty(uniqueModel.getId())) { visualdevModelDataService.visualUpdate( VisualParamModel.builder().visualdevEntity(visualdevEntity).data(resultMap).id(uniqueModel.getId()).isUpload(true).build()); infoVO.setId(uniqueModel.getId()); infoVO.setIntegrateId(uniqueModel.getId()); infoVO.setData(JsonUtil.getObjectToString(resultMap)); } else { DataModel dataModel = visualdevModelDataService.visualCreate( VisualParamModel.builder().visualdevEntity(visualdevEntity).data(resultMap).isUpload(true).build()); infoVO.setId(dataModel.getMainId()); infoVO.setData(JsonUtil.getObjectToString(resultMap)); } dataInfo.add(infoVO); } } } catch (Exception e) { e.printStackTrace(); throw new WorkFlowException(MsgCode.IMP004.get()); } finally { DynamicDataSourceUtil.clearSwitchDataSource(); } excelImportModel.setFnum(failResult.size()); excelImportModel.setSnum(dataList.size() - failResult.size()); excelImportModel.setResultType(failResult.size() > 0 ? 1 : 0); excelImportModel.setFailResult(failResult); excelImportModel.setDataInfoList(dataInfo); return excelImportModel; } public List checkExcelData(List modelList, Map data, Map localCache, Map insMap, Map errorMap, ImportFormCheckUniqueModel uniqueModel) { List errList = new ArrayList<>(modelList.size()); try { UserInfo userInfo = UserProvider.getUser(); UserEntity userEntity = userApi.getInfoById(userInfo.getUserId()); //读取系统控件 所需编码 id Map depMap = (Map) localCache.get("_dep_map"); Map comMap = (Map) localCache.get("_com_map"); Map posMap = (Map) localCache.get("_pos_map"); //key value对调 posMap = posMap.entrySet().stream().collect(Collectors.toMap(t -> String.valueOf(t.getValue()), Map.Entry::getKey, (e, r) -> r)); Map userMap = (Map) localCache.get("_user_map"); Map roleMap = (Map) localCache.get("_role_map"); Map groupMap = (Map) localCache.get("_group_map"); Map allOrgsTreeName = (Map) localCache.get("_com_tree_map"); //系统参数,及xxxx--当前组织数据缓存 Map> allTypeMap = new HashMap<>(); allTypeMap = localCache.containsKey("allTypeMap") ? (Map>) localCache.get("allTypeMap") : allTypeMap; //异常数据 for (int i = 0; i < modelList.size(); i++) { FieLdsModel swapDataVo = modelList.get(i); errList.add(i, ""); try { String jnpfKey = swapDataVo.getConfig().getJnpfKey(); String dataType = swapDataVo.getConfig().getDataType(); Object valueO = data.get(swapDataVo.getVModel()); String label = swapDataVo.getConfig().getLabel(); //不支持导入控件 if (JnpfKeyConsts.getUploadMaybeNull().contains(jnpfKey)) { insMap.put(swapDataVo.getVModel(), null); continue; } //是否必填 boolean required = swapDataVo.getConfig().isRequired(); if (valueO == null || "null".equals(valueO) || StringUtil.isEmpty(String.valueOf(valueO))) { if (required) { errList.set(i, label + "不能为空"); } continue; } String value = String.valueOf(valueO); if (StringUtil.isEmpty(value)) { continue; } Boolean multiple = swapDataVo.getMultiple(); if (JnpfKeyConsts.CHECKBOX.equals(jnpfKey)) { multiple = true; } if (JnpfKeyConsts.CASCADER.equals(jnpfKey)) { multiple = swapDataVo.getMultiple(); } boolean valueMul = value.contains(","); value = value.trim(); List valueList = valueMul ? Arrays.asList(value.split(",")) : new ArrayList<>(); if (!valueMul) { valueList.add(value); } String ableIds = swapDataVo.getAbleIds() != null ? swapDataVo.getAbleIds() : "[]"; List ableList = JsonUtil.getJsonToList(ableIds, String.class); //处理自定义范围:系统参数及、选中组织、选中组织及子组织、选中组织及子孙组织、 OnlineCusCheckModel cusCheckModel = getSystemParamIds(ableList, allTypeMap, jnpfKey); cusCheckModel.setControlType(jnpfKey); List dataList; switch (jnpfKey) { case JnpfKeyConsts.NUM_INPUT: String regNum = "-?\\d+(\\.\\d+)?"; if (StringUtil.isNotEmpty(value) && !value.matches(regNum)) { errList.set(i, label + "值不正确"); break; } //有精度,验证精度 BigDecimal valueDecimal = null; try { valueDecimal = new BigDecimal(value); } catch (Exception e) { } if (valueDecimal == null) { errList.set(i, label + "值不正确"); break; } if (swapDataVo.getPrecision() != null && valueDecimal.scale() > swapDataVo.getPrecision()) { errList.set(i, label + "值的精度不正确"); break; } if (swapDataVo.getMin() != null) { if (valueDecimal.compareTo(new BigDecimal(swapDataVo.getMin())) < 0) { errList.set(i, label + "值不能小于最小值"); break; } } if (swapDataVo.getMax() != null) { if (valueDecimal.compareTo(new BigDecimal(swapDataVo.getMax())) > 0) { errList.set(i, label + "值不能大于最大值"); break; } } break; /** * 高级控件 */ case JnpfKeyConsts.COMSELECT: if (!multiple && valueList.size() > 1) { errList.set(i, label + "值不正确"); break; } //验证值是否正确 // List> comTwoList = new ArrayList<>(); List comOneList = new ArrayList<>(); boolean comErrorHapen = false; for (String comValue : valueList) { if (StringUtil.isEmpty(comValue)) { errList.set(i, label + "值不正确"); comErrorHapen = true; break; } boolean find = false; for (String key : allOrgsTreeName.keySet()) { Object o = allOrgsTreeName.get(key); if (comValue.equals(o.toString())) { comOneList.add(key); find = true; break; } } if (!find) { errList.set(i, label + "值不正确"); comErrorHapen = true; break; } } if (comErrorHapen) { break; } //判断是否是可选范围 insMap.put(swapDataVo.getVModel(), !multiple ? (comOneList.size() > 0 ? comOneList.get(0) : "") : JsonUtil.getObjectToString(comOneList)); if ("custom".equals(swapDataVo.getSelectType())) { cusCheckModel.setDataList(comOneList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.DEPSELECT: dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, depMap, valueList, errList, i); if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(dataList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.POSSELECT: dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, posMap, valueList, errList, i); if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(dataList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.USERSELECT: dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, userMap, valueList, errList, i); if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(dataList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.CUSTOMUSERSELECT: boolean cusUserErrorHapen = false; if (!multiple) { //非多选填入多选值 if (valueList.size() > 1) { cusUserErrorHapen = true; errList.set(i, label + "值不正确"); } } if (!cusUserErrorHapen) { boolean cusUserErrorHapen1 = false; List cusUserList = new ArrayList<>(); for (String va : valueList) { if (StringUtil.isEmpty(va)) { cusUserErrorHapen1 = true; break; } String type = null; String id = null; if (groupMap.get(va) != null) { type = "group"; id = groupMap.get(va).toString(); } else if (roleMap.get(va) != null) { type = "role"; id = roleMap.get(va).toString(); } else if (depMap.get(va) != null) { type = "department"; id = depMap.get(va).toString(); } else if (comMap.get(va) != null) { type = "company"; id = comMap.get(va).toString(); } else if (posMap.get(va) != null) { type = "position"; id = posMap.get(va).toString(); } else if (userMap.get(va) != null) { type = "user"; id = userMap.get(va).toString(); } if (type == null && id == null) { cusUserErrorHapen1 = true; } else { String lastCusId = id + "--" + type; cusUserList.add(lastCusId); } } if (cusUserErrorHapen1) { errList.set(i, label + "值不正确"); } else { insMap.put(swapDataVo.getVModel(), !multiple ? cusUserList.get(0) : JsonUtil.getObjectToString(cusUserList)); if (swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(cusUserList); checkCustomControl(cusCheckModel, errList, i, label); } } } break; case JnpfKeyConsts.ROLESELECT: dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, roleMap, valueList, errList, i); if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(dataList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.GROUPSELECT: dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, groupMap, valueList, errList, i); if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) { cusCheckModel.setDataList(dataList); checkCustomControl(cusCheckModel, errList, i, label); } break; case JnpfKeyConsts.ADDRESS: if (!multiple && valueList.size() > 1) { errList.set(i, label + "值不正确"); break; } boolean errorHapen = false; valueList = Arrays.asList(value.split(",")); List addresss = new ArrayList<>(); List addressList1 = new ArrayList<>(); for (String va : valueList) { if (StringUtil.isEmpty(va)) { errList.set(i, label + "值不正确"); errorHapen = true; break; } String[] addressSplit = va.split("/"); if (addressSplit.length != swapDataVo.getLevel() + 1) { errList.set(i, label + "值的格式不正确"); errorHapen = true; break; } List addressJoined = new ArrayList<>(); List addressParentID = new ArrayList<>(); for (String add : addressSplit) { ProvinceEntity PRO = areaApi.getProListBytype(add, addressParentID); if (PRO == null) { errList.set(i, label + "值不正确"); errorHapen = true; break; } else { addressJoined.add(PRO.getId()); addressParentID.add(PRO.getId()); } } if (errorHapen) { break; } addressList1.addAll(addressJoined); addresss.add(addressJoined.toArray(new String[addressJoined.size()])); } if (errorHapen) { break; } insMap.put(swapDataVo.getVModel(), multiple ? JsonUtil.getObjectToString(addresss) : JsonUtil.getObjectToString(addressList1)); break; /** * 系统控件 */ case JnpfKeyConsts.CURRORGANIZE: List OrgRelations = userRelationApi.getListByUserIdAndObjType(userInfo.getUserId(), PermissionConst.ORGANIZE); insMap.put(swapDataVo.getVModel(), OrgRelations.size() > 0 ? OrgRelations.get(0).getObjectId() : null); break; case JnpfKeyConsts.CURRDEPT: List depUserRelations = userRelationApi.getListByUserIdAndObjType(userInfo.getUserId(), PermissionConst.DEPARTMENT); insMap.put(swapDataVo.getVModel(), depUserRelations.size() > 0 ? depUserRelations.get(0).getObjectId() : null); break; case JnpfKeyConsts.CREATEUSER: insMap.put(swapDataVo.getVModel(), userEntity.getId()); break; case JnpfKeyConsts.CREATETIME: insMap.put(swapDataVo.getVModel(), DateUtil.getNow()); break; case JnpfKeyConsts.MODIFYTIME: break; case JnpfKeyConsts.MODIFYUSER: break; case JnpfKeyConsts.CURRPOSITION: insMap.put(swapDataVo.getVModel(), userEntity.getPositionId()); break; /** * 基础控件 */ case JnpfKeyConsts.SWITCH: String activeTxt = swapDataVo.getActiveTxt(); String inactiveTxt = swapDataVo.getInactiveTxt(); if (value.equals(activeTxt)) { insMap.put(swapDataVo.getVModel(), 1); } else if (value.equals(inactiveTxt)) { insMap.put(swapDataVo.getVModel(), 0); } else { errList.set(i, label + "值不正确"); } break; case JnpfKeyConsts.RATE: Double ratevalue = null; try { ratevalue = Double.valueOf(value); if (ratevalue == null) { errList.set(i, label + "值不正确"); break; } } catch (Exception e) { errList.set(i, label + "值不正确"); break; } Double maxvalue = Double.valueOf(0); if (swapDataVo.getCount() != -1) { maxvalue = Double.valueOf(swapDataVo.getCount()); } if (ratevalue > maxvalue) { errList.set(i, label + "值不能大于最大值"); break; } if (swapDataVo.getAllowhalf()) { if (ratevalue % 0.5 != 0 || ratevalue < 0) { errList.set(i, label + "值不正确"); } } else { if (ratevalue % 1 != 0 || ratevalue < 0) { errList.set(i, label + "值不正确"); } } insMap.put(swapDataVo.getVModel(), ratevalue); break; case JnpfKeyConsts.SLIDER: BigDecimal Ivalue = null; try { Ivalue = new BigDecimal(value); if (Ivalue == null) { errList.set(i, label + "值不正确"); break; } } catch (Exception e) { errList.set(i, label + "值不正确"); break; } if (swapDataVo.getMin() != null) { BigDecimal min = new BigDecimal(swapDataVo.getMin()); if (Ivalue.compareTo(min) == -1) { errList.set(i, label + "值不能小于最小值"); break; } } if (swapDataVo.getMax() != null) { BigDecimal max = new BigDecimal(swapDataVo.getMax()); if (Ivalue.compareTo(max) == 1) { errList.set(i, label + "值不能大于最大值"); break; } } insMap.put(swapDataVo.getVModel(), Ivalue); break; case JnpfKeyConsts.TEXTAREA: if (StringUtil.isNotEmpty(swapDataVo.getMaxlength())) { if (value.length() > Integer.valueOf(swapDataVo.getMaxlength())) { errList.set(i, label + "值超出最多输入字符限制"); break; } } break; case JnpfKeyConsts.COM_INPUT: //只验证子表。主副表在外面做唯一验证 Boolean unique = swapDataVo.getConfig().getUnique(); if (!uniqueModel.isMain()) { if (StringUtil.isNotEmpty(swapDataVo.getMaxlength())) { if (value.length() > Integer.valueOf(swapDataVo.getMaxlength())) { errList.set(i, label + "值超出最多输入字符限制"); break; } } boolean comInputError = false; if (unique) { //子表重复只判断同一个表单 if (insMap.get("child_table_list") != null) { List> childList = uniqueModel.getChildMap(); String finalValue = value; for (int j = 0; j < childList.size(); j++) { Map t = childList.get(j); if (finalValue.equals(t.get(swapDataVo.getVModel()))) { comInputError = true; errList.set(i, label + "值已存在"); uniqueModel.setChildIndex(j); break; } } } } //验证正则 if (StringUtil.isNotEmpty(swapDataVo.getConfig().getRegList())) { List regList = JsonUtil.getJsonToList(swapDataVo.getConfig().getRegList(), RegListModel.class); for (RegListModel regListModel : regList) { //处理正则格式 String reg = regListModel.getPattern(); if (reg.startsWith("/") && reg.endsWith("/")) { reg = reg.substring(1, reg.length() - 1); } boolean matches = value.matches(reg); if (!matches) { comInputError = true; errList.set(i, label + regListModel.getMessage()); } } } if (!comInputError) { insMap.put(swapDataVo.getVModel(), value); } } break; case JnpfKeyConsts.TIME: //格式 String dataFomrat = "yyyy-MM-dd " + swapDataVo.getFormat(); String valueTime = DateUtil.daFormat(new Date()) + " " + value; try { if (swapDataVo.getFormat().length() != value.length()) throw new DataException(); SimpleDateFormat formatter = new SimpleDateFormat(dataFomrat); formatter.setLenient(false); Date d = formatter.parse(valueTime); } catch (Exception e) { errList.set(i, label + "值不正确"); break; } //范围 try { //判断时间是否在设置范围内 boolean timeHasRangeError = FormPublicUtils.dateTimeCondition(swapDataVo, dataFomrat, valueTime, data, jnpfKey); if (timeHasRangeError) { errList.set(i, label + "值不在范围内"); break; } } catch (Exception e) { errList.set(i, label + "值不在范围内"); break; } break; case JnpfKeyConsts.DATE: case JnpfKeyConsts.DATE_CALCULATE: String format = swapDataVo.getFormat(); Date valueDate = null; try { if (format.length() != value.length()) throw new DataException(); SimpleDateFormat formatter = new SimpleDateFormat(format); formatter.setLenient(false); valueDate = formatter.parse(value); } catch (Exception e) { errList.set(i, label + "值不正确"); break; } try { //判断时间是否在设置范围内 boolean timeHasRangeError = FormPublicUtils.dateTimeCondition(swapDataVo, format, value, data, jnpfKey); if (timeHasRangeError) { errList.set(i, label + "值不在范围内"); break; } } catch (Exception e) { errList.set(i, label + "值不在范围内"); break; } insMap.put(swapDataVo.getVModel(), valueDate.getTime()); break; /** * 子表 */ case JnpfKeyConsts.CHILD_TABLE: StringJoiner childJoiner = new StringJoiner(","); List> childAllData = (List>) data.get(swapDataVo.getVModel()); List> childTable = new ArrayList<>(childAllData.size()); uniqueModel.setChildMap(new ArrayList<>()); //子表条数限制 if (swapDataVo.getIsNumLimit() && childAllData.size() > swapDataVo.getNumLimit()) { errList.set(i, MsgCode.VS033.get(swapDataVo.getConfig().getLabel())); continue; } for (int childI = 0, childLen = childAllData.size(); childI < childLen; childI++) { Map item = childAllData.get(childI); Map childMap = new HashMap<>(item); childMap.put("mainAndMast", data); childMap.put("child_table_list", data.get(swapDataVo.getVModel())); Map childTableMap = new HashMap<>(childMap); Map childerrorMap = new HashMap<>(childMap); uniqueModel.setMain(false); StringJoiner childJoiner1 = new StringJoiner(","); List childErrList = this.checkExcelData(swapDataVo.getConfig().getChildren(), childMap, localCache, childTableMap, childerrorMap, uniqueModel); childErrList.stream().forEach(t -> { if (StringUtil.isNotEmpty(t)) { childJoiner1.add(t); } }); List> childList = uniqueModel.getChildMap(); if (childJoiner1.length() > 0) { if (uniqueModel.isUpdate() && uniqueModel.getChildIndex() != null && childJoiner1.toString().split(",").length == 1 && childJoiner1.toString().contains("值已存在")) { childList.set(uniqueModel.getChildIndex(), childTableMap); } else { childJoiner.add(childJoiner1.toString()); } } else { childList.add(childTableMap); childTable.add(childTableMap); } } if (childJoiner.length() == 0) { insMap.put(swapDataVo.getVModel(), childTable); } else { errList.set(i, childJoiner.toString()); } uniqueModel.setMain(true); break; default: break; } /** * 数据接口 */ if (dataType != null) { List> options = new ArrayList<>(); String dataLabel = swapDataVo.getProps().getLabel() != null ? swapDataVo.getProps().getLabel() : ""; String dataValue = swapDataVo.getProps().getValue() != null ? swapDataVo.getProps().getValue() : ""; String children = swapDataVo.getProps().getChildren() != null ? swapDataVo.getProps().getChildren() : ""; boolean isCascader = JnpfKeyConsts.CASCADER.equals(jnpfKey); String localCacheKey; Map dataInterfaceMap = new HashMap<>(); //静态数据 if (dataType.equals(OnlineDataTypeEnum.STATIC.getType())) { localCacheKey = String.format("%s-%s", swapDataVo.getConfig().getRelationTable() + swapDataVo.getVModel(), OnlineDataTypeEnum.STATIC.getType()); if (!localCache.containsKey(localCacheKey)) { if (swapDataVo.getOptions() != null) { options = JsonUtil.getJsonToListMap(swapDataVo.getOptions()); String Children = swapDataVo.getProps().getChildren(); JSONArray staticData = JsonUtil.getListToJsonArray(options); OnlineSwapDataUtils.getOptions(dataLabel, dataValue, Children, staticData, options); } else { options = JsonUtil.getJsonToListMap(swapDataVo.getOptions()); } Map finalDataInterfaceMap = new HashMap<>(16); String finalDataLabel = dataLabel; String finalDataValue = dataValue; options.stream().forEach(o -> { finalDataInterfaceMap.put(String.valueOf(o.get(finalDataLabel)), o.get(finalDataValue)); }); localCache.put(localCacheKey, finalDataInterfaceMap); dataInterfaceMap = finalDataInterfaceMap; } else { dataInterfaceMap = (Map) localCache.get(localCacheKey); } checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, dataInterfaceMap, valueList, errList, i, isCascader); //远端数据 } else if (dataType.equals(OnlineDataTypeEnum.DYNAMIC.getType())) { localCacheKey = String.format("%s-%s-%s-%s", OnlineDataTypeEnum.DYNAMIC.getType(), swapDataVo.getConfig().getPropsUrl(), dataValue, dataLabel); if (!localCache.containsKey(localCacheKey)) { List templateJson = swapDataVo.getConfig().getTemplateJson(); Map param = new HashMap<>(); for (TemplateJsonModel tm : templateJson) { param.put(tm.getField(), tm.getDefaultValue()); } ActionResult actionResult = dataInterFaceApi.infoToIdById(swapDataVo.getConfig().getPropsUrl(), param); if (actionResult != null && actionResult.getData() != null) { List> dycDataList = new ArrayList<>(); if (actionResult.getData() instanceof List) { dycDataList = (List>) actionResult.getData(); } JSONArray dataAll = JsonUtil.getListToJsonArray(dycDataList); OnlineSwapDataUtils.treeToList(dataLabel, dataValue, children, dataAll, options); Map finalDataInterfaceMap1 = new HashMap<>(16); String finalDataLabel2 = dataLabel; String finalDataValue1 = dataValue; options.stream().forEach(o -> { finalDataInterfaceMap1.put(String.valueOf(o.get(finalDataLabel2)), String.valueOf(o.get(finalDataValue1))); }); dataInterfaceMap = finalDataInterfaceMap1; localCache.put(localCacheKey, dataInterfaceMap); } } else { dataInterfaceMap = (Map) localCache.get(localCacheKey); } checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, dataInterfaceMap, valueList, errList, i, isCascader); //数据字典 } else if (dataType.equals(OnlineDataTypeEnum.DICTIONARY.getType())) { localCacheKey = String.format("%s-%s", OnlineDataTypeEnum.DICTIONARY.getType(), swapDataVo.getConfig().getDictionaryType()); dataLabel = swapDataVo.getProps().getLabel(); dataValue = swapDataVo.getProps().getValue(); if (!localCache.containsKey(localCacheKey)) { List list = dictionaryDataApi.getDicList(swapDataVo.getConfig().getDictionaryType()); options = list.stream().map(dic -> { Map dictionaryMap = new HashMap<>(16); dictionaryMap.put("id", dic.getId()); dictionaryMap.put("enCode", dic.getEnCode()); dictionaryMap.put("fullName", dic.getFullName()); return dictionaryMap; }).collect(Collectors.toList()); localCache.put(localCacheKey, options); } else { options = (List>) localCache.get(localCacheKey); } Map finalDataInterfaceMap1 = new HashMap<>(16); String finalDataLabel3 = dataLabel; String finalDataValue3 = dataValue; options.stream().forEach(o -> finalDataInterfaceMap1.put(String.valueOf(o.get(finalDataLabel3)), o.get(finalDataValue3))); checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, finalDataInterfaceMap1, valueList, errList, i, isCascader); } } } catch (Exception e) { e.printStackTrace(); errList.set(i, e.getMessage()); } } localCache.put("allTypeMap", allTypeMap); } catch (Exception e) { throw new RuntimeException(e); } return errList; } //处理自定义范围:系统参数及、选中组织、选中组织及子组织、选中组织及子孙组织、 public OnlineCusCheckModel getSystemParamIds(List ableList, Map> allTypeMap, String jnpfKey) { UserInfo userInfo = UserProvider.getUser(); OnlineCusCheckModel cusCheckModel = new OnlineCusCheckModel(); for (String item : ableList) { List itemList = new ArrayList<>(); if (DataInterfaceVarConst.ORG.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item)); } else { itemList = userInfo.getOrganizeIds(); allTypeMap.put(item, itemList); cusCheckModel.getAbleComIds().addAll(itemList); } } else if (DataInterfaceVarConst.ORGANDSUB.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = organizeApi.getListByParentIds(userInfo.getOrganizeIds()); itemList.addAll(userInfo.getOrganizeIds()); itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAbleComIds().addAll(itemList); } } else if (DataInterfaceVarConst.ORGANIZEANDPROGENY.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = organizeApi.getProgeny(userInfo.getOrganizeIds(), null); itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAbleComIds().addAll(itemList); } } else if (DataInterfaceVarConst.POSITIONID.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item)); } else { itemList = userInfo.getPositionIds(); allTypeMap.put(item, itemList); cusCheckModel.getAblePosIds().addAll(itemList); } } else if (DataInterfaceVarConst.POSITIONANDSUB.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = positionApi.getListByParentIds(userInfo.getPositionIds()); itemList.addAll(userInfo.getOrganizeIds()); itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAblePosIds().addAll(itemList); } } else if (DataInterfaceVarConst.POSITIONANDPROGENY.equals(item)) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = positionApi.getProgeny(userInfo.getPositionIds(), null); itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAblePosIds().addAll(itemList); } } else if (DataInterfaceVarConst.USER.equals(item)) { cusCheckModel.getAbleUserIds().add(userInfo.getUserId()); } else { String[] split = item.split("--"); if (split.length > 1) { if (SysParamEnum.ORG.getCode().equalsIgnoreCase(split[1])) { cusCheckModel.getAbleComIds().add(split[0]); } else if (SysParamEnum.SUBORG.getCode().equalsIgnoreCase(split[1])) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = organizeApi.getListByParentIds(Arrays.asList(split[0])); itemList.add(split[0]); itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); List listByOrgIds = positionApi.getListByOrgIds(itemList); itemList.addAll(listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); allTypeMap.put(item, itemList); cusCheckModel.getAbleComIds().addAll(itemList); } } else if (SysParamEnum.PROGENYORG.getCode().equalsIgnoreCase(split[1])) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = organizeApi.getProgeny(Arrays.asList(split[0]), null); itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); List listByOrgIds = positionApi.getListByOrgIds(itemList); itemList.addAll(listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAbleComIds().addAll(itemList); } } else if (SysParamEnum.POS.getCode().equalsIgnoreCase(split[1])) { cusCheckModel.getAblePosIds().add(split[0]); } else if (SysParamEnum.SUBPOS.getCode().equalsIgnoreCase(split[1])) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = positionApi.getListByParentIds(Arrays.asList(split[0])); itemList.addAll(Arrays.asList(split[0])); itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAblePosIds().addAll(itemList); } } else if (SysParamEnum.PROGENYPOS.getCode().equalsIgnoreCase(split[1])) { if (allTypeMap.containsKey(item)) { cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item)); } else { List listByParentIds = positionApi.getProgeny(Arrays.asList(split[0]), null); itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); allTypeMap.put(item, itemList); cusCheckModel.getAblePosIds().addAll(itemList); } } else if (SysParamEnum.ROLE.getCode().equalsIgnoreCase(split[1])) { cusCheckModel.getAbleRoleIds().add(split[0]); } else if (SysParamEnum.GROUP.getCode().equalsIgnoreCase(split[1])) { cusCheckModel.getAbleGroupIds().add(split[0]); } else if (SysParamEnum.USER.getCode().equalsIgnoreCase(split[1])) { cusCheckModel.getAbleUserIds().add(split[0]); } } else { if (JnpfKeyConsts.COMSELECT.equalsIgnoreCase(jnpfKey)) { cusCheckModel.getAbleComIds().add(item); } if (JnpfKeyConsts.ROLESELECT.equalsIgnoreCase(jnpfKey)) { cusCheckModel.getAbleRoleIds().add(item); } if (JnpfKeyConsts.GROUPSELECT.equalsIgnoreCase(jnpfKey)) { cusCheckModel.getAbleGroupIds().add(item); } if (JnpfKeyConsts.USERSELECT.equalsIgnoreCase(jnpfKey) || JnpfKeyConsts.CUSTOMUSERSELECT.equalsIgnoreCase(jnpfKey)) { cusCheckModel.getAbleUserIds().add(item); } } } } return cusCheckModel; } public void checkCustomControl(OnlineCusCheckModel cusCheckModel, List errList, int i, String label) { boolean contains; List ableIdsAll = new ArrayList<>(); List ableDepIds = cusCheckModel.getAbleDepIds(); List ableGroupIds = cusCheckModel.getAbleGroupIds(); List ablePosIds = cusCheckModel.getAblePosIds(); List ableRoleIds = cusCheckModel.getAbleRoleIds(); List ableUserIds = cusCheckModel.getAbleUserIds(); List ableComIds = cusCheckModel.getAbleComIds(); // List ableComIdsStr = cusCheckModel.getAbleComIdsStr(); List dataList = cusCheckModel.getDataList(); String controlType = cusCheckModel.getControlType(); switch (controlType) { case JnpfKeyConsts.GROUPSELECT: ableIdsAll.addAll(ableGroupIds); break; case JnpfKeyConsts.ROLESELECT: ableIdsAll.addAll(ableRoleIds); break; case JnpfKeyConsts.DEPSELECT: ableIdsAll.addAll(ableDepIds); break; case JnpfKeyConsts.COMSELECT: ableIdsAll.addAll(ableComIds); break; case JnpfKeyConsts.CUSTOMUSERSELECT: for (String id : ableGroupIds) { ableIdsAll.add(id + "--group"); } for (String id : ablePosIds) { ableIdsAll.add(id + "--pos"); } for (String id : ableRoleIds) { ableIdsAll.add(id + "--role"); } for (String id : ableUserIds) { ableIdsAll.add(id + "--user"); } for (String id : ableComIds) { ableIdsAll.add(id + "--org"); } ableIdsAll.addAll(ableDepIds); ableIdsAll.addAll(ableGroupIds); ableIdsAll.addAll(ablePosIds); ableIdsAll.addAll(ableRoleIds); ableIdsAll.addAll(ableUserIds); ableIdsAll.addAll(ableComIds); List listByObjectIdAll = userRelationApi.getListByObjectIdAll(ableIdsAll); for (UserRelationEntity userRelationEntity : listByObjectIdAll) { ableIdsAll.add(userRelationEntity.getUserId() + "--user"); } break; case JnpfKeyConsts.USERSELECT: List objIds = new ArrayList<>(); if (ableComIds.size() > 0) { List lastIds = new ArrayList<>(); for (String str : ableComIds) { lastIds.add(str); } objIds.addAll(lastIds); } if (ableDepIds.size() > 0) { List lastIds = new ArrayList<>(); for (String str : ableDepIds) { lastIds.add(str); } objIds.addAll(lastIds); } if (ableGroupIds.size() > 0) { objIds.addAll(ableGroupIds); } if (ablePosIds.size() > 0) { objIds.addAll(ablePosIds); } if (ableRoleIds.size() > 0) { objIds.addAll(ableRoleIds); } List UserIds = userRelationApi.getListByObjectIdAll(objIds).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); UserIds.addAll(ableUserIds); ableIdsAll.addAll(UserIds); break; case JnpfKeyConsts.POSSELECT: List posIds = new ArrayList<>(); if (ableDepIds.size() > 0) { List depIds = positionApi.getListByOrganizeId(ableDepIds).stream().map(PositionEntity::getId).collect(Collectors.toList()); posIds.addAll(depIds); } if (ablePosIds.size() > 0) { posIds.addAll(ablePosIds); } ableIdsAll.addAll(posIds); break; default: break; } if (ableIdsAll.size() > 0) { for (String id : dataList) { contains = ableIdsAll.contains(id); if (!contains) { errList.set(i, label + "值不在范围内"); break; } } } } public List checkOptionsControl(boolean multiple, Map insMap, String vModel, String label, Map cacheMap, List valueList, List errList, int i) { boolean error = false; if (!multiple) { //非多选填入多选值 if (valueList.size() > 1) { error = true; errList.set(i, label + "值不正确"); } } List dataList = new ArrayList<>(); if (!error) { boolean errorHapen = false; for (String va : valueList) { if (StringUtil.isEmpty(va)) { errorHapen = true; break; } Object vo = cacheMap.get(va); if (vo == null) { errorHapen = true; break; } else { dataList.add(vo.toString()); } } if (errorHapen) { errList.set(i, label + "值不正确"); } else { insMap.put(vModel, !multiple ? dataList.get(0) : JsonUtil.getObjectToString(dataList)); } } return dataList; } public void checkFormDataInteface(boolean multiple, Map insMap, String vModel, String label, Map cacheMap, List valueList, List errList, int i, boolean isCascader) { List staticStrData = new ArrayList<>(); List staticStrDataList1 = new ArrayList<>(); //单选给多选直接报错 if (!multiple && valueList.size() > 1) { errList.set(i, label + "值不正确"); return; } boolean hasError = false; boolean takeOne = false; for (String dicValue : valueList) { if (isCascader) { List staticStrDataList2 = new ArrayList<>(); if (!multiple && valueList.size() > 1) hasError = true; if (dicValue.contains("/")) { String[] split = dicValue.split("/"); for (String s : split) { Object s1 = cacheMap.get(s); if (s1 != null) { staticStrDataList2.add(s1.toString()); staticStrDataList1.add(s1.toString()); } else { hasError = true; } } staticStrData.add(staticStrDataList2.toArray(new String[staticStrDataList2.size()])); } else { if (cacheMap.get(dicValue) == null) { hasError = true; } else { staticStrDataList1.add(cacheMap.get(dicValue).toString()); staticStrData.add(new String[]{cacheMap.get(dicValue).toString()}); } } } else { takeOne = true; Object s1 = cacheMap.get(dicValue); if (s1 != null) { staticStrDataList1.add(s1.toString()); } else { hasError = true; } } } if (hasError) { errList.set(i, label + "值不正确"); } else { String v = multiple ? takeOne ? JsonUtil.getObjectToString(staticStrDataList1) : JsonUtil.getObjectToString(staticStrData) : takeOne ? staticStrDataList1.get(0) : JsonUtil.getObjectToString(staticStrDataList1); insMap.put(vModel, v); } } }