package com.java110.api.importData;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.java110.core.factory.GenerateCodeFactory;
|
import com.java110.dto.payFee.PayFeeBatchDto;
|
import com.java110.dto.user.UserDto;
|
import com.java110.intf.fee.IPayFeeBatchV1InnerServiceSMO;
|
import com.java110.intf.user.IUserInnerServiceSMO;
|
import com.java110.po.payFee.PayFeeBatchPo;
|
import com.java110.utils.util.Assert;
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
|
public class DefaultImportDataAdapt {
|
|
@Autowired
|
private IPayFeeBatchV1InnerServiceSMO payFeeBatchV1InnerServiceSMOImpl;
|
|
private static final Date EXCEL_EPOCH;
|
|
static {
|
// 初始化Excel起始日期(1899-12-30,对应Excel的0天)
|
Calendar cal = Calendar.getInstance();
|
cal.set(1899, Calendar.DECEMBER, 30, 0, 0, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
EXCEL_EPOCH = cal.getTime();
|
}
|
|
/**
|
* 将Excel日期数值(如45734.0)转换为Date对象
|
* @param excelDate Excel日期数值
|
* @return 对应的Date对象
|
*/
|
public static Date doubleToDate(double excelDate) {
|
// 处理Excel 1900年闰年错误(Excel错误地将1900年视为闰年)
|
long days = (long) Math.floor(excelDate);
|
if (days >= 60) { // 1900-03-01及之后的日期需要减1天
|
days--;
|
}
|
|
// 计算总毫秒数(天数部分 + 时间部分)
|
long totalMillis = (long)(days * 86400000L) // 1天 = 86400000毫秒
|
+ (long)((excelDate - days) * 86400000L);
|
|
// 从基准日期开始累加毫秒数
|
return new Date(EXCEL_EPOCH.getTime() + totalMillis);
|
}
|
|
/**
|
* 处理Excel日期字符串(如"45734.0"),转换为"yyyy-MM-dd"格式
|
* @param strDate Excel日期数值字符串
|
* @return 格式化后的日期字符串
|
* @throws ParseException 转换失败时抛出
|
*/
|
public String handleExcelDateString(String strDate){
|
// 1. 将字符串转换为double(如"45734.0" -> 45734.0)
|
double excelDateValue = Double.parseDouble(strDate);
|
|
// 2. 将Excel数值转换为Date对象
|
Date tDate = doubleToDate(excelDateValue);
|
|
// 3. 格式化为"yyyy-MM-dd"
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
return sdf.format(tDate);
|
}
|
|
|
@Autowired
|
private IUserInnerServiceSMO userInnerServiceSMOImpl;
|
protected boolean hasSpecialCharacters(String str) {
|
if (str.contains("-") || str.contains("#") || str.contains("?") || str.contains("&")) {
|
return true;
|
}
|
|
return false;
|
}
|
|
protected boolean hasRoomSpecialCharacters(String str) {
|
if ( str.contains("#") || str.contains("?") || str.contains("&")) {
|
return true;
|
}
|
|
return false;
|
}
|
|
|
//解析Excel日期格式
|
public static String excelDoubleToDate(String strDate) {
|
if (strDate.length() == 5) {
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date tDate = DoubleToDate(Double.parseDouble(strDate));
|
return sdf.format(tDate);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return strDate;
|
}
|
}
|
return strDate;
|
}
|
|
|
//解析Excel日期格式
|
public static Date DoubleToDate(Double dVal) {
|
Date tDate = new Date();
|
long localOffset = tDate.getTimezoneOffset() * 60000; //系统时区偏移 1900/1/1 到 1970/1/1 的 25569 天
|
tDate.setTime((long) ((dVal - 25569) * 24 * 3600 * 1000 + localOffset));
|
|
return tDate;
|
}
|
|
/**
|
* 生成批次号
|
*
|
* @param reqJson
|
*/
|
public void generatorBatch(JSONObject reqJson) {
|
PayFeeBatchPo payFeeBatchPo = new PayFeeBatchPo();
|
payFeeBatchPo.setBatchId(GenerateCodeFactory.getGeneratorId("12"));
|
payFeeBatchPo.setCommunityId(reqJson.getString("communityId"));
|
payFeeBatchPo.setCreateUserId(reqJson.getString("userId"));
|
UserDto userDto = new UserDto();
|
userDto.setUserId(reqJson.getString("userId"));
|
List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
|
|
Assert.listOnlyOne(userDtos, "用户不存在");
|
payFeeBatchPo.setCreateUserName(userDtos.get(0).getUserName());
|
payFeeBatchPo.setState(PayFeeBatchDto.STATE_NORMAL);
|
payFeeBatchPo.setMsg("正常");
|
int flag = payFeeBatchV1InnerServiceSMOImpl.savePayFeeBatch(payFeeBatchPo);
|
|
if (flag < 1) {
|
throw new IllegalArgumentException("生成批次失败");
|
}
|
|
reqJson.put("batchId", payFeeBatchPo.getBatchId());
|
}
|
|
}
|