|
|
|
@ -8,14 +8,30 @@ import apelet.common.generator.utils.OrmGenDataSourceUtil; |
|
|
|
import apelet.common.online.plugin.BeginOperationTransactionArgs; |
|
|
|
import apelet.common.online.plugin.BeginOperationTransactionArgs; |
|
|
|
import apelet.common.online.plugin.OperationServicePlugIn; |
|
|
|
import apelet.common.online.plugin.OperationServicePlugIn; |
|
|
|
import apelet.common.online.plugin.OperationServicePlugInArgs; |
|
|
|
import apelet.common.online.plugin.OperationServicePlugInArgs; |
|
|
|
|
|
|
|
import apelet.common.orm.impl.Filter; |
|
|
|
|
|
|
|
import apelet.common.orm.impl.FilterItem; |
|
|
|
import apelet.common.orm.impl.Selector; |
|
|
|
import apelet.common.orm.impl.Selector; |
|
|
|
import apelet.common.orm.impl.SelectorItem; |
|
|
|
import apelet.common.orm.impl.SelectorItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
审核通过插件 |
|
|
|
审核通过插件 |
|
|
|
|
|
|
|
审核通过后:报价单状态置 3(已审核)、is_contract 置 1(转为合同), |
|
|
|
|
|
|
|
并将报价单主表数据写入 contract 表、报价单附表数据同步写入 contract_e 表。 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ReviewPastPlugin extends OperationServicePlugIn { |
|
|
|
public class ReviewPastPlugin extends OperationServicePlugIn { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 写入合同表时需跳过的字段: |
|
|
|
|
|
|
|
* id 由 addNew 自动生成;status/canaelreason/is_contract 为报价单特有字段,合同表无对应列 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final Set<String> SKIP_CONTRACT_FIELDS = new HashSet<>(Arrays.asList( |
|
|
|
|
|
|
|
"id", "status", "canaelreason", "is_contract")); |
|
|
|
|
|
|
|
|
|
|
|
private final OrmGenDataSourceUtil ormGenDataSourceUtil; |
|
|
|
private final OrmGenDataSourceUtil ormGenDataSourceUtil; |
|
|
|
|
|
|
|
|
|
|
|
public ReviewPastPlugin() { |
|
|
|
public ReviewPastPlugin() { |
|
|
|
@ -38,12 +54,62 @@ public class ReviewPastPlugin extends OperationServicePlugIn { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 获取单据对象
|
|
|
|
// 获取单据对象
|
|
|
|
ObjectValue bill = modelCollcetion.getObject(i); |
|
|
|
ObjectValue bill = modelCollcetion.getObject(i); |
|
|
|
bill.put("status", "3"); |
|
|
|
String quotationId = bill.getString("id"); |
|
|
|
bill.put("billstatus", "C"); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 查询报价单完整数据(用于更新状态及复制写入合同表)
|
|
|
|
|
|
|
|
ObjectValue quotation = ormGenDataSourceUtil.queryOne("quotation", Long.valueOf(quotationId)); |
|
|
|
|
|
|
|
if (quotation == null) { |
|
|
|
|
|
|
|
throw new MyRuntimeException("报价单不存在,id=" + quotationId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 审核通过:状态置 3、billstatus 置 C、is_contract 置 1(转为合同)
|
|
|
|
|
|
|
|
quotation.put("status", "3"); |
|
|
|
|
|
|
|
quotation.put("billstatus", "C"); |
|
|
|
|
|
|
|
quotation.put("is_contract", "1"); |
|
|
|
Selector selector = new Selector(); |
|
|
|
Selector selector = new Selector(); |
|
|
|
selector.getList().add(new SelectorItem("status")); |
|
|
|
selector.getList().add(new SelectorItem("status")); |
|
|
|
selector.getList().add(new SelectorItem("billstatus")); |
|
|
|
selector.getList().add(new SelectorItem("billstatus")); |
|
|
|
ormGenDataSourceUtil.update(bill.getTableName(), bill, selector); |
|
|
|
selector.getList().add(new SelectorItem("is_contract")); |
|
|
|
|
|
|
|
ormGenDataSourceUtil.update(quotation.getTableName(), quotation, selector); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 将报价单数据写入合同表(跳过 id 及报价单特有字段)
|
|
|
|
|
|
|
|
ObjectValue contract = new ObjectValue("contract"); |
|
|
|
|
|
|
|
for (Object fieldObj : quotation.getValues().entrySet()) { |
|
|
|
|
|
|
|
Map.Entry field = (Map.Entry) fieldObj; |
|
|
|
|
|
|
|
String fieldName = String.valueOf(field.getKey()); |
|
|
|
|
|
|
|
if (SKIP_CONTRACT_FIELDS.contains(fieldName)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
contract.put(fieldName, field.getValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ObjectValue newContract = ormGenDataSourceUtil.addNew("contract", contract); |
|
|
|
|
|
|
|
Object newContractId = newContract.get("id"); |
|
|
|
|
|
|
|
if (newContractId == null) { |
|
|
|
|
|
|
|
throw new MyRuntimeException("写入合同表失败,未生成合同ID"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String contractId = String.valueOf(newContractId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 报价单附表数据同步写入合同附表,parent_id 指向新写入的合同主表 id
|
|
|
|
|
|
|
|
Filter entryFilter = new Filter(); |
|
|
|
|
|
|
|
entryFilter.add(new FilterItem("parent_id", FilterItem.equals, quotationId)); |
|
|
|
|
|
|
|
ObjectCollection quotationEntries = ormGenDataSourceUtil.query("quotation_e", entryFilter, new Selector()); |
|
|
|
|
|
|
|
if (quotationEntries != null && !quotationEntries.isEmpty()) { |
|
|
|
|
|
|
|
for (int j = 0; j < quotationEntries.size(); j++) { |
|
|
|
|
|
|
|
ObjectValue quotationEntry = quotationEntries.getObject(j); |
|
|
|
|
|
|
|
ObjectValue contractEntry = new ObjectValue("contract_e"); |
|
|
|
|
|
|
|
for (Object fieldObj : quotationEntry.getValues().entrySet()) { |
|
|
|
|
|
|
|
Map.Entry field = (Map.Entry) fieldObj; |
|
|
|
|
|
|
|
String fieldName = String.valueOf(field.getKey()); |
|
|
|
|
|
|
|
if ("id".equals(fieldName)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
contractEntry.put(fieldName, field.getValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
contractEntry.put("parent_id", contractId); |
|
|
|
|
|
|
|
ormGenDataSourceUtil.addNew("contract_e", contractEntry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
} catch (Exception ex) { |
|
|
|
throw new MyRuntimeException(ex.getMessage()); |
|
|
|
throw new MyRuntimeException(ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|