<?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.thhy.materials.modules.biz.rsbmaterials.mapper.RsbMaterialsMapper">
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
t.id as id,
|
t.rsb_id as rsbId,
|
t.material_name as materialName,
|
t.material_value as materialValue
|
</sql>
|
|
<sql id="condition_query">
|
<where>
|
<trim suffixOverrides=" AND ">
|
<if test="rsbId!=null and rsbId!=''">
|
t.rsb_id = #{rsbId} AND
|
</if>
|
<if test="materialName!=null and materialName!=''">
|
t.material_name = #{materialName} AND
|
</if>
|
<if test="materialValue!=null">
|
t.material_value = #{materialValue} AND
|
</if>
|
</trim>
|
</where>
|
</sql>
|
|
<select id="queryById" resultType="com.thhy.materials.modules.biz.rsbmaterials.entity.RsbMaterials">
|
select <include refid="Base_Column_List" />
|
from t_rsb_materials t
|
where t.id=#{id}
|
</select>
|
|
<select id="queryVersionById" resultType="integer">
|
select version from t_rsb_materials
|
where id=#{id}
|
</select>
|
|
<!--查询列表-->
|
<select id="findList" resultType="com.thhy.materials.modules.biz.rsbmaterials.entity.RsbMaterials">
|
SELECT
|
<include refid="Base_Column_List" />
|
from t_rsb_materials t
|
<include refid="condition_query" />
|
</select>
|
|
<!--查询列表-->
|
<select id="findAll" resultType="com.thhy.materials.modules.biz.rsbmaterials.entity.RsbMaterials">
|
SELECT
|
<include refid="Base_Column_List" />
|
from t_rsb_materials t
|
</select>
|
|
<!--插入操作-->
|
<insert id="insert">
|
insert into t_rsb_materials
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="id != null">
|
id,
|
</if>
|
<if test="rsbId != null">
|
rsb_id,
|
</if>
|
<if test="materialName != null">
|
material_name,
|
</if>
|
<if test="materialValue != null">
|
material_value,
|
</if>
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="id != null">
|
#{id},
|
</if>
|
<if test="rsbId != null">
|
#{rsbId},
|
</if>
|
<if test="materialName != null">
|
#{materialName},
|
</if>
|
<if test="materialValue != null">
|
#{materialValue},
|
</if>
|
</trim>
|
</insert>
|
|
|
<!--更新操作-->
|
<update id="update">
|
update t_rsb_materials
|
<set>
|
<if test="rsbId != null">
|
rsb_id=#{rsbId},
|
</if>
|
<if test="materialName != null">
|
material_name=#{materialName},
|
</if>
|
<if test="materialValue != null">
|
material_value=#{materialValue},
|
</if>
|
</set>
|
where id=#{id}
|
</update>
|
|
<!--逻辑删除-->
|
<update id="deletelogic">
|
update t_rsb_materials
|
SET is_use = 0
|
where id=#{id}
|
</update>
|
|
<!--根据ID删除-->
|
<delete id="deleteById">
|
delete from t_rsb_materials
|
where id=#{id}
|
</delete>
|
|
<delete id="deleteByRabPlan">
|
delete from t_rsb_materials
|
where rsb_id = #{rsbId}
|
</delete>
|
|
|
<select id="queryValueMonth" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
|
SELECT DATE_FORMAT(a.month,'%Y-%m') as shuDate, case when b.materialValue is null then 0 else b.materialValue end as materialValue from (
|
|
SELECT @s := DATE_ADD(@s,INTERVAL 1 MONTH) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(#{startTime},INTERVAL -1 MONTH)) temp WHERE @s < DATE_ADD(#{endTime},INTERVAL -1 MONTH)) a
|
left join
|
|
(select a.ym,sum(a.material_value) as materialValue from
|
(
|
select mmi.material_name,mmi.material_value,DATE_FORMAT(mm.create_time,'%Y-%m') as ym
|
from t_mix_material_info mmi
|
left join t_mix_material mm on mm.id = mmi.mix_material_id
|
where mm.is_use = 1 and mmi.material_name = #{materialName} and mm.company_id = #{companyId} and mm.create_time BETWEEN #{startTime} AND DATE_ADD(DATE_ADD(DATE_FORMAT(#{endTime},'%Y-%m-01 23:59:59'),INTERVAL 1 MONTH),INTERVAL -1 DAY)
|
) a
|
group by a.ym) b on DATE_FORMAT(a.month,'%Y-%m') = b.ym
|
</select>
|
|
<select id="queryValueDay" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
|
SELECT DATE_FORMAT(a.month,'%Y-%m-%d') as shuDate, case when b.materialValue is null then 0 else b.materialValue end as materialValue from (
|
|
SELECT @s := DATE_ADD(@s,INTERVAL 1 DAY) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(#{startTime},INTERVAL -1 DAY)) temp WHERE @s < #{endTime}) a
|
left join
|
|
(
|
select a.ym,sum(a.material_value) as materialValue FROM
|
(
|
select mmi.material_name,mmi.material_value,DATE_FORMAT(mm.create_time,'%Y-%m-%d') as ym
|
from t_mix_material_info mmi
|
left join t_mix_material mm on mm.id = mmi.mix_material_id
|
where mm.is_use = 1 and mmi.material_name = #{materialName} and mm.company_id = #{companyId} and mm.create_time BETWEEN #{startTime} AND #{endTime}
|
) a group by a.ym
|
) b on DATE_FORMAT(a.month,'%Y-%m-%d') = b.ym
|
</select>
|
|
<select id="queryMaterials" resultType="com.thhy.materials.modules.biz.materialsplan.entity.MaterialVo">
|
<!--select sd.dict_name as materialCName,a.material_name as materialName,a.material_value as materialValue from
|
(select rm.material_name,sum(rm.material_value) as material_value
|
from t_rsb_materials rm
|
left join t_rsb_material_plan rmp on rmp.id = rm.rsb_id
|
where rmp.create_time BETWEEN #{startTime} and #{endTime}
|
group by rm.material_name) a
|
left join sys_dict sd on sd.dict_id = a.material_name
|
order by sd.dict_value-->
|
|
select sd.dict_id as materialName,sd.dict_name as materialCName,
|
(
|
select case when sum(mmi.material_value) is null then 0 else sum(mmi.material_value) end as material_value
|
from t_mix_material_info mmi
|
left join t_mix_material tmm on mmi.mix_material_id = tmm.id
|
where tmm.is_use = 1 and mmi.material_name = sd.dict_id and tmm.company_id = #{companyId}
|
<if test="dateType==1">
|
and (tmm.create_time BETWEEN #{startTime} and #{endTime})
|
</if>
|
<if test="dateType==2">
|
and DATE_FORMAT(tmm.create_time ,'%Y-%m') >= DATE_FORMAT(#{startDay} ,'%Y-%m')
|
and DATE_FORMAT(tmm.create_time ,'%Y-%m') <= DATE_FORMAT(#{endDay} ,'%Y-%m')
|
</if>
|
) as materialValue
|
from sys_dict sd where sd.dict_type = "pipe_materials" order by sd.dict_value
|
</select>
|
|
<select id="queryAllMaterial" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatResultVo">
|
select dict_id as materialName,dict_name as materialCName
|
from sys_dict
|
where dict_type = 'pipe_materials'
|
<if test="materialName !=null and materialName !=''">
|
AND dict_id = #{materialName}
|
</if>
|
order by dict_value
|
</select>
|
|
|
|
</mapper>
|