refactor(oa/erp): 重构合同台账报表查询逻辑

dev
Yangk 4 days ago
parent 8fad40933e
commit 4654c9ffbd

@ -1,6 +1,9 @@
package org.dromara.oa.erp.mapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.dromara.oa.erp.domain.ErpContractInfo;
import org.dromara.oa.erp.domain.vo.ContractLedgerReportVo;
import java.util.List;
@ -13,6 +16,6 @@ public interface ContractLedgerReportMapper {
/**
*
*/
List<ContractLedgerReportVo> selectContractLedgerList(@Param("bo") ContractLedgerReportVo bo);
List<ContractLedgerReportVo> selectContractLedgerList(@Param(Constants.WRAPPER) Wrapper<ErpContractInfo> wrapper);
}

@ -1,14 +1,19 @@
package org.dromara.oa.erp.service.impl;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.oa.erp.domain.ErpContractInfo;
import org.dromara.oa.erp.domain.vo.ContractLedgerReportVo;
import org.dromara.oa.erp.mapper.ContractLedgerReportMapper;
import org.dromara.oa.erp.service.IContractLedgerReportService;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* Service
@ -19,14 +24,42 @@ public class ContractLedgerReportServiceImpl implements IContractLedgerReportSer
private final ContractLedgerReportMapper reportMapper;
private MPJLambdaWrapper<ErpContractInfo> buildQueryWrapper(ContractLedgerReportVo bo) {
MPJLambdaWrapper<ErpContractInfo> lqw = JoinWrappers.lambda(ErpContractInfo.class);
lqw.eq(ErpContractInfo::getDelFlag, "0");
if (bo.getContractIdList() != null && !bo.getContractIdList().isEmpty()) {
lqw.in(ErpContractInfo::getContractId, bo.getContractIdList());
}
lqw.like(StringUtils.isNotBlank(bo.getCustomerContractCode()), ErpContractInfo::getCustomerContractCode, bo.getCustomerContractCode());
lqw.like(StringUtils.isNotBlank(bo.getInternalContractCode()), ErpContractInfo::getInternalContractCode, bo.getInternalContractCode());
lqw.like(StringUtils.isNotBlank(bo.getProjectCode()), "p.project_code", bo.getProjectCode());
lqw.eq(StringUtils.isNotBlank(bo.getBusinessDirection()), ErpContractInfo::getBusinessDirection, bo.getBusinessDirection());
Map<String, Object> params = bo.getParams();
if (params != null) {
if (params.get("beginContractDate") != null && StringUtils.isNotBlank(params.get("beginContractDate").toString())) {
lqw.apply("DATE_FORMAT(t.contract_date,'%y%m%d') >= DATE_FORMAT({0},'%y%m%d')", params.get("beginContractDate").toString());
}
if (params.get("endContractDate") != null && StringUtils.isNotBlank(params.get("endContractDate").toString())) {
lqw.apply("DATE_FORMAT(t.contract_date,'%y%m%d') <= DATE_FORMAT({0},'%y%m%d')", params.get("endContractDate").toString());
}
}
lqw.orderByDesc(ErpContractInfo::getCreateTime);
return lqw;
}
@Override
public TableDataInfo<ContractLedgerReportVo> queryContractLedgerList(ContractLedgerReportVo bo) {
List<ContractLedgerReportVo> list = reportMapper.selectContractLedgerList(bo);
MPJLambdaWrapper<ErpContractInfo> lqw = buildQueryWrapper(bo);
List<ContractLedgerReportVo> list = reportMapper.selectContractLedgerList(lqw);
return TableDataInfo.build(list);
}
@Override
public List<ContractLedgerReportVo> queryContractLedgerAll(ContractLedgerReportVo bo) {
return reportMapper.selectContractLedgerList(bo);
MPJLambdaWrapper<ErpContractInfo> lqw = buildQueryWrapper(bo);
return reportMapper.selectContractLedgerList(lqw);
}
}

