116 lines
4.6 KiB
Java
116 lines
4.6 KiB
Java
package com.tenwa.apzl.discount;
|
|
|
|
import java.util.Map;
|
|
|
|
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.amarsoft.awe.util.Transaction;
|
|
import com.amarsoft.context.ASUser;
|
|
import com.tenwa.comm.exception.BusinessException;
|
|
import com.tenwa.officetempalte.importcallback.impl.BaseImportExcelCallBack;
|
|
|
|
public class AssetsOffCallBack extends BaseImportExcelCallBack{
|
|
@Override
|
|
public void run(ASUser CurUser, BizObject importObject,
|
|
Map<String, String> model, Integer rowIndex, JBOTransaction tx,
|
|
Transaction Sqlca) throws Exception {
|
|
//合同号
|
|
String contractNo = importObject.getAttribute("CONTRACT_NO")==null?"":importObject.getAttribute("CONTRACT_NO").toString();
|
|
//资产转出方
|
|
String assettransferer = importObject.getAttribute("ASSETTRANSFERER")==null?"":importObject.getAttribute("ASSETTRANSFERER").toString();
|
|
//转出日期
|
|
String transferdate = importObject.getAttribute("TRANSFERDATE")==null?"":importObject.getAttribute("TRANSFERDATE").toString();
|
|
//转出备注
|
|
String turnoutremarks = importObject.getAttribute("TURNOUTREMARKS")==null?"":importObject.getAttribute("TURNOUTREMARKS").toString();
|
|
if (contractNo=="" || assettransferer=="" || transferdate=="") {
|
|
throw new BusinessException("合同号或资产转出方或转出如期为空!");
|
|
}
|
|
|
|
//将yyyy-mm-dd这种日期格式改为yyyy/mm/dd
|
|
// 如果是8位 20000101
|
|
if(transferdate.indexOf("/") != -1){
|
|
String[] date = transferdate.split("/");
|
|
transferdate = "";
|
|
for(String d:date){
|
|
if(d.length() == 1){
|
|
d = "0"+d;
|
|
}
|
|
transferdate += d+"/";
|
|
}
|
|
transferdate = transferdate.substring(0,transferdate.length()-1);
|
|
}else if(transferdate.length()==8){
|
|
StringBuffer sb1=new StringBuffer(transferdate);
|
|
// 在3位置插入"/"
|
|
String s1=sb1.insert(4,"/").toString(); // 2000/0101
|
|
StringBuffer sb2=new StringBuffer(s1);
|
|
transferdate=sb2.insert(7,"/").toString(); // 2000/01/01
|
|
}else if(transferdate.contains("-")){
|
|
transferdate=transferdate.replaceAll("-", "/");
|
|
}else if(transferdate.contains("年")&&transferdate.contains("月")&&transferdate.contains("日")){
|
|
transferdate=transferdate.replaceAll("年", "/").replaceAll("月","/").replaceAll("日","");
|
|
}
|
|
String[] checkDate = transferdate.split("/");
|
|
try{
|
|
int year = Integer.parseInt(checkDate[0]);
|
|
int month = Integer.parseInt(checkDate[1]);
|
|
int day = Integer.parseInt(checkDate[2]);
|
|
int num = 28;
|
|
if(day <= 0){
|
|
throw new RuntimeException("第"+(rowIndex+1)+"行日期不正确,不存在'"+day+"'这样的日期!");
|
|
}
|
|
String mes = "平年";
|
|
if((year%4 == 0 && year%100 != 0) || year%400 == 0){
|
|
num = 29;
|
|
mes = "闰年";
|
|
}
|
|
switch(month){
|
|
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
|
|
if(day > 31 || day <= 0){
|
|
throw new RuntimeException("第"+(rowIndex+1)+"行日期不正确,"+month+"月份没有"+day+"天!");
|
|
}
|
|
break;
|
|
case 2:
|
|
if(day > num || day <=0){
|
|
throw new RuntimeException("第"+(rowIndex+1)+"行日期不正确,"+mes+month+"月份没有"+day+"天!");
|
|
}
|
|
break;
|
|
case 4:case 6:case 9:case 11:
|
|
if(day > 30 || day <=0){
|
|
throw new RuntimeException("第"+(rowIndex+1)+"行日期不正确,"+month+"月份没有"+day+"天!");
|
|
}
|
|
break;
|
|
default:
|
|
throw new RuntimeException("第"+(rowIndex+1)+"行月份错误,没有'"+month+"'月份!");
|
|
}
|
|
}catch(NumberFormatException e){
|
|
throw new BusinessException("第"+(rowIndex+1)+"行日期格式不正确!");
|
|
}catch(RuntimeException e){
|
|
throw new BusinessException(e.getMessage());
|
|
}
|
|
|
|
|
|
//查询该合同号是否存在
|
|
BizObjectManager contractInfoManager = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx);
|
|
BizObject contractInfo = contractInfoManager.createQuery("CONTRACT_NO=:CONTRACT_NO").setParameter("CONTRACT_NO", contractNo).getSingleResult(true);
|
|
if (contractInfo==null) {
|
|
throw new BusinessException("该合同号 "+contractNo+" 不存在!");
|
|
}
|
|
//已经存在资产转出方的不允许导入
|
|
String ass = contractInfo.getAttribute("ASSETTRANSFERER")==null? "" : contractInfo.getAttribute("ASSETTRANSFERER").toString();
|
|
if (!"".equals(ass)) {
|
|
throw new BusinessException("该合同号 "+contractNo+" 已存在<<资产转出方>> 请勿重复导入!");
|
|
}
|
|
|
|
contractInfo.setAttributeValue("ASSETTRANSFERER", assettransferer);
|
|
contractInfo.setAttributeValue("TRANSFERDATE", transferdate);
|
|
contractInfo.setAttributeValue("TURNOUTREMARKS", turnoutremarks);
|
|
contractInfoManager.saveObject(contractInfo);
|
|
|
|
}
|
|
|
|
}
|