物管理后端
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.

93 lines
4.9 KiB

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.thing.carbon.pub.mapper.CarbonPubSupplierMapper">
  4. <sql id="condition">
  5. <where>
  6. <if test="params.name != null and params.name != '' ">
  7. and cps.name like concat('%', #{params.name}, '%')
  8. </if>
  9. <if test="params.regionId != null">
  10. and cps.region_id = #{params.regionId}::bigint
  11. </if>
  12. <if test="params.productType != null and params.productType != '' ">
  13. and temp.product_type like concat('%', #{params.productType}, '%')
  14. </if>
  15. </where>
  16. </sql>
  17. <select id="countBy" resultType="java.lang.Long">
  18. select count(cps.*)
  19. from carbon_pub_supplier cps
  20. left join (select string_agg(distinct industry_sub, ',') as product_type, tenant_code
  21. from iot_carbon_production_variety
  22. group by tenant_code) temp on cps.code = temp.tenant_code
  23. <include refid="condition" />
  24. </select>
  25. <select id="selectBy" resultType="com.thing.carbon.pub.dto.CarbonPubSupplierDTO">
  26. select id, name, code, access_token, region_id, points, temp.product_type, t2.records_count
  27. from carbon_pub_supplier cps
  28. left join (select string_agg(distinct industry_sub, ',') as product_type, tenant_code
  29. from iot_carbon_production_variety
  30. group by tenant_code) temp on cps.code = temp.tenant_code
  31. left join (select sum(pr_unit) as records_count, tenant_code
  32. from (select count(distinct pr_code) as pr_unit, tenant_code, pr_code
  33. from carbon_pub_production_result
  34. group by product_id, pr_code, tenant_code) t1
  35. group by tenant_code) t2 on cps.code = t2.tenant_code
  36. <include refid="condition" />
  37. limit #{params.limit} offset #{params.offset}
  38. </select>
  39. <select id="avgCarbonOfAllProduct" resultType="java.math.BigDecimal">
  40. select COALESCE( avg(carbon), 0 ) AS carbon
  41. from (select tenant_code,
  42. sum(type1_carbon_avg)
  43. + sum(type1_usage_avg)
  44. + sum(type2_carbon_avg)
  45. + sum(type3_carbon_avg)
  46. + sum(type4_carbon_avg)
  47. + sum(type5_carbon_avg)
  48. + sum(type6_carbon_avg)
  49. + sum(type6_fq_carbon_avg) as carbon
  50. from (select product_id,
  51. product_name,
  52. pr_code,
  53. carbon_type,
  54. tenant_code,
  55. case carbon_type when '1' then carbon_avg else 0 end as type1_carbon_avg,
  56. case carbon_type when '1' then usage_avg else 0 end as type1_usage_avg,
  57. case carbon_type when '2' then carbon_avg else 0 end as type2_carbon_avg,
  58. case carbon_type when '3' then carbon_avg else 0 end as type3_carbon_avg,
  59. case carbon_type when '4' then carbon_avg else 0 end as type4_carbon_avg,
  60. case carbon_type when '5' then carbon_avg else 0 end as type5_carbon_avg,
  61. case carbon_type when '6' then carbon_avg else 0 end as type6_carbon_avg,
  62. case carbon_type when '6' then fq_carbon_avg else 0 end as type6_fq_carbon_avg
  63. from (select product_id,
  64. product_name,
  65. pr_code,
  66. carbon_type,
  67. tenant_code,
  68. sum(carbon_avg) as carbon_avg,
  69. sum(usage_avg) as usage_avg,
  70. sum(fq_carbon_avg) as fq_carbon_avg
  71. from carbon_pub_production_result
  72. <where>
  73. <if test="tenantCode!=null">
  74. and tenant_code = #{tenantCode}
  75. </if>
  76. <if test="start!=null">
  77. and finish_time >= #{start}
  78. </if>
  79. <if test="end!=null">
  80. and finish_time &lt;= #{end}
  81. </if>
  82. </where>
  83. group by product_id, product_name, pr_code, carbon_type, tenant_code) as t1) as t2
  84. group by product_id, product_name, pr_code, tenant_code) as t3
  85. where tenant_code = #{tenantCode}
  86. </select>
  87. </mapper>