You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
4.9 KiB
94 lines
4.9 KiB
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
|
<mapper namespace="com.thing.carbon.pub.mapper.CarbonPubSupplierMapper">
|
|
|
|
<sql id="condition">
|
|
<where>
|
|
<if test="params.name != null and params.name != '' ">
|
|
and cps.name like concat('%', #{params.name}, '%')
|
|
</if>
|
|
<if test="params.regionId != null">
|
|
and cps.region_id = #{params.regionId}::bigint
|
|
</if>
|
|
<if test="params.productType != null and params.productType != '' ">
|
|
and temp.product_type like concat('%', #{params.productType}, '%')
|
|
</if>
|
|
</where>
|
|
</sql>
|
|
|
|
<select id="countBy" resultType="java.lang.Long">
|
|
select count(cps.*)
|
|
from carbon_pub_supplier cps
|
|
left join (select string_agg(distinct industry_sub, ',') as product_type, tenant_code
|
|
from iot_carbon_production_variety
|
|
group by tenant_code) temp on cps.code = temp.tenant_code
|
|
<include refid="condition" />
|
|
</select>
|
|
|
|
<select id="selectBy" resultType="com.thing.carbon.pub.dto.CarbonPubSupplierDTO">
|
|
select id, name, code, access_token, region_id, points, temp.product_type, t2.records_count
|
|
from carbon_pub_supplier cps
|
|
left join (select string_agg(distinct industry_sub, ',') as product_type, tenant_code
|
|
from iot_carbon_production_variety
|
|
group by tenant_code) temp on cps.code = temp.tenant_code
|
|
left join (select sum(pr_unit) as records_count, tenant_code
|
|
from (select count(distinct pr_code) as pr_unit, tenant_code, pr_code
|
|
from carbon_pub_production_result
|
|
group by product_id, pr_code, tenant_code) t1
|
|
group by tenant_code) t2 on cps.code = t2.tenant_code
|
|
<include refid="condition" />
|
|
limit #{params.limit} offset #{params.offset}
|
|
</select>
|
|
|
|
<select id="avgCarbonOfAllProduct" resultType="java.math.BigDecimal">
|
|
select COALESCE( avg(carbon), 0 ) AS carbon
|
|
from (select tenant_code,
|
|
sum(type1_carbon_avg)
|
|
+ sum(type1_usage_avg)
|
|
+ sum(type2_carbon_avg)
|
|
+ sum(type3_carbon_avg)
|
|
+ sum(type4_carbon_avg)
|
|
+ sum(type5_carbon_avg)
|
|
+ sum(type6_carbon_avg)
|
|
+ sum(type6_fq_carbon_avg) as carbon
|
|
from (select product_id,
|
|
product_name,
|
|
pr_code,
|
|
carbon_type,
|
|
tenant_code,
|
|
case carbon_type when '1' then carbon_avg else 0 end as type1_carbon_avg,
|
|
case carbon_type when '1' then usage_avg else 0 end as type1_usage_avg,
|
|
case carbon_type when '2' then carbon_avg else 0 end as type2_carbon_avg,
|
|
case carbon_type when '3' then carbon_avg else 0 end as type3_carbon_avg,
|
|
case carbon_type when '4' then carbon_avg else 0 end as type4_carbon_avg,
|
|
case carbon_type when '5' then carbon_avg else 0 end as type5_carbon_avg,
|
|
case carbon_type when '6' then carbon_avg else 0 end as type6_carbon_avg,
|
|
case carbon_type when '6' then fq_carbon_avg else 0 end as type6_fq_carbon_avg
|
|
from (select product_id,
|
|
product_name,
|
|
pr_code,
|
|
carbon_type,
|
|
tenant_code,
|
|
sum(carbon_avg) as carbon_avg,
|
|
sum(usage_avg) as usage_avg,
|
|
sum(fq_carbon_avg) as fq_carbon_avg
|
|
from carbon_pub_production_result
|
|
<where>
|
|
<if test="tenantCode!=null">
|
|
and tenant_code = #{tenantCode}
|
|
</if>
|
|
<if test="start!=null">
|
|
and finish_time >= #{start}
|
|
</if>
|
|
<if test="end!=null">
|
|
and finish_time <= #{end}
|
|
</if>
|
|
</where>
|
|
group by product_id, product_name, pr_code, carbon_type, tenant_code) as t1) as t2
|
|
group by product_id, product_name, pr_code, tenant_code) as t3
|
|
where tenant_code = #{tenantCode}
|
|
</select>
|
|
|
|
|
|
</mapper>
|