YZProjectCloud/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/GreenCarbonDataMapper.xml

138 lines
7.2 KiB
XML

<?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.yanzhu.manage.mapper.GreenCarbonDataMapper">
<resultMap type="GreenCarbonData" id="GreenCarbonDataResult">
<result property="id" column="id" />
<result property="comId" column="com_id" />
<result property="projectId" column="project_id" />
<result property="dataDate" column="data_date"/>
<result property="itemId" column="item_id" />
<result property="estimateValue" column="estimate_value" />
<result property="practicalValue" column="practical_value" />
<result property="state" column="state" />
<result property="remark" column="remark" />
<result property="isDel" column="is_del" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="compName" column="comp_name"/>
<result property="projectName" column="project_name"/>
<result property="factorType" column="factor_type"/>
<association property="greenCarbonItem" javaType="GreenCarbonItem">
<id property="id" column="gid"></id>
<result property="carbonFactorType" column="carbon_factor_type" />
<result property="carbonName" column="carbon_name" />
<result property="unit" column="unit" />
<result property="carbonFactor" column="carbon_factor" />
</association>
</resultMap>
<sql id="selectGreenCarbonDataVo">
select gd.id, gd.com_id, gd.project_id,gd.data_date, gd.item_id, gd.estimate_value, gd.practical_value, gd.state,
gd.remark, gd.is_del, gd.create_by, gd.create_time, gd.update_by, gd.update_time,
dp.`dept_name` comp_name,pi.`project_name`,g.id gid,g.carbon_factor_type,g.carbon_name,g.unit,g.carbon_factor
from green_carbon_data gd
LEFT JOIN sys_dept dp ON gd.`com_id`=dp.`dept_id`
LEFT JOIN pro_project_info pi ON gd.`project_id`=pi.`id`
LEFT JOIN green_carbon_item g on g.id=gd.item_id
</sql>
<select id="selectGreenCarbonDataList" parameterType="GreenCarbonData" resultMap="GreenCarbonDataResult">
<include refid="selectGreenCarbonDataVo"/>
<where>
<if test="comId != null "> and gd.com_id = #{comId}</if>
<if test="projectId != null "> and gd.project_id = #{projectId}</if>
<if test="itemId != null "> and gd.item_id = #{itemId}</if>
<if test="estimateValue != null "> and gd.estimate_value = #{estimateValue}</if>
<if test="practicalValue != null "> and gd.practical_value = #{practicalValue}</if>
<if test="state != null "> and gd.state = #{state}</if>
<if test="dataDate != null "> and date(gd.data_date) = date(#{dataDate})</if>
<if test="factorType != null "> and g.carbon_factor_type = #{factorType}</if>
<if test="isDel != null "> and gd.is_del = #{isDel}</if>
</where>
</select>
<select id="groupByFactorType" parameterType="GreenCarbonData" resultMap="GreenCarbonDataResult">
SELECT g.carbon_factor_type factor_type,count(1) id
from green_carbon_data gd
JOIN green_carbon_item g on g.id=gd.item_id
<where>
<if test="comId != null "> and gd.com_id = #{comId}</if>
<if test="projectId != null "> and gd.project_id = #{projectId}</if>
</where>
GROUP BY g.carbon_factor_type
</select>
<select id="selectGreenCarbonDataById" parameterType="Long" resultMap="GreenCarbonDataResult">
<include refid="selectGreenCarbonDataVo"/>
where gd.id = #{id}
</select>
<insert id="insertGreenCarbonData" parameterType="GreenCarbonData">
insert into green_carbon_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="comId != null">com_id,</if>
<if test="projectId != null">project_id,</if>
<if test="dataDate != null">data_date,</if>
<if test="itemId != null">item_id,</if>
<if test="estimateValue != null">estimate_value,</if>
<if test="practicalValue != null">practical_value,</if>
<if test="state != null">state,</if>
<if test="remark != null">remark,</if>
<if test="isDel != null">is_del,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="comId != null">#{comId},</if>
<if test="projectId != null">#{projectId},</if>
<if test="dataDate != null">#{dataDate},</if>
<if test="itemId != null">#{itemId},</if>
<if test="estimateValue != null">#{estimateValue},</if>
<if test="practicalValue != null">#{practicalValue},</if>
<if test="state != null">#{state},</if>
<if test="remark != null">#{remark},</if>
<if test="isDel != null">#{isDel},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateGreenCarbonData" parameterType="GreenCarbonData">
update green_carbon_data
<trim prefix="SET" suffixOverrides=",">
<if test="comId != null">com_id = #{comId},</if>
<if test="projectId != null">project_id = #{projectId},</if>
<if test="dataDate != null">data_date = #{dataDate},</if>
<if test="itemId != null">item_id = #{itemId},</if>
<if test="estimateValue != null">estimate_value = #{estimateValue},</if>
<if test="practicalValue != null">practical_value = #{practicalValue},</if>
<if test="state != null">state = #{state},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteGreenCarbonDataById" parameterType="Long">
delete from green_carbon_data where id = #{id}
</delete>
<delete id="deleteGreenCarbonDataByIds" parameterType="String">
delete from green_carbon_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>