163 lines
6.4 KiB
Java
163 lines
6.4 KiB
Java
package com.tenwa.apzl.discount;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO;
|
|
import jbo.voucher.LB_DISCOUNT;
|
|
|
|
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.amarsoft.dict.als.cache.CacheLoaderFactory;
|
|
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);
|
|
|
|
}
|
|
//
|
|
public void runBefore(ASUser CurUser, Map<String, String> model, List<BizObject> importObjects, JBOTransaction tx,Transaction Sqlca) throws Exception {
|
|
Sqlca = Transaction.createTransaction(CacheLoaderFactory.getDataSource());
|
|
String error="";
|
|
boolean flag = false;
|
|
String insertSql="";
|
|
Date date = new Date();
|
|
String date1 = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss").format(date);
|
|
|
|
/**
|
|
* 校验重复导入
|
|
*/
|
|
// 用于校验是否重复
|
|
List<String> contractNo = new ArrayList<String>();
|
|
// 经所有业务合同号存入集合
|
|
List<BizObject> ConList=JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO.CLASS_NAME,"ASSETTRANSFERER IS NOT NULL").getResultList(false);
|
|
for(int i=0;i<ConList.size();i++) {
|
|
contractNo.add(ConList.get(i).getAttribute("CONTRACT_NO").getString());
|
|
}
|
|
// 未导入的加到集合, 已有的报重复校验
|
|
for(BizObject bo:importObjects){
|
|
String CONTRACT_NO = bo.getAttribute("CONTRACT_NO").getString();
|
|
if(!contractNo.contains(CONTRACT_NO)){
|
|
contractNo.add(CONTRACT_NO);
|
|
}else {
|
|
String uuids = UUID.randomUUID().toString();
|
|
String uuid = uuids.replaceAll("-", "");
|
|
insertSql="INSERT INTO li_assets_off(id,CONTRACT_NO,inputuser,inputtime,updateuser,updatetime) values('"+uuid+"','"+CONTRACT_NO+"','administrator','"+date1+"','administrator','"+date1+"')";
|
|
Sqlca.executeSQL(insertSql);
|
|
error+=",【"+CONTRACT_NO+"】";
|
|
flag=true;
|
|
}
|
|
}
|
|
Sqlca.commit();
|
|
if(flag) {
|
|
error = error.substring(1);
|
|
throw new BusinessException("该合同号:"+error+"已存在<<资产转出方>> 请勿重复导入!");
|
|
}
|
|
if(Sqlca !=null){
|
|
Sqlca.disConnect();
|
|
}
|
|
}
|
|
}
|