<?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.mixingstationstorage.mapper.MinXingPlantMapper">
|
|
<insert id="insert" >
|
insert into t_material_stock_record
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
id,
|
</if>
|
<if test="createDate != null">
|
create_date,
|
</if>
|
<if test="type != null">
|
type,
|
</if>
|
<if test="opType != null">
|
op_type,
|
</if>
|
<if test="dictId != null">
|
material_name,
|
</if>
|
<if test="materialValue != null">
|
material_value,
|
</if>
|
<if test="beforeStock != null">
|
before_stock,
|
</if>
|
<if test="afterStock != null">
|
after_stock,
|
</if>
|
<if test="companyId != null">
|
company_id,
|
</if>
|
<if test="remark != null">
|
remark,
|
</if>
|
<if test="createUser != null">
|
create_user,
|
</if>
|
<if test="supplierName != null">
|
supplier_name,
|
</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
#{id},
|
</if>
|
<if test="createDate != null">
|
#{createDate},
|
</if>
|
<if test="type != null">
|
#{type},
|
</if>
|
<if test="opType != null">
|
#{opType},
|
</if>
|
<if test="dictId != null">
|
#{dictId},
|
</if>
|
<if test="materialValue != null">
|
#{materialValue},
|
</if>
|
<if test="beforeStock != null">
|
#{beforeStock},
|
</if>
|
<if test="afterStock != null">
|
#{afterStock},
|
</if>
|
<if test="companyId != null">
|
#{companyId},
|
</if>
|
<if test="remark != null">
|
#{remark},
|
</if>
|
<if test="createUser != null">
|
#{createUser},
|
</if>
|
<if test="supplierName != null">
|
#{supplierName},
|
</if>
|
</trim>
|
</insert>
|
|
<select id="selectAllList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.MinXingPlantDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.MinXingPlantVo">
|
SELECT
|
DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createDate,
|
b.dict_name dictName,
|
a.material_value changeStock,
|
d.real_name username,
|
'吨' unit,
|
a.supplier_name supplierName
|
FROM t_material_stock_record a
|
LEFT JOIN sys_dict b ON b.dict_id = a.material_name
|
LEFT JOIN sys_users d ON d.user_id = a.create_user
|
where
|
a.op_type =1 and a.company_id = #{companyId}
|
<if test="dictId != null and dictId != ''">
|
AND a.material_name = #{dictId}
|
</if>
|
<if test="supplierName != null and supplierName != ''">
|
AND a.supplier_name regexp #{supplierName}
|
</if>
|
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
AND a.create_date BETWEEN #{startTime} AND #{endTime}
|
</if>
|
order by a.create_date desc
|
</select>
|
|
<!-- 库存管理 -->
|
<select id="selectInventoryList" resultType="java.util.Map">
|
SELECT
|
a.id,
|
b.dict_name materialName,
|
'吨' unit,
|
FORMAT(a.material_value, 4) materialValue,
|
a.material_name dictId
|
FROM t_material_stock a
|
LEFT JOIN sys_dict b ON b.dict_id = material_name
|
where a.company_id = #{companyId}
|
<if test="id != null and id != ''">
|
AND a.id = #{id}
|
</if>
|
<if test="materialName != null and materialName != ''">
|
AND a.material_name in (SELECT dict_id FROM sys_dict WHERE dict_type = 'pipe_materials' and dict_name LIKE CONCAT('%',#{materialName},'%'))
|
</if>
|
order by a.create_time desc
|
</select>
|
|
<update id="updateInventory" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.entity.TMaterialStockVo">
|
<if test=" id != null">
|
UPDATE t_material_stock SET material_value = #{materialValue} WHERE id = #{id}
|
</if>
|
<if test="dictId != null">
|
update t_material_stock set material_value=material_value+#{materialValue} WHERE material_name= #{dictId}
|
</if>
|
</update>
|
<!-- 库存管理结束 -->
|
|
<!-- 校正记录 -->
|
<insert id="insertInventoryRecord">
|
insert into t_material_stock_record
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
id,
|
</if>
|
<if test="createDate != null">
|
create_date,
|
</if>
|
<if test="type != null">
|
type,
|
</if>
|
<if test="opType != null">
|
op_type,
|
</if>
|
<if test="materialName != null">
|
material_name,
|
</if>
|
<if test="materialValue != null">
|
material_value,
|
</if>
|
<if test="beforeStock != null">
|
before_stock,
|
</if>
|
<if test="afterStock != null">
|
after_stock,
|
</if>
|
<if test="companyId != null">
|
company_id,
|
</if>
|
<if test="remark != null">
|
remark,
|
</if>
|
<if test="createUser != null">
|
create_user,
|
</if>
|
<if test="supplierName != null">
|
supplier_name,
|
</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
#{id},
|
</if>
|
<if test="createDate != null">
|
#{createDate},
|
</if>
|
<if test="type != null">
|
#{type},
|
</if>
|
<if test="opType != null">
|
#{opType},
|
</if>
|
<if test="materialName != null">
|
#{materialName},
|
</if>
|
<if test="materialValue != null">
|
#{materialValue},
|
</if>
|
<if test="beforeStock != null">
|
#{beforeStock},
|
</if>
|
<if test="afterStock != null">
|
#{afterStock},
|
</if>
|
<if test="companyId != null">
|
#{companyId},
|
</if>
|
<if test="remark != null">
|
#{remark},
|
</if>
|
<if test="createUser != null">
|
#{createUser},
|
</if>
|
<if test="supplierName != null">
|
#{supplierName},
|
</if>
|
</trim>
|
</insert>
|
<select id="selectInventoryRecordList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.TMaterialStockRecordDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.TMaterialStockRecordVo">
|
SELECT
|
a.id,
|
DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createTime,
|
b.dict_name materialName,
|
'吨' unit,
|
a.material_value materialValue,
|
a.before_stock beforeStock,
|
a.after_stock afterStock,
|
a.remark remark,
|
a.create_user createUser
|
FROM t_material_stock_record a
|
LEFT JOIN sys_dict b ON b.dict_id = material_name
|
WHERE a.type = 3 and a.company_id = #{companyId}
|
<if test="dictId != null and dictId != ''">
|
AND a.material_name = #{dictId}
|
</if>
|
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
AND a.create_date BETWEEN #{startTime} AND #{endTime}
|
</if>
|
order by a.create_date desc
|
</select>
|
|
<!-- 校正记录结束 -->
|
|
|
<!-- 消耗记录 Consumption records -->
|
<select id="selectAllConsumptionList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.ConsumptionRecordDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.MXConsumptionRecordsVo">
|
SELECT
|
DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createDate,
|
d.dict_name materialName,
|
'吨' unit,
|
FORMAT(a.material_value, 4) materialValue,
|
a.pipe_num pipNum,
|
c.pro_name proName
|
FROM t_material_stock_record a
|
LEFT JOIN t_pipe_info b ON b.pipe_id = a.pipe_id
|
LEFT JOIN sys_project c ON c.pro_id = b.pro_id
|
LEFT JOIN sys_dict d ON d.dict_id = a.material_name
|
WHERE a.type = 2 AND a.company_id = #{companyId}
|
<if test="dictId != null and dictId != ''">
|
AND a.material_name = #{dictId}
|
</if>
|
<if test="proId != null and proId != ''">
|
AND b.pro_id = #{proId}
|
</if>
|
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
AND a.create_date BETWEEN #{startTime} AND #{endTime}
|
</if>
|
</select>
|
|
<select id="numberOfMaterials" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="java.util.Map">
|
SELECT
|
a.dict_name materialName,
|
IFNULL(FORMAT(sum(b.materialValue),4),0) materialValue
|
FROM sys_dict a
|
LEFT JOIN
|
(SELECT
|
a.material_value materialValue,
|
a.material_name dict_id
|
FROM t_material_stock_record a
|
WHERE a.type = 2
|
and a.create_date BETWEEN #{startDay} and #{endDay}
|
and a.company_id = #{companyId}
|
)b on b.dict_id = a.dict_id
|
WHERE a.dict_type ='pipe_materials' and a.is_use = 1
|
<if test="dictId != null and dictId !=''">
|
and a.dict_id =#{dictId}
|
</if>
|
GROUP BY a.dict_name
|
</select>
|
|
<select id="queryValueMonth" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
|
|
SELECT
|
d.moth shuDate,
|
IFNULL(c.materialValue,0) materialValue
|
FROM (
|
SELECT moth FROM (
|
SELECT
|
DATE_FORMAT( date_add( concat( #{startDay} ), INTERVAL ( help_topic_id ) DAY ), '%Y-%m' ) moth
|
FROM
|
mysql.help_topic
|
WHERE
|
help_topic_id <= timestampdiff( DAY, concat( #{startDay} ), concat( #{endDay} ) )
|
) m GROUP BY m.moth
|
) d
|
LEFT JOIN (
|
SELECT createDate,
|
sum(materialValue) materialValue,
|
dictId
|
FROM(
|
SELECT
|
DATE_FORMAT( a.create_date, '%Y-%m') createDate,
|
a.material_value materialValue,
|
a.material_name dictId
|
FROM t_material_stock_record a
|
WHERE a.material_name = #{dictId} AND a.type = 2 AND a.company_id = #{companyId}
|
) b
|
GROUP BY b.createDate,b.dictId
|
) c on c.createDate = d.moth
|
</select>
|
|
<select id="queryValueDay" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
|
SELECT
|
d.moth shuDate,
|
IFNULL(c.materialValue,0) materialValue
|
FROM (
|
SELECT
|
DATE_FORMAT( date_add( concat( #{startDay} ), INTERVAL ( help_topic_id ) DAY ), '%Y-%m-%d' ) moth
|
FROM
|
mysql.help_topic
|
WHERE
|
help_topic_id <= timestampdiff( DAY, concat( #{startDay} ), concat( #{endDay} ) )
|
) d
|
LEFT JOIN (
|
SELECT createDate,
|
sum(materialValue) materialValue,
|
dictId
|
FROM(
|
SELECT
|
DATE_FORMAT( a.create_date, '%Y-%m-%d') createDate,
|
a.material_value materialValue,
|
a.material_name dictId
|
FROM t_material_stock_record a
|
WHERE a.material_name = #{dictId} AND a.type = 2 AND a.company_id = #{companyId}
|
) b
|
GROUP BY b.createDate,b.dictId
|
) c on c.createDate = d.moth
|
</select>
|
<!--消耗记录结束 -->
|
</mapper>
|