| | |
| | | package com.java110.api.importData.adapt; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.api.components.ValueUtil; |
| | | import com.java110.api.importData.DefaultImportDataAdapt; |
| | | import com.java110.api.importData.IImportDataCleaningAdapt; |
| | | import com.java110.dto.community.CommunityDto; |
| | | import com.java110.dto.importData.Vtil; |
| | | import com.java110.dto.system.ComponentValidateResult; |
| | | import com.java110.intf.community.ICommunityInnerServiceSMO; |
| | | import com.java110.intf.community.IVisitInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerV1InnerServiceSMO; |
| | | import com.java110.po.car.CarInoutPo; |
| | | import com.java110.po.meter.MeterWaterPo; |
| | | import com.java110.po.owner.VisitPo; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import com.java110.utils.util.ImportExcelUtils; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service("ImportCarInoutDataCleaning") |
| | | @Service("importCarInoutDataCleaning") |
| | | public class ImportCarInoutDataCleaningAdapt extends DefaultImportDataAdapt implements IImportDataCleaningAdapt { |
| | | |
| | | @Autowired |
| | | private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private ICommunityInnerServiceSMO communityInnerServiceSMOImpl; |
| | | @Autowired |
| | | private IVisitInnerServiceSMO visitInnerServiceSMOImpl; |
| | | @Override |
| | |
| | | */ |
| | | private void getCarInouts(Workbook workbook, List<CarInoutPo> carInoutPos, ComponentValidateResult result) throws ParseException { |
| | | Sheet sheet = null; |
| | | sheet = ImportExcelUtils.getSheet(workbook, "临时停车费 导入模板"); |
| | | sheet = ImportExcelUtils.getSheet(workbook, "临时停车费模板"); |
| | | List<Object[]> oList = ImportExcelUtils.listFromSheet(sheet); |
| | | List<Map<String, Object>> maps = BeanConvertUtil.beanCovertMapListC(communityInnerServiceSMOImpl.queryCommunitys(new CommunityDto())); |
| | | for (int osIndex = 0; osIndex < oList.size(); osIndex++) { |
| | | Object[] os = oList.get(osIndex); |
| | | if (osIndex <= 2) { // 第一行是 头部信息 直接跳过 |
| | | if (osIndex <= 1) { // 第一行是 头部信息 直接跳过 |
| | | continue; |
| | | } |
| | | Assert.hasValue(os[1], (osIndex + 1) + "行小区编码不能为空"); |
| | | Assert.hasValue(os[3], (osIndex + 1) + "行车牌号码不能为空"); |
| | | Assert.hasValue(os[6], (osIndex + 1) + "行到访日期不能为空"); |
| | | if (Vtil.defaultValue(os[0], null) == null) { |
| | | continue; |
| | | } |
| | | if (Vtil.defaultValue(os[3], null) == null) { |
| | | os[3] = "A888888"; |
| | | } |
| | | // Assert.hasValue(os[6], (osIndex + 1) + "行到访日期不能为空"); |
| | | Assert.hasValue(os[11], (osIndex + 1) + "行进场时间不能为空"); |
| | | |
| | | CarInoutPo carInoutPo = new CarInoutPo(); |
| | | carInoutPo.setCommunityCode(defaultValue(os[1])); |
| | | carInoutPo.setCarNum(defaultValue(os[3])); |
| | | carInoutPo.setVehicleType(defaultValue(os[5])); |
| | | VisitPo visitPo = new VisitPo(); |
| | | visitPo.setVisitTime(defaultValue(os[6])); |
| | | visitPo.setvName(defaultValue(os[7])); |
| | | visitPo.setPhoneNumber(defaultValue(os[8])); |
| | | visitPo.setCarNum(defaultValue(os[3])); |
| | | visitPo.setVisitCase(defaultValue(os[10])); |
| | | carInoutPo.setVisitPo(visitPo); |
| | | carInoutPo.setInTime(defaultValue(os[11])); |
| | | carInoutPo.setInAddress(defaultValue(os[12])); |
| | | carInoutPo.setOutTime(defaultValue(os[13])); |
| | | carInoutPo.setOutAddress(defaultValue(os[14])); |
| | | carInoutPo.setParkingDuration(defaultValue(os[15])); |
| | | carInoutPo.setPayDate(defaultValue(os[16])); |
| | | carInoutPo.setPaymentAmount(defaultValue(os[17])); |
| | | carInoutPo.setMerchantId(defaultValue(os[18])); |
| | | carInoutPo.setPayer(defaultValue(os[19])); |
| | | carInoutPo.setBankDepositDate(defaultValue(os[20])); |
| | | carInoutPo.setBankDepositor(defaultValue(os[21])); |
| | | try { |
| | | carInoutPo.setCommunityCode(defaultValue(os[1])); |
| | | carInoutPo.setCommunityName(defaultValue(os[2])); |
| | | setCommunityId(carInoutPo, os, maps); |
| | | carInoutPo.setCarNum(defaultValue(os[3])); |
| | | carInoutPo.setVehicleType(defaultValue(os[5])); |
| | | VisitPo visitPo = new VisitPo(); |
| | | visitPo.setVisitTime(Vtil.defaultValueToDate(defaultValue(os[6]))); |
| | | visitPo.setvName(defaultValue(os[7])); |
| | | visitPo.setPhoneNumber(defaultValue(os[8])); |
| | | visitPo.setCarNum(defaultValue(os[3])); |
| | | visitPo.setVisitCase(defaultValue(os[10])); |
| | | carInoutPo.setVisitPo(visitPo); |
| | | carInoutPo.setInTime(Vtil.defaultValueToDate(os[11])); |
| | | carInoutPo.setInAddress(defaultValue(os[12])); |
| | | carInoutPo.setOutTime(Vtil.defaultValueToDate(os[13])); |
| | | carInoutPo.setOutAddress(defaultValue(os[14])); |
| | | carInoutPo.setParkingDuration(defaultValue(os[15])); |
| | | carInoutPo.setPayDate(Vtil.defaultValueToDate(os[16])); |
| | | carInoutPo.setPaymentAmount(defaultValue(os[17])); |
| | | carInoutPo.setMerchantId(defaultValue(os[18])); |
| | | carInoutPo.setPayer(defaultValue(os[19])); |
| | | carInoutPo.setBankDepositDate(Vtil.defaultValueToDate(os[20])); |
| | | carInoutPo.setBankDepositor(defaultValue(os[21])); |
| | | } catch (ArrayIndexOutOfBoundsException e) { |
| | | |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("未知错误:" + e); |
| | | } |
| | | carInoutPos.add(carInoutPo); |
| | | } |
| | | } |
| | | |
| | | public void setCommunityId(CarInoutPo po, Object[] os, List<Map<String, Object>> maps) { |
| | | for (Map<String, Object> map : maps) { |
| | | if (ValueUtil.defaultValue(os[1]).isEmpty() && ValueUtil.defaultValue(os[2]).isEmpty()){ |
| | | throw new IllegalArgumentException("小区名称和小区编号均为空"); |
| | | } |
| | | if (ValueUtil.defaultValue(os[1]).isEmpty()) { |
| | | if (Vtil.defaultValue(map.get("name")).contains(ValueUtil.defaultValue(os[2]))) { |
| | | po.setCommunityId(map.get("communityId").toString()); |
| | | return; |
| | | } |
| | | } else if (ValueUtil.defaultValue(os[2]).isEmpty()){ |
| | | if (Vtil.defaultValue(map.get("communityCode")).equals(ValueUtil.defaultValue(os[1]))) { |
| | | po.setCommunityId(map.get("communityId").toString()); |
| | | return; |
| | | } |
| | | } else { |
| | | if (Vtil.defaultValue(map.get("communityCode")).equals(ValueUtil.defaultValue(os[1])) && Vtil.defaultValue(map.get("name")).contains(ValueUtil.defaultValue(os[2]))) { |
| | | po.setCommunityId(map.get("communityId").toString()); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | throw new IllegalArgumentException("未查询到小区:" + Vtil.appendHyphenToRight(ValueUtil.defaultValue(os[1])) + ValueUtil.defaultValue(os[2])); |
| | | } |
| | | |
| | | public String defaultValue(Object o) { |
| | | return o == null ? "" : o.toString(); |
| | | return o == null ? null : o.toString(); |
| | | } |
| | | } |