|
@@ -146,27 +146,23 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SupplierStatisticsResult> supplierStatistics(DateStatisticsResult dateStatisticsResult) {
|
|
|
+ public List<SupplierStatisticsResult> supplierStatistics(Condition condition) {
|
|
|
// 初始化返回值
|
|
|
List<SupplierStatisticsResult> result = initSupplierStatisticsResult();
|
|
|
|
|
|
- Integer type = dateStatisticsResult.getType();
|
|
|
- // 历史账期没有需要付款的记录
|
|
|
- if (ObjectUtil.equals(type, 1)) {
|
|
|
+ // 历史账期没有待付款记录
|
|
|
+ if (HISTORICAL_ACCOUNTING_PERIOD.equals(condition.getType())) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- Date beginTime = dateStatisticsResult.getBeginTime();
|
|
|
- Date endTime = dateStatisticsResult.getEndTime();
|
|
|
-
|
|
|
QueryWrapper<Object> wrapper = Wrappers.query();
|
|
|
- splicingContractSelectCondition(wrapper);
|
|
|
|
|
|
- String whereTime = "date_add( c.complete_time , interval c.account_date day)";
|
|
|
+ // 合同筛选
|
|
|
+ contractScreen(wrapper);
|
|
|
+ // 账期筛选
|
|
|
+ accountDateScreen(wrapper, condition);
|
|
|
|
|
|
- wrapper.ge(ObjectUtil.notEqual(type, 2) && ObjectUtil.isNotEmpty(beginTime), whereTime, beginTime)
|
|
|
- .le(ObjectUtil.isNotEmpty(endTime), whereTime, endTime)
|
|
|
- .groupBy("c.supplier_id");
|
|
|
+ wrapper.groupBy("c.supplier_id");
|
|
|
|
|
|
List<SupplierInfo> supplierInfoList = baseMapper.getSupplierInfoList(wrapper);
|
|
|
|
|
@@ -200,6 +196,51 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Map<String, Object> statusStatistics(Condition condition) {
|
|
|
+ // 历史账期没有待付款记录
|
|
|
+ if (HISTORICAL_ACCOUNTING_PERIOD.equals(condition.getType())) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("canLaunch", 0);
|
|
|
+ map.put("needSupplemented", 0);
|
|
|
+ map.put("total", 0);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query();
|
|
|
+
|
|
|
+ // 合同筛选
|
|
|
+ contractScreen(wrapper);
|
|
|
+ // 账期筛选
|
|
|
+ accountDateScreen(wrapper, condition);
|
|
|
+ // 供应商筛选
|
|
|
+ supplierIdScreen(wrapper, condition);
|
|
|
+
|
|
|
+ return baseMapper.statusStatistics(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> cycleStatistics(Condition condition) {
|
|
|
+
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query();
|
|
|
+
|
|
|
+ // 合同筛选
|
|
|
+ contractScreen(wrapper);
|
|
|
+ // 账期筛选
|
|
|
+ accountDateScreen(wrapper, condition);
|
|
|
+ // 供应商筛选
|
|
|
+ supplierIdScreen(wrapper, condition);
|
|
|
+ // 合同状态筛选
|
|
|
+ statusScreen(wrapper, condition);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ Date currentAccountBeginTime = getCurrentAccountBeginTime(date);
|
|
|
+ Date currentAccountEndTime = getCurrentAccountEndTime(date);
|
|
|
+
|
|
|
+ return baseMapper.cycleStatistics(wrapper, currentAccountBeginTime, currentAccountEndTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
|
|
|
// 历史账期没有待付款记录
|
|
@@ -211,21 +252,20 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
|
|
|
QueryWrapper<Object> wrapper = Wrappers.query();
|
|
|
|
|
|
- // 拼接合同查询条件
|
|
|
- splicingContractSelectCondition(wrapper);
|
|
|
-
|
|
|
- // 拼接传入查询条件
|
|
|
- splicingPageWrapper(wrapper, condition);
|
|
|
+ // 合同筛选
|
|
|
+ contractScreen(wrapper);
|
|
|
+ // 账期筛选
|
|
|
+ accountDateScreen(wrapper, condition);
|
|
|
+ // 供应商筛选
|
|
|
+ supplierIdScreen(wrapper, condition);
|
|
|
+ // 合同状态筛选
|
|
|
+ statusScreen(wrapper, condition);
|
|
|
+ // 周期筛选
|
|
|
+ cycleScreen(wrapper, condition, date);
|
|
|
|
|
|
Page<Map<String, Object>> page = baseMapper.getPage(condition.getPage(), wrapper);
|
|
|
|
|
|
- List<Map<String, Object>> records = page.getRecords();
|
|
|
-
|
|
|
- if (records.size() == 0) {
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- for (Map<String, Object> record : records) {
|
|
|
+ for (Map<String, Object> record : page.getRecords()) {
|
|
|
// 赋值付款期限
|
|
|
setTermsPayment(date, record);
|
|
|
// 质检是否完成
|
|
@@ -240,19 +280,6 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 初始化供应商统计结果集
|
|
|
- */
|
|
|
- private List<SupplierStatisticsResult> initSupplierStatisticsResult() {
|
|
|
- List<SupplierStatisticsResult> result = new ArrayList<>();
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- SupplierStatisticsResult supplierStatisticsResult = new SupplierStatisticsResult();
|
|
|
- supplierStatisticsResult.setTitleType(i);
|
|
|
- result.add(supplierStatisticsResult);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 合同付款时间段统计返回值初始化
|
|
|
*
|
|
|
* @param date 当前日期
|
|
@@ -299,6 +326,18 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化供应商统计结果集
|
|
|
+ */
|
|
|
+ private List<SupplierStatisticsResult> initSupplierStatisticsResult() {
|
|
|
+ List<SupplierStatisticsResult> result = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ SupplierStatisticsResult supplierStatisticsResult = new SupplierStatisticsResult();
|
|
|
+ supplierStatisticsResult.setTitleType(i);
|
|
|
+ result.add(supplierStatisticsResult);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 生成返回结果集
|
|
@@ -313,17 +352,6 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 拼接合同查询条件
|
|
|
- */
|
|
|
- private void splicingContractSelectCondition(QueryWrapper<Object> wrapper) {
|
|
|
- wrapper.eq("c.del_flag", StatusConstant.NOT_DELETED)
|
|
|
- .lt("c.pay_status", ContractPayStatusEnum.COMPLETED.getType())
|
|
|
- .and(q -> q.eq("c.account_date", 0)
|
|
|
- .or(w -> w.gt("c.account_date", 0)
|
|
|
- .eq("c.status", ContractStatusEnum.COMPLETED.getType())));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 赋值付款期限
|
|
|
*/
|
|
|
private void setTermsPayment(Date date, Map<String, Object> record) {
|
|
@@ -331,74 +359,96 @@ public class ContractPayServiceImpl extends ServiceImpl<ContractPayMapper, Contr
|
|
|
Date completeTime = Convert.toDate(record.get("completeTime"));
|
|
|
// 账期
|
|
|
Integer accountDate = Convert.toInt(record.get("accountDate"));
|
|
|
- // 完成时间到今天距离多少天
|
|
|
- long day = DateUtil.betweenDay(completeTime, date, true);
|
|
|
+
|
|
|
+ long day = completeTime == null ? 0 : DateUtil.betweenDay(completeTime, date, true);
|
|
|
|
|
|
// 赋值付钱期限(距离账期还要多少天,负值为超过付款日期多少天)
|
|
|
record.put("termsPayment", accountDate - day);
|
|
|
}
|
|
|
|
|
|
+ // 付款时间:最后入库时间 + 账期
|
|
|
+ private static final String whereTime = "date_add( c.complete_time , interval c.account_date day)";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同筛选
|
|
|
+ */
|
|
|
+ private void contractScreen(QueryWrapper<Object> wrapper) {
|
|
|
+ wrapper.eq("c.del_flag", StatusConstant.NOT_DELETED)
|
|
|
+ .lt("c.pay_status", ContractPayStatusEnum.COMPLETED.getType())
|
|
|
+ .and(q -> q.eq("c.account_date", 0)
|
|
|
+ .or(w -> w.gt("c.account_date", 0)
|
|
|
+ .eq("c.status", ContractStatusEnum.COMPLETED.getType())));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 拼接分页查询条件
|
|
|
+ * 账期筛选
|
|
|
*/
|
|
|
- private void splicingPageWrapper(QueryWrapper<Object> wrapper, Condition condition) {
|
|
|
+ private void accountDateScreen(QueryWrapper<Object> wrapper, Condition condition) {
|
|
|
|
|
|
- Long supplierId = condition.getLong("supplierId");
|
|
|
Integer type = condition.getType();
|
|
|
- String beginTime = condition.getStr("beginTime");
|
|
|
- String endTime = condition.getStr("endTime");
|
|
|
+ Date beginTime = condition.getBeginTime();
|
|
|
+ Date endTime = condition.getEndTime();
|
|
|
+
|
|
|
+ wrapper.func(q -> {
|
|
|
+ if (CURRENT_ACCOUNTING_PERIOD.equals(type)) {
|
|
|
+ q.le(whereTime, endTime);
|
|
|
+ } else if (FUTURE_ACCOUNTING_PERIOD.equals(type)) {
|
|
|
+ q.between(whereTime, beginTime, endTime);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商筛选
|
|
|
+ */
|
|
|
+ private void supplierIdScreen(QueryWrapper<Object> wrapper, Condition condition) {
|
|
|
+ Long supplierId = condition.getLong("supplierId");
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(supplierId), "c.supplier_id", supplierId);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 合同状态筛选
|
|
|
+ */
|
|
|
+ private void statusScreen(QueryWrapper<Object> wrapper, Condition condition) {
|
|
|
Integer status = condition.getStatus();
|
|
|
- Integer accountStatus = condition.getInt("accountStatus");
|
|
|
+ wrapper.func(q -> {
|
|
|
+ // 可发起
|
|
|
+ if (ObjectUtil.equals(status, 1)) {
|
|
|
+ q.apply("c.apply_pay_amount = 0 " +
|
|
|
+ "and t.batchCount = t.qualityTestingCount " +
|
|
|
+ "and t.contractFileCount > 0 " +
|
|
|
+ "and c.invoice_amount >= c.adjust_amount");
|
|
|
+ }
|
|
|
+ // 待补齐
|
|
|
+ else if (ObjectUtil.equals(status, 2)) {
|
|
|
+ q.apply("t.batchCount != t.qualityTestingCount " +
|
|
|
+ "or t.contractFileCount <= 0 " +
|
|
|
+ "or c.invoice_amount < c.adjust_amount");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- Date date = new Date();
|
|
|
+ /**
|
|
|
+ * 周期筛选
|
|
|
+ */
|
|
|
+ private void cycleScreen(QueryWrapper<Object> wrapper, Condition condition, Date date) {
|
|
|
|
|
|
- // 付款时间:最后入库时间 + 账期
|
|
|
- String whereTime = "date_add( c.complete_time , interval c.account_date day)";
|
|
|
-
|
|
|
- wrapper
|
|
|
- // 供应商
|
|
|
- .eq(ObjectUtil.isNotEmpty(supplierId), "c.supplier_id", supplierId)
|
|
|
- // 账期
|
|
|
- .func(type != null, q -> {
|
|
|
- if (CURRENT_ACCOUNTING_PERIOD.equals(type)) {
|
|
|
- q.le(whereTime, endTime);
|
|
|
- } else {
|
|
|
- q.between(whereTime, beginTime, endTime);
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- .func(q -> {
|
|
|
- // 可发起
|
|
|
- if (ObjectUtil.equals(status, 1)) {
|
|
|
- q.apply("c.apply_pay_amount = 0 " +
|
|
|
- "and t.batchCount = t.qualityTestingCount " +
|
|
|
- "and t.contractFileCount > 0 " +
|
|
|
- "and c.invoice_amount >= c.adjust_amount");
|
|
|
- }
|
|
|
- // 待补齐
|
|
|
- else if (ObjectUtil.equals(status, 2)) {
|
|
|
- q.apply("t.batchCount != t.qualityTestingCount " +
|
|
|
- "or t.contractFileCount <= 0 " +
|
|
|
- "or c.invoice_amount < c.adjust_amount");
|
|
|
- }
|
|
|
- })
|
|
|
+ Integer cycleType = condition.getInt("cycleType");
|
|
|
|
|
|
- .func(q -> {
|
|
|
- // 本周期
|
|
|
- if (ObjectUtil.equals(accountStatus, 1)) {
|
|
|
- q.between(whereTime, getCurrentAccountBeginTime(date), getCurrentAccountEndTime(date));
|
|
|
- }
|
|
|
- // 上周期顺延
|
|
|
- else if (ObjectUtil.equals(accountStatus, 2)) {
|
|
|
- q.lt(whereTime, getCurrentAccountBeginTime(date));
|
|
|
- }
|
|
|
- // 其他(未来账期)
|
|
|
- else if (ObjectUtil.equals(accountStatus, 3)) {
|
|
|
- q.gt(whereTime, getCurrentAccountEndTime(date));
|
|
|
- }
|
|
|
- })
|
|
|
- ;
|
|
|
+ wrapper.func(q -> {
|
|
|
+ // 本周期
|
|
|
+ if (ObjectUtil.equals(cycleType, 1)) {
|
|
|
+ q.between(whereTime, getCurrentAccountBeginTime(date), getCurrentAccountEndTime(date));
|
|
|
+ }
|
|
|
+ // 上周期顺延
|
|
|
+ else if (ObjectUtil.equals(cycleType, 2)) {
|
|
|
+ q.lt(whereTime, getCurrentAccountBeginTime(date));
|
|
|
+ }
|
|
|
+ // 其他(未来账期)
|
|
|
+ else if (ObjectUtil.equals(cycleType, 3)) {
|
|
|
+ q.gt(whereTime, getCurrentAccountEndTime(date));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|