@ -6,25 +6,25 @@
<select id="selectContractLedgerList" resultType="org.dromara.oa.erp.domain.vo.ContractLedgerReportVo">
SELECT
c.contract_id,
t.contract_id,
<!-- 合同信息 -->
c.internal_contract_code,
c.external_contract_code,
c.customer_contract_code,
DATE_FORMAT(c.contract_date, '%Y-%m-%d') AS contract_date,
DATE_FORMAT(c.create_time, '%Y-%m') AS month,
c.order_contract_code,
c.project_contract_code,
t.internal_contract_code,
t.external_contract_code,
t.customer_contract_code,
DATE_FORMAT(t.contract_date, '%Y-%m-%d') AS contract_date,
DATE_FORMAT(t.create_time, '%Y-%m') AS month,
t.order_contract_code,
t.project_contract_code,
cust.customer_name AS customer_name,
mat_sub.product_name AS product_name,
c.mesnac_contract_price,
c.total_price,
c.payment_method,
c.delivery_start,
c.warranty_period,
t.mesnac_contract_price,
t.total_price,
t.payment_method,
t.delivery_start,
t.warranty_period,
u1.nick_name AS contract_manager_name,
d.dept_name AS contract_dept_name,
c.business_direction,
t.business_direction,
<!-- 项目基本信息 -->
p.project_code,
p.project_name,
@ -32,48 +32,21 @@
pt.type_name,
<!-- 备注 -->
fcust.customer_name AS final_customer_name
FROM erp_contract_info c
FROM erp_contract_info t
LEFT JOIN (
SELECT contract_id, GROUP_CONCAT(DISTINCT product_name SEPARATOR '') AS product_name
FROM erp_contract_material
WHERE del_flag = '0'
GROUP BY contract_id
) mat_sub ON c.contract_id = mat_sub.contract_id
LEFT JOIN crm_customer_info cust ON c.one_customer_id = cust.customer_id AND cust.del_flag = '0'
LEFT JOIN sys_user u1 ON u1.user_id = c.contract_manager_id
LEFT JOIN sys_dept d ON d.dept_id = c.contract_dept_id
LEFT JOIN erp_project_contracts pc ON pc.contract_id = c.contract_id AND pc.del_flag = '0'
) mat_sub ON t.contract_id = mat_sub.contract_id
LEFT JOIN crm_customer_info cust ON t.one_customer_id = cust.customer_id AND cust.del_flag = '0'
LEFT JOIN sys_user u1 ON u1.user_id = t.contract_manager_id
LEFT JOIN sys_dept d ON d.dept_id = t.contract_dept_id
LEFT JOIN erp_project_contracts pc ON pc.contract_id = t.contract_id AND pc.del_flag = '0'
LEFT JOIN erp_project_info p ON p.project_id = pc.project_id AND p.del_flag = '0'
LEFT JOIN sys_user u2 ON u2.user_id = p.manager_id
LEFT JOIN erp_project_type pt ON pt.project_type_id = p.project_type_id
LEFT JOIN crm_customer_info fcust ON c.final_customer_id = fcust.customer_id AND fcust.del_flag = '0'
<where>
c.del_flag = '0'
<if test="bo.contractIdList != null and bo.contractIdList.size() > 0">
AND c.contract_id IN
<foreach collection="bo.contractIdList" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="bo.customerContractCode != null and bo.customerContractCode != ''">
AND c.customer_contract_code LIKE CONCAT('%', #{bo.customerContractCode}, '%')
</if>
<if test="bo.internalContractCode != null and bo.internalContractCode != ''">
AND c.internal_contract_code LIKE CONCAT('%', #{bo.internalContractCode}, '%')
</if>
<if test="bo.projectCode != null and bo.projectCode != ''">
AND p.project_code LIKE CONCAT('%', #{bo.projectCode}, '%')
</if>
<if test="bo.businessDirection != null and bo.businessDirection != ''">
AND c.business_direction = #{bo.businessDirection}
</if>
<if test="bo.params != null and bo.params.beginContractDate != null and bo.params.beginContractDate != ''">
AND DATE_FORMAT(c.contract_date,'%y%m%d') &gt;= DATE_FORMAT(#{bo.params.beginContractDate},'%y%m%d')
</if>
<if test="bo.params != null and bo.params.endContractDate != null and bo.params.endContractDate != ''">
AND DATE_FORMAT(c.contract_date,'%y%m%d') &lt;= DATE_FORMAT(#{bo.params.endContractDate},'%y%m%d')
</if>
</where>
ORDER BY c.create_time DESC
LEFT JOIN crm_customer_info fcust ON t.final_customer_id = fcust.customer_id AND fcust.del_flag = '0'
${ew.customSqlSegment}
</select>
</mapper>

Loading…
Cancel
Save