1.导出实现类
package com.dst.steed.fulfillment.modules.business.resourceplan.serviceimport;import com.alibaba.excel.EasyExcelFactory;
import com.dst.steed.common.domain.response.Response;
import com.dst.steed.common.util.*;
import com.dst.steed.fulfillment.common.constant.DictTypeConstant;
import com.dst.steed.fulfillment.common.constant.vehicle.VehicleAttributeConstant;
import com.dst.steed.fulfillment.common.domain.acl.vehicle.attribute.AttributeValueInherit;
import com.dst.steed.fulfillment.common.domain.acl.vehicle.attribute.AttributeValueOut;
import com.dst.steed.fulfillment.common.domain.biz.resourceplan.InsertSituationRequireImportEO;
import com.dst.steed.fulfillment.common.domain.biz.resourceplan.InsertSituationRequireImportMap;
import com.dst.steed.fulfillment.common.domain.biz.resourceplan.ResourcePlanResult;
import com.dst.steed.fulfillment.common.domain.biz.resourceplan.inner.ResourceSituationInsertInnerDTO;
import com.dst.steed.fulfillment.common.enums.resourceplan.ResourceSituationSourceEnum;
import com.dst.steed.fulfillment.common.enums.resourceplan.ResourceSituationStatusEnum;
import com.dst.steed.fulfillment.common.enums.resourceplan.ResourceSituationTypeEnum;
import com.dst.steed.fulfillment.common.utils.CodeUtils;
import com.dst.steed.fulfillment.common.utils.string.StringUtil;
import com.dst.steed.fulfillment.infrastructure.acl.goods.AttributeValueServiceImpl;
import com.dst.steed.fulfillment.infrastructure.acl.goods.api.GoodsCenterServiceImpl;
import com.dst.steed.fulfillment.infrastructure.acl.operatecore.DictServiceImpl;
import com.dst.steed.fulfillment.infrastructure.acl.org.OrgServiceImpl;
import com.dst.steed.fulfillment.infrastructure.biz.resourceplan.entity.ReplaceModel;
import com.dst.steed.fulfillment.infrastructure.biz.resourceplan.entity.ResourceSituation;
import com.dst.steed.fulfillment.infrastructure.biz.resourceplan.entity.SituationRequire;
import com.dst.steed.fulfillment.infrastructure.core.resourceplan.ResourceSituationCoreService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;import java.util.*;
import java.util.stream.Collectors;/*** 月资源计划-新增资源需求导入业务类*/
@Slf4j
@Service
public class InsertSituationRequireImportService {@Autowiredprivate ResourceSituationCoreService resourceSituationCoreService;@Autowiredprivate AttributeValueServiceImpl attributeValueService;@Autowiredprivate OrgServiceImpl orgService;@Autowiredprivate DictServiceImpl dictService;@Autowiredprivate GoodsCenterServiceImpl goodsCenterService;@Autowiredprivate CodeUtils codeUtils;private final static String YYYY_MM_DD = "yyyy/mm/dd";/*** 月资源计划-新增资源需求导入* @param file* @return*/public Response importInsertSituationRequireTemplate(MultipartFile file,String regionCode,String beginTime,String endTime) {if (null == file || file.isEmpty()) {return Response.error("参数验证不通过");}try{List<InsertSituationRequireImportEO> eoList = EasyExcelFactory.read(file.getInputStream()).sheet(0).headRowNumber(2).head(InsertSituationRequireImportEO.class).doReadSync();if (CollectionUtils.isEmpty(eoList) || eoList.size() < 1) {return Response.error("导入数据为空");}if(eoList.size() > 1000) {return Response.error("导入的数量不能超过1000条!");}InsertSituationRequireImportMap importMap = initImportMap(eoList);List<ResourcePlanResult> validateResults = validateImport(eoList,regionCode,importMap);if(!CollectionUtils.isEmpty(validateResults)){return Response.succeed(validateResults);}//转换对应实体packResourceSituationList(eoList,importMap,beginTime,endTime);return Response.succeed();} catch (Exception e) {log.error("资源计划-新增资源需求导入错误", e);}return Response.error("导入失败");}private InsertSituationRequireImportMap initImportMap(List<InsertSituationRequireImportEO> eoList) {InsertSituationRequireImportMap importMap = new InsertSituationRequireImportMap();//城市名称和编码List<String> cityNames = eoList.stream().filter(e -> StringUtil.isNotNullorEmpty(e.getCityName())).map(InsertSituationRequireImportEO::getCityName).distinct().collect(Collectors.toList());Map<String, String> cityMap = orgService.getCityMap(cityNames);importMap.setCityMap(cityMap);//高中低顶要求Map<String, String> topRequireMap = dictService.getDictNameValueMapByType(DictTypeConstant.BUSINESS_RESOURCE_PLAN_TOP_REQUIRE);importMap.setTopRequireMap(topRequireMap);//车辆性质Map<String, String> carNoNatureMap = dictService.getDictNameValueMapByType(DictTypeConstant.BUSINESS_CARNO_NATURE);importMap.setCarNoNatureMap(carNoNatureMap);//是否可替换(0 否 1 是 )Map<String, String> canReplaceCarModelMap = new HashMap<>();canReplaceCarModelMap.put("否","0");canReplaceCarModelMap.put("是","1");importMap.setCanReplaceCarModelMap(canReplaceCarModelMap);return importMap;}private Boolean packResourceSituationList(List<InsertSituationRequireImportEO> eoList,InsertSituationRequireImportMap importMap,String beginTime,String endTime) {if (!CollectionUtils.isEmpty(eoList)) {List<SituationRequire> situationRequires = new ArrayList<>();List<ResourceSituation> resourceSituations = new ArrayList<>();for (InsertSituationRequireImportEO eo : eoList) {String situationResourceId = DstIdUtil.stringId();SituationRequire situationRequire = new SituationRequire();situationRequire.setId(situationResourceId);DstBeanUtil.copy(eo, situationRequire);situationRequire.setRequireSource(ResourceSituationSourceEnum.HANDLER_ADD.getSource());situationRequire.setReplaceModel(eo.getReplaceModel());if (StringUtil.isNotNullorEmpty(eo.getLastDeliverTime())) {situationRequire.setLastDeliverTime(DstDateUtil.parse(eo.getLastDeliverTime(), YYYY_MM_DD));}situationRequire.setCreatorId((DstUserUtil.getUserId().isPresent()) ? String.valueOf(DstUserUtil.getUserId().get()): String.valueOf(DstUserUtil.ADMIN_ID));situationRequire.setCreatorName((DstUserUtil.getRealName().isPresent()) ? DstUserUtil.getRealName().get(): DstUserUtil.ADMIN_REAL_NAME);situationRequires.add(situationRequire);// 资源情况ResourceSituation resourceSituation = new ResourceSituation();resourceSituation.setId(DstIdUtil.stringId());resourceSituation.setResourceSituationCode(codeUtils.generateResourceSituationCode(ResourceSituationTypeEnum.MONTH));resourceSituation.setSituationRequireId(situationResourceId);resourceSituation.setCityCode(eo.getCityCode());resourceSituation.setBeginTime(DstDateUtil.parse(beginTime,DstDateUtil.Y_M_D));resourceSituation.setEndTime(DstDateUtil.parse(endTime,DstDateUtil.Y_M_D));resourceSituation.setType(ResourceSituationTypeEnum.MONTH.getType());resourceSituation.setStatus(ResourceSituationStatusEnum.MONTH_WAIT_CITY_DECISION.getStatus());resourceSituation.setCreatorId((DstUserUtil.getUserId().isPresent()) ? String.valueOf(DstUserUtil.getUserId().get()): String.valueOf(DstUserUtil.ADMIN_ID));resourceSituation.setCreatorName((DstUserUtil.getRealName().isPresent()) ? DstUserUtil.getRealName().get(): DstUserUtil.ADMIN_REAL_NAME);resourceSituations.add(resourceSituation);}if (!CollectionUtils.isEmpty(situationRequires) && !CollectionUtils.isEmpty(situationRequires)) {resourceSituationCoreService.batchSaveSituationInsertInnerDTO(new ResourceSituationInsertInnerDTO(resourceSituations,null,situationRequires));return true;}}return false;}/*** 校验导入信息* @param eoList* @return*/private List<ResourcePlanResult> validateImport(List<InsertSituationRequireImportEO> eoList,String regionCode,InsertSituationRequireImportMap importMap) {List<ResourcePlanResult> validateResults = new ArrayList<>();Set<String> insertSituationRequireSet = new HashSet<>();Map<String, List<AttributeValueOut>> valueMap = attributeValueService.getAttrValueMapByAttrKeys(VehicleAttributeConstant.exportAttrKey);List<AttributeValueInherit> attrValueInheritList = goodsCenterService.getAttrValueInheritList();List<String> cityCodesByRegionCode = orgService.getCityCodesByRegionCode(regionCode);for (int i = 0; i < eoList.size() ; i++) {StringBuffer lineError = new StringBuffer();int lineNum = i + 3;InsertSituationRequireImportEO data = eoList.get(i);//非空校验validateImportIsNull(data, lineNum, lineError);//字典值校验validateDict(data,lineNum,lineError,importMap,cityCodesByRegionCode);//属性值校验validateAttrValue(data,lineNum,lineError,valueMap,attrValueInheritList);//校验唯一性validateUnique(data,lineNum,lineError,insertSituationRequireSet);if(lineError.length() > 0){validateResults.add(new ResourcePlanResult(String.format("第%d行",lineNum),lineError.toString()));}}return validateResults;}/*** 校验唯一性* @param data* @param lineNum* @param lineError* @param insertSituationRequireSet*/private void validateUnique(InsertSituationRequireImportEO data, int lineNum, StringBuffer lineError, Set<String> insertSituationRequireSet) {if (insertSituationRequireSet.contains(DstJsonUtil.toString(data))) {lineError.append(String.format("第%d行表格中不能有完全重复的数据!",lineNum));}insertSituationRequireSet.add(DstJsonUtil.toString(data));}/*** 属性值校验* @param data* @param lineNum* @param lineError* @param valueMap*/private void validateAttrValue(InsertSituationRequireImportEO data, int lineNum, StringBuffer lineError, Map<String, List<AttributeValueOut>> valueMap,List<AttributeValueInherit> attrValueInheritList) {if (StringUtil.isNotNullorEmpty(data.getCarBrandName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_G_CAR_BRAND, data.getCarBrandName());String valueId = attrValueMapByAttrKeyMap.get(data.getCarBrandName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【车辆品牌】【%s】在系统中不存在的属性值!",lineNum,data.getCarBrandName()));} else {data.setCarBrand(valueId);}}if (StringUtil.isNotNullorEmpty(data.getCarModelName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_G_CAR_MODEL, data.getCarModelName());String valueId = attrValueMapByAttrKeyMap.get(data.getCarModelName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【车辆型号】【%s】在系统中不存在的属性值!",lineNum,data.getCarModelName()));} else {data.setCarModel(valueId);}}if (StringUtil.isNotNullorEmpty(data.getCarBrandName()) && StringUtil.isNotNullorEmpty(data.getCarModelName())){if (!goodsCenterService.checkBranAndModeInherit(attrValueInheritList,data.getCarBrandName(),data.getCarModelName())) {lineError.append(String.format("第%d行【车辆品牌-型号】【%s】【%s】只可填写车辆品牌下的型号!",lineNum,data.getCarBrandName(),data.getCarModelName()));}}if (StringUtil.isNotNullorEmpty(data.getCarModelGroupName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_A_CAR_MODEL_GROUP, data.getCarModelGroupName());String valueId = attrValueMapByAttrKeyMap.get(data.getCarModelGroupName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【车辆族群】【%s】在系统中不存在的属性值!",lineNum,data.getCarModelGroupName()));} else {data.setCarModelGroup(valueId);}}if (StringUtil.isNotNullorEmpty(data.getEsdTotalPowerName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_A_ESD_TOTAL_POWER, data.getEsdTotalPowerName());String valueId = attrValueMapByAttrKeyMap.get(data.getEsdTotalPowerName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【电池包度数】【%s】在系统中不存在的属性值!",lineNum,data.getEsdTotalPowerName()));} else {data.setEsdTotalPower(valueId);}}if (StringUtil.isNotNullorEmpty(data.getEsdCompanyName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_A_ESD_COMPANY, data.getEsdCompanyName());String valueId = attrValueMapByAttrKeyMap.get(data.getEsdCompanyName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【电池包厂商】【%s】在系统中不存在的属性值!",lineNum,data.getEsdCompanyName()));} else {data.setEsdCompany(valueId);}}if (StringUtil.isNotNullorEmpty(data.getVehicleUseName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.A_OPT_VEHICLE_USE, data.getVehicleUseName());String valueId = attrValueMapByAttrKeyMap.get(data.getVehicleUseName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【车辆用途】【%s】在系统中不存在的属性值!",lineNum,data.getVehicleUseName()));} else {data.setVehicleUse(valueId);}}if (StringUtil.isNotNullorEmpty(data.getAssetClassifyName())) {Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.A_OPT_ASSET_CLASSIFY, data.getAssetClassifyName());String valueId = attrValueMapByAttrKeyMap.get(data.getAssetClassifyName());if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【资产分类】【%s】在系统中不存在的属性值!",lineNum,data.getAssetClassifyName()));} else {data.setAssetClassify(valueId);}}if (StringUtil.isNotNullorEmpty(data.getReplaceCarModelMame())) {try {List<ReplaceModel> replaceModels = new ArrayList<>();String[] brandAndMode = data.getReplaceCarModelMame().split("、");for (String item : brandAndMode) {String[] brandAndModeSplit = item.split("/");String brand = brandAndModeSplit[0];String model = brandAndModeSplit[1];ReplaceModel replaceModel = new ReplaceModel();Map<String, String> attrBrandValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_G_CAR_BRAND, brand);String valueId = attrBrandValueMapByAttrKeyMap.get(brand);if (StringUtil.isBlank(valueId)) {lineError.append(String.format("第%d行【替换车型-车辆品牌】【%s】在系统中不存在的属性值!", lineNum, brand));} else {replaceModel.setBrandId(valueId);replaceModel.setBrandName(brand);}Map<String, String> attrValueMapByAttrKeyMap = attributeValueService.getAttrValueMapByAttrKeyMap(valueMap, VehicleAttributeConstant.AK_G_CAR_MODEL, model);String modelValueId = attrValueMapByAttrKeyMap.get(model);if (StringUtil.isBlank(modelValueId)) {lineError.append(String.format("第%d行【替换车型-车辆型号】【%s】在系统中不存在的属性值!", lineNum, model));} else {replaceModel.setModelId(modelValueId);replaceModel.setModelName(model);}if (StringUtil.isNotNullorEmpty(brand) && StringUtil.isNotNullorEmpty(model)){if (!goodsCenterService.checkBranAndModeInherit(attrValueInheritList,brand,model)) {lineError.append(String.format("第%d行【替换车型-车辆品牌-型号】【%s】【%s】只可填写车辆品牌下的型号!",lineNum,brand,model));}}replaceModels.add(replaceModel);}data.setReplaceModel(replaceModels);} catch (Exception e) {log.error(String.format("替换车型%s输入有误",data.getReplaceCarModelMame()));lineError.append(String.format("第%d行【替换车型】【%s】输入有误,请检查!", lineNum, data.getReplaceCarModelMame()));}}}private void validateImportIsNull(InsertSituationRequireImportEO data, int lineNum, StringBuffer lineError) {if (StringUtil.isBlank(data.getCityName())) {lineError.append(String.format("第%d行【城市】为空!",lineNum));}if(StringUtils.isBlank(data.getCarBrandName())) {lineError.append(String.format("第%d行【车辆品牌】为空!",lineNum));}if(StringUtils.isBlank(data.getCarModelName())) {lineError.append(String.format("第%d行【车辆型号】为空!",lineNum));}if(StringUtils.isBlank(data.getCarModelGroupName())) {lineError.append(String.format("第%d行【车辆族群】为空!",lineNum));}if(StringUtils.isBlank(data.getCanReplaceCarModelMame())) {lineError.append(String.format("第%d行【是否可替换车型】为空!",lineNum));}else if (data.getCanReplaceCarModelMame().equals("是")) {if (StringUtil.isBlank(data.getReplaceCarModelMame())) {lineError.append(String.format("第%d行【可替换车型】是否可替换车型为是则为必填!",lineNum));}}if(StringUtils.isBlank(data.getCarNoNatureName())) {lineError.append(String.format("第%d行【车牌性质】为空!",lineNum));}if (!StringUtil.isBlank(data.getLastDeliverTime())) {try {DstDateUtil.parse(data.getLastDeliverTime(), YYYY_MM_DD);} catch (Exception e) {log.error("时间格式解析异常:{}",e.getMessage());lineError.append(String.format("第%d行【最后交付时间】请输入yyyy/mm/dd格式",lineNum));}}if(Objects.isNull(data.getRequireVehicleCount())) {lineError.append(String.format("第%d行【需求数量】为空!",lineNum));} else if (data.getRequireVehicleCount() <=0 ){lineError.append(String.format("第%d行【需求数量】只可填写大于0的整数,最大可输入99999!",lineNum));}if (!StringUtil.isBlank(data.getNeedColor())) {if (data.getNeedColor().length() > 50) {lineError.append(String.format("第%d行【车身颜色】最多可填写50字符!", lineNum));}}if (!StringUtil.isBlank(data.getTransformRequire())) {if (data.getTransformRequire().length() > 50) {lineError.append(String.format("第%d行【技改要求】最多可填写50字符!", lineNum));}}}private void validateDict(InsertSituationRequireImportEO data, int lineNum, StringBuffer lineError,InsertSituationRequireImportMap importMap,List<String> cityCodesByRegionCode) {if (!importMap.getCityMap().containsKey(data.getCityName())) {lineError.append(String.format("第%d行 城市:【%s】输入有误,在系统不存在,请检查!", lineNum, data.getCityName()));} else {data.setCityCode(importMap.getCityMap().get(data.getCityName()));}if (!cityCodesByRegionCode.contains(data.getCityCode())) {lineError.append(String.format("第%d行【%s】只可填写当前大区下的城市!",lineNum,data.getCityName()));}if (StringUtil.isNotNullorEmpty(data.getTopRequireName())) {if (!importMap.getTopRequireMap().containsKey(data.getTopRequireName())) {lineError.append(String.format("第%d行 高中低顶要求:【%s】输入有误!", lineNum, data.getTopRequireName()));} else {data.setTopRequire(Integer.valueOf(importMap.getTopRequireMap().get(data.getTopRequireName())));}}if (!importMap.getCarNoNatureMap().containsKey(data.getCarNoNatureName())) {lineError.append(String.format("第%d行 车牌性质:【%s】输入有误!", lineNum, data.getCarNoNatureName()));} else {data.setCarNoNature(Integer.valueOf(importMap.getCarNoNatureMap().get(data.getCarNoNatureName())));}if (!importMap.getCanReplaceCarModelMap().containsKey(data.getCanReplaceCarModelMame())) {lineError.append(String.format("第%d行 是否可替换车型:【%s】输入有误!", lineNum, data.getCanReplaceCarModelMame()));} else {data.setCanReplaceCarModel(importMap.getCanReplaceCarModelMap().get(data.getCanReplaceCarModelMame()));}}}
2.导出异常信息类
package com.dst.steed.fulfillment.common.domain.biz.resourceplan;import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;/**
*@ClassName ResourcePlanResult
*@Description 资源计划导入结果类
*@Author lwp
*@Date 2024/3/6 14:09
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
public class ResourcePlanResult {/** 资源情况编码**/private String index;/** 错误信息**/private String message;public ResourcePlanResult(String index, String message) {this.index = index;this.message = message;}}
3.字段组装map类
package com.dst.steed.fulfillment.common.domain.biz.resourceplan;import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;import java.util.Map;/*** @Description: 月资源计划-新增资源需求导入常量透传类* @author lwp* @date 2024/3/7 18:06*/
@Getter
@Setter
@ToString
@NoArgsConstructor
public class InsertSituationRequireImportMap {/** 高低顶要求(dst_base.marketing_interior_height)**/private Map<String, String> topRequireMap;/** 车辆性质(dst_base.business_carno_nature)**/private Map<String, String> carNoNatureMap;/** 是否可替换(0 否 1 是 )**/private Map<String, String> canReplaceCarModelMap;/** 城市名称和编码 **/private Map<String, String> cityMap;}
4.导入类
package com.dst.steed.fulfillment.common.domain.biz.resourceplan;import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.dst.steed.common.convert.translation.Translation;
import com.dst.steed.fulfillment.common.constant.DictTypeConstant;
import com.dst.steed.fulfillment.infrastructure.biz.resourceplan.entity.ReplaceModel;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;import java.io.Serializable;
import java.util.List;/*** 月资源计划-新增资源需求导入类*/
@Data
public class InsertSituationRequireImportEO implements Serializable {/*** 资源情况编码*/@ExcelProperty(index = 0)private String cityName;private String cityCode;/*** 车辆品牌*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-carBrandName")private String carBrand;@ExcelProperty(index = 1)private String carBrandName;/*** 车辆型号*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-carModelName")private String carModel;@ExcelProperty(index = 2)private String carModelName;/*** 车型族群*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-carModelGroupName")private String carModelGroup;@ExcelProperty(index = 3)private String carModelGroupName;/*** 动力电池包电量*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-carModelGroupName")private String esdTotalPower;@ExcelProperty(index = 4)private String esdTotalPowerName;/*** 电池包厂商*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-esdCompanyName")private String esdCompany;@ExcelProperty(index = 5)private String esdCompanyName;/*** 车辆用途*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-vehicleUseName")private String vehicleUse;@ExcelProperty(index = 6)private String vehicleUseName;/*** 资产分类*/@Translation(convertName = "commonConvertAttrValueIdMapValue",convertTo = "attrValueName-assetClassifyName")private String assetClassify;@ExcelProperty(index = 7)private String assetClassifyName;/*** 高中低顶要求(字典:marketing_interior_height)*/@Translation(dictType = DictTypeConstant.BUSINESS_RESOURCE_PLAN_TOP_REQUIRE)private Integer topRequire;@ExcelProperty(index = 8)private String topRequireName;/*** 车身颜色要求*/@ExcelProperty(index = 9)private String needColor;/*** 技改要求*/@ExcelProperty(index = 10)private String transformRequire;/*** 是否可替换车型,0.不可替换 1.可替换*/@ExcelProperty(index = 11)private String canReplaceCarModelMame;private String canReplaceCarModel;/*** 替换车型*/@ExcelProperty(index = 12)private String replaceCarModelMame;/*** 车牌性质(字典:business_carno_nature)*/@Translation(dictType = DictTypeConstant.BUSINESS_CARNO_NATURE)private Integer carNoNature;@ExcelProperty(index = 13)private String carNoNatureName;/*** 最后交付时间*/@JsonFormat(pattern = "yyyy/MM/dd", timezone = "GMT+8")@ExcelProperty(index = 14)private String lastDeliverTime;/*** 需求数量*/@ExcelProperty(index = 15)private Integer requireVehicleCount;/*** 可替换车型(jons数组字符串)*/@TableField(value = "replace_model", typeHandler = JacksonTypeHandler.class)private List<ReplaceModel> replaceModel;
}
5.前端请求接口控制层
/*** 月资源计划-新增资源需求导入* @author: lwp* @date: 2024/03/04 13:50**/@PostMapping(value = "/importInsertSituationRequireTemplate")public Response importInsertSituationRequireTemplate(@RequestParam(value = "file",required = true) MultipartFile file,@RequestParam(value = "regionCode", required = true) String regionCode,@RequestParam(value = "beginTime", required = true) String beginTime,@RequestParam(value = "endTime", required = true) String endTime) {return situationRequireService.importInsertSituationRequireTemplate(file,regionCode,beginTime,endTime);
6.总结
这种写法主要是代码结构清晰,再复杂的校验只要往其中填充即可