package com.qhyf.app.bl.controller; import club.newepoch.persistent.db.common.Db; import club.newepoch.persistent.db.pojo.Record; import club.newepoch.utils.StringUtils; import com.jfinal.core.ActionKey; import com.jfinal.core.action.Rest; import com.jfinal.core.pojo.RestMethod; import com.qhyf.app.bl.base.controller.QhyfController; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** * 获取保理付确认书信息的接口 * * @author lx */ public class InterfaceFactoringPayConfirmationController extends QhyfController { /** * 获取付款确认书的信息 */ @Rest(method = RestMethod.POST) @ActionKey("/api/qhyf/payConfirm/info/") public void PayConfirmationInformation() { //返回json数据 JSONObject returnJson = new JSONObject(); JSONArray data = new JSONArray(); JSONArray invoiceNodata = new JSONArray(); // 数据校验是否成功标识 boolean checkFlag = true; StringBuffer errmsgSb = new StringBuffer(); try { //获取核心企业 String coreEnterpriseId = this.getPara("coreEnterpriseId"); //获取金融机构 String financialInstitutionsId = this.getPara("financialInstitutionsId"); //获取期数 String period = this.getPara("period"); // 获取付款确认书编号 String payNo = this.getPara("payNo"); // 当payId 为空,核心企业,期数,金融机构不能为空 if (StringUtils.isBlank(payNo)) { if (StringUtils.isBlank(coreEnterpriseId)) { errmsgSb.append("核心企业不能为空;"); checkFlag = false; } if (StringUtils.isBlank(financialInstitutionsId)) { errmsgSb.append("金融机构不能为空;"); checkFlag = false; } if (StringUtils.isBlank(period)) { errmsgSb.append("期数不能为空;"); checkFlag = false; } } // 期数存在的情况下,校验期数是否为数值 if (checkFlag) { if (!checkPeriods(period.toString())) { errmsgSb.append("期数参数值不合法"); returnJson.put("errcode", "3002"); checkFlag = false; } }else { //缺少参数 returnJson.put("errcode", "3001"); } // 校验通过 if (checkFlag) { // 构造查询sql String sql= "SELECT " + " a.uuid, " + " a.pay_id AS pay_no, " + " a.core_enterprise_id, " + " b.core_enterprise_name, " + " a.financial_institutions_id, " + " c.financial_institutions_name, " + " a.signing_body_id, " + " d.sign_body_name, " + " a.periods, " + " a.suppliers_id, " + " e.suppliers_name, " + " a.item_company_id, " + " f.item_company_name, " + " g.region_name, " + " a.contract_type, " + " a.due_date, " + " a.account_receivable " + "FROM " + " biz_pay_comfirm_info a, " + " biz_core_enterprise b, " + " biz_financial_institutions c, " + " biz_signing_body d, " + " biz_suppliers e, " + " biz_item_company f, " + " biz_item_region g " + "WHERE " + " a.core_enterprise_id = b.uuid " + "AND a.financial_institutions_id = c.uuid " + "AND a.signing_body_id = d.uuid " + "AND a.suppliers_id = e.uuid " + "AND a.item_company_id = f.uuid " + "AND f.region_id = g.uuid " + "AND a.sys_status = 1 " + "AND b.sys_status = 1 " + "AND c.sys_status = 1 " + "AND d.sys_status = 1 " + "AND f.sys_status = 1 " + "AND g.sys_status = 1 " + "AND a.uuid NOT IN ( " + " SELECT " + " pay_id " + " FROM " + " biz_rollback_pay " + " WHERE " + " sys_status = 1 " + " AND biz_state <> 15 " + ")" ; // where条件 String where = ""; List<String> paras = new ArrayList<String>(); // 核心企业ID不为空时新增查询条件 if (StringUtils.notBlank(coreEnterpriseId)) { where += "and a.core_enterprise_id = ? "; paras.add(coreEnterpriseId); } // 金融机构类型不为空时新增查询条件 if (StringUtils.notBlank(financialInstitutionsId)) { where += "and a.financial_institutions_id = ? "; paras.add(financialInstitutionsId); } // 期数不为空时新增查询条件 if (StringUtils.notBlank(period)) { where += "and a.periods = ? "; paras.add(period); } // 付款确认书编号不为空时新增查询条件 if (StringUtils.notBlank(payNo)) { where += "and a.pay_id = ? "; paras.add(payNo); } List<Record> payConfirmationrecordList = Db.find(sql + where, paras.toArray()); // 当查询结果不为空时 if (!payConfirmationrecordList.isEmpty()) { for (Record rd : payConfirmationrecordList) { //查询 发票号 String invoiceNoSql = "SELECT " + " h.invoice_no, " + " a.pay_id " + " FROM " + " biz_pay_comfirm_info a, " + " biz_invoice_info h " + " WHERE " + " a.uuid = h.pay_id " + "and a.sys_status = 1 " + "AND h.sys_status = 1" + " AND a.uuid = ? "; //获取发票号 List<Record> invoiceNoList = Db.find(invoiceNoSql, rd.getStr("uuid")); JSONObject json = new JSONObject(); // 核心企业 json.put("core_enterprise_name", rd.get("coreEnterpriseName")); // 金融机构名称 json.put("financial_institutions_name", rd.get("financialInstitutionsName")); // 签约主体 json.put("signing_body_name", rd.get("signBodyName")); json.put("periods", rd.get("periods")); json.put("pay_no", rd.get("payNo")); json.put("suppliers_name", rd.get("suppliersName")); json.put("item_company_name", rd.get("itemCompanyName")); json.put("suppliers_id", rd.get("suppliersId")); json.put("item_company_id", rd.get("itemCompanyId")); json.put("item_region", rd.get("regionName")); json.put("contract_type", rd.get("contractType")); json.put("due_date", rd.get("dueDate").toString()); json.put("account_receivable", rd.get("accountReceivable")); //放入发票号 for (Record invoiceNo : invoiceNoList) { JSONObject invoiceNoJson = new JSONObject(); invoiceNoJson.put("invoiceNo", invoiceNo.get("invoiceNo")); invoiceNodata.add(invoiceNoJson); } json.put("invoiceList", invoiceNodata); // 将json加进响应体 data.add(json); } returnJson.put("errcode", "0"); returnJson.put("errmsg", ""); } else { returnJson.put("errcode", "3003"); returnJson.put("errmsg", "未获取到付款确认书信息,请检查请求参数是否正确"); } } else { //校验不通过 returnJson.put("errmsg", errmsgSb.toString()); } returnJson.put("data", data); } catch (Exception e) { // 异常处理 returnJson.put("errcode", "9999"); returnJson.put("errmsg", "内部服务处理异常!"); returnJson.put("data", data); } //返回结果 this.renderJson(returnJson); } /** * 期数校验 * @param param 需要校验的参数 * @return isCheckThrough 是否满足校验规则 */ private boolean checkPeriods(String param) { boolean isCheckThrough = StringUtils.matchRegex(param, "^\d+$"); if (isCheckThrough) { return true; } else { return false; } } }
{
"errcode": "0",
"errmsg": "",
"data": [
{
"core_enterprise_name": "万科",
"financial_institutions_name": "方正万科ABS",
"signing_body_name": "深圳市前海一方商业保理有限公司",
"periods": 1002,
"pay_no": "ZD-ABS00001-2018-0002",
"suppliers_name": "四川正丰泰建设工程有限公司",
"item_company_name": "朱德勇测试分公司",
"suppliers_id": "67d38832e14f47aea5198d40c5368a1c",
"item_company_id": "976f66dfc65143c2ad11eff5cbecf619",
"item_region": "成都",
"contract_type": "E",
"due_date": "2020-01-01",
"account_receivable": 100000,
"invoiceList": [
{
"invoiceNo": "02751761"
}
]
}
]
}
{
"errcode": "3001",
"errmsg": "核心企业不能为空;金融机构不能为空;期数不能为空;",
"data": []
}
{
"errcode": "3002",
"errmsg": "期数参数值不合法",
"data": []
}