xml源码:
<select id="getAllPeriodStatisticsList" resultType="Map">
select
<foreach collection="fieldList" index="index" item="item" separator=",">
BigToInt(ifnull( sum( case when w.year = #{year} and w.number= #{item.number} then 1 else 0 end), 0)) as ${item.number}
</foreach>
from ssr_person_warning w
left join ssr_archive_person a on a.userId = w.userId
left join ssr_organization_ext ext on ext.id = a.organizationId
where a.isCurrent = 1
and w.state = 1
<if test="field != null and field !=''"> and ext.${field} = #{districtCode} </if>
</select>
java源码:
public Map<String, Integer> getAllPeriodStatisticsList(String year, String districtCode) {
Map<String, Integer> map = new HashMap<>(8);
List<Map<String, Object>> periods = PeriodService.getPeriods(year,
TemplateDetailService.PERMONTH);
if (periods == null) {
return map;
}
Map<String, Object> param = new HashMap<>(8);
param.put("fieldList", periods);
param.put("year", year);
param.put("field", StringUtils.isBlank(districtCode) ? null :
DistrictService.getTypeByCode(districtCode) + "Code");
param.put("districtCode", districtCode);
map = sqlSessionTemplate.selectOne(NS + "getAllPeriodStatisticsList", param);
return map;
}
返回的map:
日志sql直接在navicat运行:
返回的有问题,
是有问题啊,但我不知道怎么造成的啊。