package nc.bs.backgroundtasks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.itf.jych.IPaymentorderMaintain;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.vo.jych.oavo.OaPaymentOrderVO;
import nc.vo.jych.paymentorder.AggPaymentOrderVO;
import nc.vo.jych.paymentorder.PaymentOrderVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVOUtil;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.wgbfb.tool.NullValueUtils;
import nc.vo.zkch.utils.SqlBuilder;
public class OAPaymentOrderPlugin implements IBackgroundWorkPlugin{
@Override
public PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException {
generatePaymentOrder();
return null;
}
@SuppressWarnings("unchecked")
private void generatePaymentOrder() throws BusinessException {
SqlBuilder sqlname = new SqlBuilder();
sqlname.append(" select * from jych_zj_fkd where nvl(dr,0) = 0 and nvl(iszx,'N') != 'Y' ");
List<OaPaymentOrderVO> volist = (List<OaPaymentOrderVO>) getDao().executeQuery(sqlname.toString(), new BeanListProcessor(OaPaymentOrderVO.class));
if(volist == null || volist.size() < 1){
return;
}
List<String> idlist = new ArrayList<String>();
List<String> zjpklist = new ArrayList<String>();
for (OaPaymentOrderVO vo : volist) {
String id = vo.getId() + vo.getSjly() + NullValueUtils.getNullStringValue(vo.getFklx());
idlist.add(id);
zjpklist.add(vo.getPk_fkd());
}
SqlBuilder pksql = new SqlBuilder();
pksql.append(" select pk_paymentorder from jych_paymentorder where nvl(dr,0) = 0 and ");
pksql.append(" wxtbs||sjly||fklx ", idlist.toArray(new String[0]));
List<String> pklist = (List<String>) getDao().executeQuery(pksql.toString(), new ColumnListProcessor());
Map<String, AggPaymentOrderVO> vomap = new HashMap<String, AggPaymentOrderVO>();
if(pklist != null && pklist.size() > 0){
BillQuery<AggPaymentOrderVO> billQuery = new BillQuery<AggPaymentOrderVO>(AggPaymentOrderVO.class);
AggPaymentOrderVO[] vos = billQuery.query(pklist.toArray(new String[0]));
for (AggPaymentOrderVO aggvo : vos) {
String wxtbs = aggvo.getParentVO().getWxtbs();
String sjly = aggvo.getParentVO().getSjly();
String fklx = aggvo.getParentVO().getFklx();
String id = wxtbs + sjly + fklx;
vomap.put(id, aggvo);
}
}
updateHeadVO(volist.toArray(new OaPaymentOrderVO[0]));
List<AggPaymentOrderVO> insertlist = new ArrayList<AggPaymentOrderVO>();
List<AggPaymentOrderVO> updatelist = new ArrayList<AggPaymentOrderVO>();
List<AggPaymentOrderVO> orgupdatelist = new ArrayList<AggPaymentOrderVO>();
for (OaPaymentOrderVO vo : volist) {
String id = vo.getId() + vo.getSjly() + NullValueUtils.getNullStringValue(vo.getFklx());
if(vomap != null && vomap.size() > 0 && vomap.containsKey(id)){
AggPaymentOrderVO aggvo = vomap.get(id);
AggPaymentOrderVO clone = (AggPaymentOrderVO) aggvo.clone();
PaymentOrderVO headvo = clone.getParentVO();
headvo.setStatus(VOStatus.UPDATED);
setHeadvo(headvo, vo);
updatelist.add(clone);
orgupdatelist.add(aggvo);
} else {
AggPaymentOrderVO aggvo = new AggPaymentOrderVO();
PaymentOrderVO headvo = new PaymentOrderVO();
headvo.setStatus(VOStatus.NEW);
headvo.setPk_billtype("XS01");
headvo.setTranstypecode("XS01-Cxx-01");
headvo.setPk_org(vo.getPk_org());
headvo.setPk_org_v(vo.getPk_org_v());
headvo.setPk_group(vo.getPk_group());
headvo.setPk_transtype(vo.getPk_transtype());
headvo.setDbilldate(new UFDate());
headvo.setVbillstatus(-1);
setHeadvo(headvo, vo);
aggvo.setParentVO(headvo);
insertlist.add(aggvo);
}
}
if(insertlist != null && insertlist.size() > 0){
AggPaymentOrderVO[] insertvos = getService().insert(insertlist.toArray(new AggPaymentOrderVO[0]), insertlist.toArray(new AggPaymentOrderVO[0]));
List<AggPaymentOrderVO> insertvolist = new ArrayList<AggPaymentOrderVO>();
for (AggPaymentOrderVO insertvo : insertvos) {
AggPaymentOrderVO clone = (AggPaymentOrderVO) insertvo.clone();
PaymentOrderVO vo = clone.getParentVO();
vo.setVbillstatus(1);vo.setApprovedate(new UFDateTime());vo.setApprover(vo.getCreator());
insertvolist.add(clone);
}
getService().approve(insertvolist.toArray(new AggPaymentOrderVO[0]), insertvos);
}
if(updatelist != null && updatelist.size() > 0){
getService().update(updatelist.toArray(new AggPaymentOrderVO[0]), orgupdatelist.toArray(new AggPaymentOrderVO[0]));
}
SqlBuilder updatesql = new SqlBuilder();
updatesql.append(" update jych_zj_fkd set iszx = 'Y' where ");
updatesql.append(" pk_fkd ", zjpklist.toArray(new String[0]));
getDao().executeUpdate(updatesql.toString());
}
private void updateHeadVO(OaPaymentOrderVO[] headvos){
SuperVOUtil.execFormulaWithVOs(headvos,new String[] {
"pk_org->getcolvalue2(org_orgs,pk_org,code,\"05\",islastversion,\"Y\")",
"pk_org_v->getcolvalue(org_orgs,pk_vid,pk_org,pk_org)",
"pk_group->getcolvalue(org_group,pk_group,code,\"01\")",
"def1->fkxs",
"def2->lastname",
"lastname->getColValue2(bd_psndoc,pk_psndoc,name,lastname,dr,0)",
"def3->htbh",
"htbh->getColValue(view_jych_contract,pk,htbh,htbh)",
"def4->departmentname",
"departmentname->getColValue2(org_dept,pk_dept,name,departmentname,dr,0)",
"def5->xmbh",
"xmbh->getColValue2(zkch_marketpro,pk_marketpro,marketprocode,xmbh,dr,0)"
});
}
public void setHeadvo(PaymentOrderVO headvo, OaPaymentOrderVO vo){
headvo.setWxtbs(vo.getId());
headvo.setSqrq(vo.getSqrq());
headvo.setSsjg(vo.getSzjg());
headvo.setSqr(vo.getLastname());
headvo.setSqbm(vo.getDepartmentname());
headvo.setZfddh(vo.getZfddh());
headvo.setXmbh(vo.getXmbh());
headvo.setHtbh(vo.getHtbh());
headvo.setFksy(vo.getFksy());
headvo.setBcfkmny(vo.getBcfkjey());
headvo.setBcsjzf(vo.getBcsjzf());
headvo.setYingfmny(vo.getYfkje());
headvo.setFkxs(vo.getFkxs());
headvo.setIscxyfk(vo.getSfcxyfk());
headvo.setGddate(vo.getLastoperatedate());
headvo.setCnspdate(vo.getOperatedate());
headvo.setFklx(vo.getFklx());
headvo.setSjly(vo.getSjly());
headvo.setSfhjk(vo.getSfhjk());
headvo.setCxje(vo.getCxje());
headvo.setDef1(vo.getDef1());
headvo.setDef2(vo.getDef2());
headvo.setDef3(vo.getDef3());
headvo.setDef4(vo.getDef4());
headvo.setDef5(vo.getDef5());
}
private IPaymentorderMaintain service;
private IPaymentorderMaintain getService() {
if (service == null) {
service = NCLocator.getInstance().lookup(
IPaymentorderMaintain.class);
}
return service;
}
private BaseDAO dao;
private BaseDAO getDao(){
if(dao == null){
dao = new BaseDAO();
}
return dao;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238