157 lines
8.0 KiB
Java
157 lines
8.0 KiB
Java
|
|
package com.seeyon.apps.assetstenant.bill;
|
||
|
|
|
||
|
|
import com.alibaba.fastjson.JSONObject;
|
||
|
|
import com.seeyon.apps.assetstenant.assets.AssetsService;
|
||
|
|
import com.seeyon.apps.assetstenant.assets.OaAssetsVo;
|
||
|
|
import com.seeyon.apps.assetstenant.config.AssetsTenantConfigProvider;
|
||
|
|
import com.seeyon.apps.assetstenant.constants.RentConstants;
|
||
|
|
import com.seeyon.apps.assetstenant.contract.ContractService;
|
||
|
|
import com.seeyon.apps.assetstenant.po.PageQueryVo;
|
||
|
|
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.math.BigDecimal;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
public class BillService {
|
||
|
|
|
||
|
|
private AssetsTenantConfigProvider configProvider = (AssetsTenantConfigProvider) AppContext.getBean("assetsTenantConfigProvider");
|
||
|
|
private ContractService contractService = (ContractService) AppContext.getBean("contractService");
|
||
|
|
private AssetsService assetsService = (AssetsService) AppContext.getBean("assetsService");
|
||
|
|
|
||
|
|
private String getFormNo() {
|
||
|
|
return configProvider.getBizConfigByKey(RentConstants.CONTRACTBILLFORMNO);
|
||
|
|
}
|
||
|
|
|
||
|
|
private TableContext getTableContext() throws BusinessException {
|
||
|
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
||
|
|
return tableContext;
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getStringValue(Map<String, Object> fieldsMap,String key) {
|
||
|
|
Object o = fieldsMap.get(key);
|
||
|
|
if(o == null) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return o + "";
|
||
|
|
}
|
||
|
|
|
||
|
|
private List<FormWhereCondition> buildConditions(JSONObject params, FormTableBean formTableBean) {
|
||
|
|
List<FormWhereCondition> conditions = new ArrayList<>();
|
||
|
|
if(StringUtils.isNotBlank(params.getString("cusNo"))) {
|
||
|
|
conditions.add(FormWhereCondition.build().display("承租方编号").value(params.getString("cusNo")));
|
||
|
|
}
|
||
|
|
if(StringUtils.isNotBlank(params.getString("billNo"))) {
|
||
|
|
conditions.add(FormWhereCondition.build().display("租赁账单编号").value(params.getString("billNo")));
|
||
|
|
}
|
||
|
|
if(StringUtils.isNotBlank(params.getString("billStatus"))) {
|
||
|
|
if("已缴费".equals(params.getString("billStatus"))) {
|
||
|
|
conditions.add(FormWhereCondition.build().display("账单-收款结果反馈").clauseFactor(ClauseFactor.NOT_NULL));
|
||
|
|
}else {
|
||
|
|
conditions.add(FormWhereCondition.build().display("账单-收款结果反馈").clauseFactor(ClauseFactor.NULL).startWithBracket(true).concatFactor(ClauseFactor.OR));
|
||
|
|
conditions.add(FormWhereCondition.build().display("账单-收款结果反馈").value(EnumMapUtils.getEnumItemValueByDisplayValue(formTableBean, "账单-收款结果反馈", "未收款")).endWithBracket(true));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return conditions;
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<BillVo> queryAllContractBill(List<FormWhereCondition> conditions) throws Exception {;
|
||
|
|
TableContext tableContext = getTableContext();
|
||
|
|
List<FormColumn> datas = FormTableExecutor.query(tableContext, null, conditions,true);
|
||
|
|
List<BillVo> vos = new ArrayList<>();
|
||
|
|
if(datas.size() > 0){
|
||
|
|
for (Object data : datas) {
|
||
|
|
Map<String,Object> map = (Map<String, Object>) data;
|
||
|
|
BillVo billVo = new BillVo();
|
||
|
|
fillVo(map, billVo);
|
||
|
|
vos.add(billVo);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return vos;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Integer countUnpayRentBills(JSONObject params) throws Exception {
|
||
|
|
TableContext tableContext = getTableContext();
|
||
|
|
List<FormWhereCondition> conditions = buildConditions(params,tableContext.getTableBean());
|
||
|
|
conditions.add(FormWhereCondition.build().display("账单-收款结果反馈").clauseFactor(ClauseFactor.NULL).startWithBracket(true).concatFactor(ClauseFactor.OR));
|
||
|
|
conditions.add(FormWhereCondition.build().display("账单-收款结果反馈").value(EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"账单-收款结果反馈","未收款")).endWithBracket(true));
|
||
|
|
Long count = FormTableExecutor.count(tableContext, null,conditions);
|
||
|
|
return count.intValue();
|
||
|
|
}
|
||
|
|
|
||
|
|
public PageQueryVo pageQueryContractBill(JSONObject params) throws Exception {
|
||
|
|
TableContext tableContext = getTableContext();
|
||
|
|
List<FormWhereCondition> conditions = buildConditions(params,tableContext.getTableBean());
|
||
|
|
Integer pageNo = params.getInteger("pageNo") == null ? 1 : params.getInteger("pageNo");
|
||
|
|
Integer pageSize = params.getInteger("pageSize") == null ? 10 : params.getInteger("pageSize");
|
||
|
|
PageQueryVo<BillVo> pageQueryVo = new PageQueryVo();
|
||
|
|
List<FormColumn> datas = FormTableExecutor.pageQuery(tableContext, null,conditions, pageNo, pageSize,true);
|
||
|
|
List<BillVo> vos = new ArrayList<>();
|
||
|
|
Long count = FormTableExecutor.count(tableContext,null, conditions);
|
||
|
|
if(datas.size() > 0){
|
||
|
|
for (Object data : datas) {
|
||
|
|
Map<String,Object> map = (Map<String, Object>) data;
|
||
|
|
BillVo billVo = new BillVo();
|
||
|
|
fillVo(map, billVo);
|
||
|
|
vos.add(billVo);
|
||
|
|
}
|
||
|
|
pageQueryVo.setDatas(vos);
|
||
|
|
pageQueryVo.setTotalCount(count);
|
||
|
|
}
|
||
|
|
return pageQueryVo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public BillVo queryOne(JSONObject params) throws Exception {
|
||
|
|
TableContext tableContext = getTableContext();
|
||
|
|
List<FormWhereCondition> conditions = buildConditions(params,tableContext.getTableBean());
|
||
|
|
FormColumn formColumn = FormTableExecutor.queryOne(tableContext,conditions,true);
|
||
|
|
if(formColumn == null) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
||
|
|
BillVo billVo = new BillVo();
|
||
|
|
fillVo(fieldsMap, billVo);
|
||
|
|
return billVo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void fillVo(Map<String, Object> fieldsMap, BillVo billVo) throws Exception {
|
||
|
|
billVo.setBillType("CONTRACT");
|
||
|
|
billVo.setBillNo(getStringValue(fieldsMap,"租赁账单编号" ));
|
||
|
|
String payStatus = fieldsMap.get("账单-收款结果反馈") == null ? "待缴费" : getStringValue(fieldsMap,"收款结果反馈");
|
||
|
|
billVo.setBillStatus(payStatus);
|
||
|
|
billVo.setCusNo(getStringValue(fieldsMap,"承租方编号"));
|
||
|
|
billVo.setBillStartDate(getStringValue(fieldsMap,"账单-开始日期"));
|
||
|
|
billVo.setContractNo(getStringValue(fieldsMap,"合同编号"));
|
||
|
|
billVo.setBillPayEndDate(getStringValue(fieldsMap,"账单-当前缴费时限"));
|
||
|
|
billVo.setBillEndDate(getStringValue(fieldsMap,"账单-结束日期"));
|
||
|
|
OaAssetsVo oaAssetsVo = assetsService.queryAssetsDetail(getStringValue(fieldsMap,"资产编号"));
|
||
|
|
String asssetsName = null;
|
||
|
|
if(oaAssetsVo != null) {
|
||
|
|
asssetsName = oaAssetsVo.getAssetsName();
|
||
|
|
}
|
||
|
|
String roomNo = fieldsMap.get("门牌号") == null ? "" : fieldsMap.get("门牌号") + "-";
|
||
|
|
String billTerm = "(" + billVo.getBillStartDate() + "-" + billVo.getBillEndDate() + ")";
|
||
|
|
billVo.setBillName(asssetsName + roomNo + billTerm);
|
||
|
|
BigDecimal bigDecimal = (BigDecimal) fieldsMap.get("账单-租费");
|
||
|
|
billVo.setBillAmount(bigDecimal == null ? null : bigDecimal.toString());
|
||
|
|
billVo.setBillPayTime(getStringValue(fieldsMap,"账单-实际收款时间"));
|
||
|
|
}
|
||
|
|
|
||
|
|
private String buildBillName(Map<String, Object> fieldsMap) throws Exception {
|
||
|
|
String contractNo = getStringValue(fieldsMap,"合同编号");
|
||
|
|
String term = contractService.queryContractPayPeriod(contractNo,getStringValue(fieldsMap,"账单-开始日期")) + "-";
|
||
|
|
OaAssetsVo oaAssetsVo = assetsService.queryAssetsDetail(getStringValue(fieldsMap,"资产编号"));
|
||
|
|
String asssetsName = null;
|
||
|
|
if(oaAssetsVo != null) {
|
||
|
|
asssetsName = oaAssetsVo.getAssetsName();
|
||
|
|
}
|
||
|
|
String roomNo = fieldsMap.get("门牌号") == null ? "" : fieldsMap.get("门牌号") + "-";
|
||
|
|
return asssetsName + roomNo + term;
|
||
|
|
}
|
||
|
|
}
|