134 lines
4.6 KiB
Java
134 lines
4.6 KiB
Java
package com.cm.systemcity.utils;
|
|
|
|
import com.cm.systemcity.pojo.dtos.citybuilding.CityBuildingDTO;
|
|
import com.cm.systemcity.pojo.dtos.citydistrict.CityDistrictDTO;
|
|
import com.cm.systemcity.pojo.model.buildinghouse.BuildingHouseModel;
|
|
import com.cm.systemcity.service.citybuilding.ICityBuildingService;
|
|
import com.cm.systemcity.service.citydistrict.ICityDistrictService;
|
|
import com.cm.systemcity.service.handleimportexcel.IHandleImportExcelService;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 导入excel数据的校验类
|
|
* @author renpc
|
|
*/
|
|
@Component
|
|
public class ImportExcelHelper {
|
|
|
|
@Autowired
|
|
private IHandleImportExcelService handleImportExcelService;
|
|
@Autowired
|
|
private static ICityDistrictService cityDistrictService;
|
|
@Autowired
|
|
private static ICityBuildingService cityBuildingService;
|
|
|
|
@Autowired
|
|
public void init(ICityDistrictService cityDistrictService) {
|
|
ImportExcelHelper.cityDistrictService = cityDistrictService;
|
|
}
|
|
|
|
@Autowired
|
|
public void init(ICityBuildingService cityBuildingService) {
|
|
ImportExcelHelper.cityBuildingService = cityBuildingService;
|
|
}
|
|
|
|
public static <T> String checkDataValid(T obj) {
|
|
if(null == obj) {
|
|
return null;
|
|
}
|
|
String returnStr = isMustInput(obj);
|
|
return returnStr;
|
|
}
|
|
|
|
/**
|
|
* 检查数据是否必填项缺失
|
|
* @param obj
|
|
* @param <T>
|
|
* @return
|
|
*/
|
|
private static <T> String isMustInput(T obj) {
|
|
// 房屋信息
|
|
if(obj instanceof BuildingHouseModel) {
|
|
Object temp = obj;
|
|
BuildingHouseModel buildingHouseModel = (BuildingHouseModel) temp;
|
|
return checkBuildingHouseData(buildingHouseModel);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
/**
|
|
* 检查数据是否必填项缺失(房屋管理)
|
|
* @param buildingHouseModel
|
|
* @return
|
|
*/
|
|
private static String checkBuildingHouseData(BuildingHouseModel buildingHouseModel) {
|
|
/*if(StringUtils.isEmpty(buildingHouseModel.getHouseNumber())) {
|
|
buildingHouseModel.setHouseNumber("" + Math.random() * 1000000);
|
|
// return "房屋编号必填";
|
|
}*/
|
|
if(StringUtils.isEmpty(buildingHouseModel.getDistrictName())) {
|
|
return "小区名称必填";
|
|
}
|
|
if(StringUtils.isEmpty(buildingHouseModel.getHouseNumber())) {
|
|
return "房屋编号必填";
|
|
}
|
|
/*if(StringUtils.isEmpty(buildingHouseModel.getHouseStatus())) {
|
|
return "房屋状态必填";
|
|
}
|
|
if(StringUtils.isEmpty(buildingHouseModel.getOwnerName())) {
|
|
return "房主姓名必填";
|
|
}
|
|
if(StringUtils.isEmpty(buildingHouseModel.getOwnerCard())) {
|
|
return "房主身份证号必填";
|
|
}
|
|
if(StringUtils.isEmpty(buildingHouseModel.getOwnerPhone())) {
|
|
return "房主联系方式必填";
|
|
}*/
|
|
return "";
|
|
}
|
|
|
|
/**
|
|
* 从数据库比对数据,并转换为数据库数据
|
|
* @param obj
|
|
* @param <T>
|
|
*/
|
|
public static <T> void checkDataFromDatabase(T obj) {
|
|
// 出租房
|
|
if(obj instanceof BuildingHouseModel) {
|
|
Object temp = obj;
|
|
BuildingHouseModel buildingHouseModel = (BuildingHouseModel) temp;
|
|
buildingHouseCheck(buildingHouseModel);
|
|
temp = buildingHouseModel;
|
|
obj = (T) temp;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从数据库比对数据,并转换为数据库数据(房屋管理)
|
|
* @param buildingHouseModel
|
|
*/
|
|
private static void buildingHouseCheck(BuildingHouseModel buildingHouseModel) {
|
|
if(!StringUtils.isEmpty(buildingHouseModel.getOwnerCard())) {
|
|
if(buildingHouseModel.getOwnerCard().startsWith("'")) {
|
|
buildingHouseModel.setOwnerCard(buildingHouseModel.getOwnerCard().replaceAll("'", ""));
|
|
}
|
|
}
|
|
Map<String, Object> param = new HashMap<>();
|
|
param.put("districtName", buildingHouseModel.getDistrictName());
|
|
CityDistrictDTO cityDistrictDTO = cityDistrictService.getCityDistrictByName(buildingHouseModel.getDistrictName());
|
|
if(null != cityDistrictDTO) {
|
|
buildingHouseModel.setDistrictId(cityDistrictDTO.getCityDistrictId());
|
|
}
|
|
CityBuildingDTO cityBuildingDTO = cityBuildingService.getCityBuildingByName(buildingHouseModel.getCityBuildingName());
|
|
if(null != cityBuildingDTO) {
|
|
buildingHouseModel.setCityBuildingId(cityBuildingDTO.getCityBuildingId());
|
|
}
|
|
}
|
|
|
|
}
|