问题描述
传进来的List<Object>数据在sql层面处理并将Object的某个属性加入返回列中(merchants)
List<DetailedReportRespVO> selectDetailedReport(@Param("endDate") String endDate,
@Param("merchants") List<InformationReportDTO> merchants);
public class InformationReportDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "企业编号")
private String merchantNo;
@ApiModelProperty(value = "企业名称")
private String name;
}
?查询的表中没有企业名称列,此数据是之前传入,并且返回是个list且比较大,所以在sql层处理比较好
public class DetailedReportRespVO implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "企业编号")
@ApiModelProperty(value = "企业编号")
private String merchantNo;
@Excel(name = "企业名称")
@ApiModelProperty(value = "企业名称")
private String name;
@Excel(name = "员工姓名")
@ApiModelProperty(value = "员工姓名")
private String userName;
。。。。。。。。。。。。。。。。。。。。。。。。。。。
解决方案:
mybatis将对象参数转临时表join
<select id="selectDetailedReport"
resultType="com.erp.payroll.common.model.payroll.res.DetailedReportRespVO">
SELECT DISTINCT
tem.name as name ,
t.merchant_no AS merchantNo,
t.NAME AS userName,
t.mobile AS mobile,
t.cert_no AS certNo,
t.bank_name AS bankName,
t.bank_card AS bankCard
FROM
`t_payroll_detail` t
left JOIN t_payroll tp ON tp.merchant_no = t.merchant_no
left JOIN
<foreach collection="merchants" item="merchant" index="index" separator="union" open="(" close=")">
select
#{merchant.merchantNo} as merchantNo,
#{merchant.name} as name
</foreach>
as tem
on t.merchant_no = tem.merchantNo
WHERE
tp.merchant_no in
<foreach collection="merchants" item="merchant" separator="," open="(" close=")">
#{merchant.merchantNo, jdbcType = VARCHAR}
</foreach>
AND concat( tp.pay_year, '-', LPAD( tp.pay_month, 2, 0 ) ) = #{endDate}
AND t.bank_status = 1
AND t.`status` = 0;
</select>
<foreach collection="merchants" item="merchant" index="index" separator="union" open="(" close=")">
select
#{merchant.merchantNo} as merchantNo,
#{merchant.name} as name
</foreach>
|