168 lines
8.6 KiB
Java
168 lines
8.6 KiB
Java
package com.seeyon.apps.assetstenant.discharge;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.seeyon.apps.assetstenant.assets.OaAssetsVo;
|
|
import com.seeyon.apps.assetstenant.bill.BillVo;
|
|
import com.seeyon.apps.assetstenant.config.AssetsTenantConfigProvider;
|
|
import com.seeyon.apps.assetstenant.constants.AssetsTenantConstants;
|
|
import com.seeyon.apps.assetstenant.contract.ContractService;
|
|
import com.seeyon.apps.assetstenant.flow.FlowCreateService;
|
|
import com.seeyon.apps.assetstenant.po.PageQueryVo;
|
|
import com.seeyon.apps.assetstenant.utils.ProtUtil;
|
|
import com.seeyon.apps.esign.constants.EsignConfigConstants;
|
|
import com.seeyon.cap4.form.bean.FormTableBean;
|
|
import com.seeyon.ctp.common.AppContext;
|
|
import com.seeyon.ctp.common.exceptions.BusinessException;
|
|
import com.seeyon.utils.form.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class DisCharegeService {
|
|
|
|
private AssetsTenantConfigProvider configProvider = (AssetsTenantConfigProvider) AppContext.getBean("assetsTenantConfigProvider");
|
|
private FlowCreateService flowCreateService = (FlowCreateService) AppContext.getBean("flowCreateService");
|
|
private ContractService contractService = (ContractService) AppContext.getBean("contractService");
|
|
|
|
private String getFormNo() {
|
|
return configProvider.getBizConfigByKey(AssetsTenantConstants.DISCHARGE_TEMPLATECODE);
|
|
}
|
|
private TableContext getTableContext() throws BusinessException {
|
|
return FormTableExecutor.master(getFormNo());
|
|
}
|
|
|
|
private String getStringValue(Map<String, Object> fieldsMap,String key) {
|
|
Object o = fieldsMap.get(key);
|
|
if(o == null) {
|
|
return null;
|
|
}
|
|
return o + "";
|
|
}
|
|
|
|
public PageQueryVo pageQuery(JSONObject params) throws Exception {
|
|
List<FormWhereCondition> conditions = buildConditions(params);
|
|
Integer pageNo = params.getInteger("pageNo") == null ? 1 : params.getInteger("pageNo");
|
|
Integer pageSize = params.getInteger("pageSize") == null ? 10 : params.getInteger("pageSize");
|
|
List<String> queryColumnVos = new ArrayList<>();
|
|
PageQueryVo<DisChargeRecordVo> pageQueryVo = new PageQueryVo();
|
|
List<DisChargeRecordVo> vos = new ArrayList<>();
|
|
TableContext tableContext = getTableContext();
|
|
List<FormColumn> datas = FormTableExecutor.pageQuery(tableContext, queryColumnVos, conditions, pageNo, pageSize,true);
|
|
Long count = FormTableExecutor.count(tableContext,null, conditions);
|
|
if(datas.size() > 0){
|
|
for (FormColumn data : datas) {
|
|
Map<String,Object> map = data.getFieldsMap();
|
|
DisChargeRecordVo vo = new DisChargeRecordVo();
|
|
fillVo(map,vo);
|
|
vos.add(vo);
|
|
}
|
|
pageQueryVo.setDatas(vos);
|
|
pageQueryVo.setTotalCount(count);
|
|
}
|
|
return pageQueryVo;
|
|
}
|
|
|
|
public void saveApplay(JSONObject params) throws Exception {
|
|
TableContext tableContext = getTableContext();
|
|
FormTableBean masterTableBean = tableContext.getTableBean();
|
|
String tableName = masterTableBean.getTableName();
|
|
String subDbTableName = null;
|
|
TableContext sub = FormTableExecutor.sub(getFormNo(), "租赁资产");
|
|
subDbTableName = sub.getTableName();
|
|
Map<String,Object> mainFormData = new HashMap<>();
|
|
Map<String,List<Object>> subFormDataMap = new HashMap<>();
|
|
List<Object> subFormDataList = new ArrayList<>();
|
|
Map<String,Object> data = new HashMap<>();
|
|
subFormDataMap.put(subDbTableName,subFormDataList);
|
|
String templateCode = configProvider.getBizConfigByKey(AssetsTenantConstants.DISCHARGE_TEMPLATECODE);
|
|
String appName = configProvider.getBizConfigByKey(AssetsTenantConstants.FORMAPPNAME);
|
|
mainFormData.put(tableName,data);
|
|
String contractNo = params.getString("contractNo");
|
|
List<String> assetsNoList = (List<String>) params.get("assetsNoList");
|
|
Set<String> assetsNoSet = assetsNoList.stream().collect(Collectors.toSet());
|
|
List<OaAssetsVo> oaAssetsVos = contractService.queryContractAllAssets(contractNo);
|
|
if(oaAssetsVos != null) {
|
|
oaAssetsVos.forEach(oaAssetsVo -> {
|
|
if(assetsNoSet.contains(oaAssetsVo.getAssetsNo())){
|
|
Map<String,Object> tempMap = new HashMap<>();
|
|
tempMap.put("资产编号",oaAssetsVo.getAssetsNo());
|
|
subFormDataList.add(tempMap);
|
|
}
|
|
});
|
|
}
|
|
data.put("合同名称",params.getString("contractName"));
|
|
data.put("合同编号",contractNo);
|
|
data.put("承租方类型", EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(), "承租方类型", params.getString("cusType")));
|
|
data.put("承租方名称",params.getString("cusName"));
|
|
data.put("联系方式",params.getString("phone"));
|
|
data.put("终止原因",params.getString("reason"));
|
|
data.put("退租申请状态",EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"退租申请状态","申请中"));
|
|
data.put("清算状态",EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"清算状态","未清算"));
|
|
flowCreateService.flowStart("退租申请",mainFormData,subFormDataMap,appName,templateCode);
|
|
}
|
|
|
|
public void cancelApply(String id) throws BusinessException, IOException {
|
|
List<FormWhereCondition> conditions = new ArrayList<>();
|
|
conditions.add(FormWhereCondition.build().display("ID").value(id));
|
|
FormColumn formColumn = FormTableExecutor.queryOne(getTableContext(), conditions, true);
|
|
if(formColumn == null) {
|
|
throw new BusinessException("未找到退租申请");
|
|
}
|
|
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
|
String nodeId = (String)fieldsMap.get("流程节点ID");
|
|
JSONObject params = new JSONObject();
|
|
params.put("message", "租户取消退租申请");
|
|
params.put("returnCode", 5);
|
|
ProtUtil.sendPostNotification(configProvider,params.toString(),"/seeyon/rest/flow/notification/", nodeId);
|
|
}
|
|
|
|
public void forwardApply(String id) throws BusinessException, IOException {
|
|
List<FormWhereCondition> conditions = new ArrayList<>();
|
|
conditions.add(FormWhereCondition.build().display("ID").value(id));
|
|
FormColumn formColumn = FormTableExecutor.queryOne(getTableContext(), conditions, true);
|
|
if(formColumn == null) {
|
|
throw new BusinessException("未找到退租申请");
|
|
}
|
|
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
|
String nodeId = (String)fieldsMap.get("流程节点ID");
|
|
JSONObject params = new JSONObject();
|
|
params.put("message", "租户已确认清退费用");
|
|
params.put("returnCode", 1);
|
|
ProtUtil.sendPostNotification(configProvider,params.toString(),"/seeyon/rest/flow/notification/", nodeId);
|
|
}
|
|
|
|
// public List<BillVo> queryDisChargeBill(String id) {
|
|
// List
|
|
// }
|
|
|
|
public void fillVo(Map<String, Object> fieldsMap,DisChargeRecordVo vo) throws BusinessException {
|
|
vo.setContractName(getStringValue(fieldsMap,"合同名称"));
|
|
vo.setId(getStringValue(fieldsMap,"id"));
|
|
vo.setRemark(getStringValue(fieldsMap,"审批意见"));
|
|
vo.setStatus(getStringValue(fieldsMap,"退租申请状态"));
|
|
vo.setApplyDate(getStringValue(fieldsMap,"经办日期"));
|
|
Long id = Long.parseLong(vo.getId());
|
|
List<FormWhereCondition> subConditions = new ArrayList<>();
|
|
subConditions.add(FormWhereCondition.build().display("formmain_id").value(id));
|
|
TableContext subtableContext = FormTableExecutor.sub(getFormNo(), "租赁资产");
|
|
List<FormColumn> subDatas = FormTableExecutor.query(subtableContext, null,subConditions,true);
|
|
StringBuilder dischargeItem = new StringBuilder("");
|
|
for (FormColumn subData : subDatas) {
|
|
Map<String, Object> subDataFieldsMap = subData.getFieldsMap();
|
|
String assetsName = (String) subDataFieldsMap.get("资产名称");
|
|
dischargeItem.append(assetsName).append(",");
|
|
}
|
|
vo.setDischargeItem(dischargeItem.toString());
|
|
}
|
|
|
|
private List<FormWhereCondition> buildConditions(JSONObject params) {
|
|
List<FormWhereCondition> conditions = new ArrayList<>();
|
|
if(StringUtils.isNotBlank(params.getString("cusNo"))) {
|
|
conditions.add(FormWhereCondition.build().display("承租方编号").value(params.getString("cusNo")));
|
|
}
|
|
return conditions;
|
|
}
|
|
}
|