<?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= "cc.hiver.mall.dao.mapper.PurchaseMapper" >
<resultMap id= "BaseResultMap" type= "cc.hiver.mall.entity.Purchase" >
<id column= "id" jdbcType= "VARCHAR" property= "id" />
<result column= "create_by" jdbcType= "VARCHAR" property= "createBy" />
<result column= "create_by_name" jdbcType= "VARCHAR" property= "createByName" />
<result column= "create_time" jdbcType= "TIMESTAMP" property= "createTime" />
<result column= "del_flag" jdbcType= "INTEGER" property= "delFlag" />
<result column= "update_by" jdbcType= "VARCHAR" property= "updateBy" />
<result column= "update_time" jdbcType= "TIMESTAMP" property= "updateTime" />
<result column= "supplier_id" jdbcType= "VARCHAR" property= "supplierId" />
<result column= "supplier_name" jdbcType= "VARCHAR" property= "supplierName" />
<result column= "shop_id" jdbcType= "VARCHAR" property= "shopId" />
<result column= "total_amount" jdbcType= "DECIMAL" property= "totalAmount" />
<result column= "should_pay" jdbcType= "DECIMAL" property= "shouldPay" />
<result column= "already_pay" jdbcType= "DECIMAL" property= "alreadyPay" />
<result column= "no_pay" jdbcType= "DECIMAL" property= "noPay" />
<result column= "other_pay" jdbcType= "DECIMAL" property= "otherPay" />
<result column= "in_storage_status" jdbcType= "INTEGER" property= "inStorageStatus" />
<result column= "remark" jdbcType= "VARCHAR" property= "remark" />
</resultMap>
<resultMap id= "DebtResultMap" type= "cc.hiver.mall.pojo.dto.DebtSupplier" >
<result column= "supplier_id" jdbcType= "VARCHAR" property= "supplierId" />
<result column= "consignee_name" jdbcType= "VARCHAR" property= "consigneeName" />
<result column= "no_pay" jdbcType= "DECIMAL" property= "noPay" />
</resultMap>
<sql id= "Example_Where_Clause" >
<where >
<foreach collection= "oredCriteria" item= "criteria" separator= "or" >
<if test= "criteria.valid" >
<trim prefix= "(" prefixOverrides= "and" suffix= ")" >
<foreach collection= "criteria.criteria" item= "criterion" >
<choose >
<when test= "criterion.noValue" >
and ${criterion.condition}
</when>
<when test= "criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test= "criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test= "criterion.listValue" >
and ${criterion.condition}
<foreach close= ")" collection= "criterion.value" item= "listItem" open= "(" separator= "," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id= "Update_By_Example_Where_Clause" >
<where >
<foreach collection= "example.oredCriteria" item= "criteria" separator= "or" >
<if test= "criteria.valid" >
<trim prefix= "(" prefixOverrides= "and" suffix= ")" >
<foreach collection= "criteria.criteria" item= "criterion" >
<choose >
<when test= "criterion.noValue" >
and ${criterion.condition}
</when>
<when test= "criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test= "criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test= "criterion.listValue" >
and ${criterion.condition}
<foreach close= ")" collection= "criterion.value" item= "listItem" open= "(" separator= "," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id= "Base_Column_List" >
id, create_by,create_by_name, create_time, del_flag, update_by, update_time, supplier_id,supplier_name, shop_id,
total_amount, should_pay, already_pay, no_pay,other_pay, in_storage_status,remark
</sql>
<select id= "selectByExample" parameterType= "cc.hiver.mall.entity.PurchaseExample" resultMap= "BaseResultMap" >
select
<if test= "distinct" >
distinct
</if>
<include refid= "Base_Column_List" />
from t_purchase
<if test= "_parameter != null" >
<include refid= "Example_Where_Clause" />
</if>
<if test= "orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id= "selectByPrimaryKey" parameterType= "java.lang.String" resultMap= "BaseResultMap" >
select
<include refid= "Base_Column_List" />
from t_purchase
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id= "deleteByPrimaryKey" parameterType= "java.lang.String" >
delete from t_purchase
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id= "deleteByExample" parameterType= "cc.hiver.mall.entity.PurchaseExample" >
delete from t_purchase
<if test= "_parameter != null" >
<include refid= "Example_Where_Clause" />
</if>
</delete>
<insert id= "insert" parameterType= "cc.hiver.mall.entity.Purchase" >
insert into t_purchase (id, create_by, create_by_name, create_time,
del_flag, update_by, update_time,
supplier_id,supplier_name, shop_id, total_amount,
should_pay, already_pay, no_pay,other_pay, in_storage_status,remark
)
values (#{id,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createByName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=INTEGER}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{supplierId,jdbcType=VARCHAR},#{supplierName,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL},
#{shouldPay,jdbcType=DECIMAL}, #{alreadyPay,jdbcType=DECIMAL}, #{noPay,jdbcType=DECIMAL}, #{otherPay,jdbcType=DECIMAL}, #{inStorageStatus,jdbcType=INTEGER},
#{remark,jdbcType=VARCHAR}
)
</insert>
<insert id= "insertSelective" parameterType= "cc.hiver.mall.entity.Purchase" >
insert into t_purchase
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "id != null" >
id,
</if>
<if test= "createBy != null" >
create_by,
</if>
<if test= "createByName != null" >
create_by_name,
</if>
<if test= "createTime != null" >
create_time,
</if>
<if test= "delFlag != null" >
del_flag,
</if>
<if test= "updateBy != null" >
update_by,
</if>
<if test= "updateTime != null" >
update_time,
</if>
<if test= "supplierId != null" >
supplier_id,
</if>
<if test= "supplierName != null" >
supplier_name,
</if>
<if test= "shopId != null" >
shop_id,
</if>
<if test= "totalAmount != null" >
total_amount,
</if>
<if test= "shouldPay != null" >
should_pay,
</if>
<if test= "alreadyPay != null" >
already_pay,
</if>
<if test= "noPay != null" >
no_pay,
</if>
<if test= "noPay != null" >
other_pay,
</if>
<if test= "inStorageStatus != null" >
in_storage_status,
</if>
<if test= "remark != null" >
remark,
</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "id != null" >
#{id,jdbcType=VARCHAR},
</if>
<if test= "createBy != null" >
#{createBy,jdbcType=VARCHAR},
</if>
<if test= "createByName != null" >
#{createByName,jdbcType=VARCHAR},
</if>
<if test= "createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test= "delFlag != null" >
#{delFlag,jdbcType=INTEGER},
</if>
<if test= "updateBy != null" >
#{updateBy,jdbcType=VARCHAR},
</if>
<if test= "updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test= "supplierId != null" >
#{supplierId,jdbcType=VARCHAR},
</if>
<if test= "supplierName != null" >
#{supplierName,jdbcType=VARCHAR},
</if>
<if test= "shopId != null" >
#{shopId,jdbcType=VARCHAR},
</if>
<if test= "totalAmount != null" >
#{totalAmount,jdbcType=DECIMAL},
</if>
<if test= "shouldPay != null" >
#{shouldPay,jdbcType=DECIMAL},
</if>
<if test= "alreadyPay != null" >
#{alreadyPay,jdbcType=DECIMAL},
</if>
<if test= "noPay != null" >
#{noPay,jdbcType=DECIMAL},
</if>
</trim>
</insert>
<select id= "countByExample" parameterType= "cc.hiver.mall.entity.PurchaseExample" resultType= "java.lang.Long" >
select count(*) from t_purchase
<if test= "_parameter != null" >
<include refid= "Example_Where_Clause" />
</if>
</select>
<update id= "updateByExampleSelective" parameterType= "map" >
update t_purchase
<set >
<if test= "record.id != null" >
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test= "record.createBy != null" >
create_by = #{record.createBy,jdbcType=VARCHAR},
</if>
<if test= "record.createByName != null" >
create_by_name = #{record.createByName,jdbcType=VARCHAR},
</if>
<if test= "record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test= "record.delFlag != null" >
del_flag = #{record.delFlag,jdbcType=INTEGER},
</if>
<if test= "record.updateBy != null" >
update_by = #{record.updateBy,jdbcType=VARCHAR},
</if>
<if test= "record.updateTime != null" >
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
<if test= "record.supplierId != null" >
supplier_id = #{record.supplierId,jdbcType=VARCHAR},
</if>
<if test= "record.supplierName != null" >
supplier_name = #{record.supplierName,jdbcType=VARCHAR},
</if>
<if test= "record.shopId != null" >
shop_id = #{record.shopId,jdbcType=VARCHAR},
</if>
<if test= "record.totalAmount != null" >
total_amount = #{record.totalAmount,jdbcType=DECIMAL},
</if>
<if test= "record.shouldPay != null" >
should_pay = #{record.shouldPay,jdbcType=DECIMAL},
</if>
<if test= "record.alreadyPay != null" >
already_pay = #{record.alreadyPay,jdbcType=DECIMAL},
</if>
<if test= "record.noPay != null" >
no_pay = #{record.noPay,jdbcType=DECIMAL},
</if>
<if test= "record.otherpay != null" >
other_pay = #{record.otherpay,jdbcType=DECIMAL},
</if>
<if test= "record.inStorageStatus != null" >
in_storage_status = #{record.inStorageStatus,jdbcType=INTEGER},
</if>
<if test= "record.remark != null" >
remark = #{record.remark,jdbcType=VARCHAR},
</if>
</set>
<if test= "_parameter != null" >
<include refid= "Update_By_Example_Where_Clause" />
</if>
</update>
<update id= "updateByExample" parameterType= "map" >
update t_purchase
set id = #{record.id,jdbcType=VARCHAR},
create_by = #{record.createBy,jdbcType=VARCHAR},
create_by_name = #{record.createByName,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
del_flag = #{record.delFlag,jdbcType=INTEGER},
update_by = #{record.updateBy,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
supplier_id = #{record.supplierId,jdbcType=VARCHAR},
supplier_name = #{record.supplierName,jdbcType=VARCHAR},
shop_id = #{record.shopId,jdbcType=VARCHAR},
total_amount = #{record.totalAmount,jdbcType=DECIMAL},
should_pay = #{record.shouldPay,jdbcType=DECIMAL},
already_pay = #{record.alreadyPay,jdbcType=DECIMAL},
no_pay = #{record.noPay,jdbcType=DECIMAL},
other_pay = #{record.otherPay,jdbcType=DECIMAL},
in_storage_status = #{record.inStorageStatus,jdbcType=INTEGER},
remark = #{record.remark,jdbcType=VARCHAR}
<if test= "_parameter != null" >
<include refid= "Update_By_Example_Where_Clause" />
</if>
</update>
<update id= "updateByPrimaryKeySelective" parameterType= "cc.hiver.mall.entity.Purchase" >
update t_purchase
<set >
<if test= "createBy != null" >
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test= "createByName != null" >
create_by_name = #{createByName,jdbcType=VARCHAR},
</if>
<if test= "createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test= "delFlag != null" >
del_flag = #{delFlag,jdbcType=INTEGER},
</if>
<if test= "updateBy != null" >
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test= "updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test= "supplierId != null" >
supplier_id = #{supplierId,jdbcType=VARCHAR},
</if>
<if test= "supplierName != null" >
supplier_name = #{supplierName,jdbcType=VARCHAR},
</if>
<if test= "shopId != null" >
shop_id = #{shopId,jdbcType=VARCHAR},
</if>
<if test= "totalAmount != null" >
total_amount = #{totalAmount,jdbcType=DECIMAL},
</if>
<if test= "shouldPay != null" >
should_pay = #{shouldPay,jdbcType=DECIMAL},
</if>
<if test= "alreadyPay != null" >
already_pay = #{alreadyPay,jdbcType=DECIMAL},
</if>
<if test= "noPay != null" >
no_pay = #{noPay,jdbcType=DECIMAL},
</if>
<if test= "otherPay != null" >
other_pay = #{otherPay,jdbcType=DECIMAL},
</if>
<if test= "inStorageStatus != null" >
in_storage_status = #{inStorageStatus,jdbcType=INTEGER},
</if>
<if test= "remark != null" >
remark = #{remark,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id= "updateByPrimaryKey" parameterType= "cc.hiver.mall.entity.Purchase" >
update t_purchase
set create_by = #{createBy,jdbcType=VARCHAR},
create_by_name = #{createByName,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=INTEGER},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
supplier_id = #{supplierId,jdbcType=VARCHAR},
supplier_name = #{supplierName,jdbcType=VARCHAR},
shop_id = #{shopId,jdbcType=VARCHAR},
total_amount = #{totalAmount,jdbcType=DECIMAL},
should_pay = #{shouldPay,jdbcType=DECIMAL},
already_pay = #{alreadyPay,jdbcType=DECIMAL},
no_pay = #{noPay,jdbcType=DECIMAL},
other_pay = #{otherPay,jdbcType=DECIMAL},
in_storage_status = #{inStorageStatus,jdbcType=INTEGER},
remark = #{remark,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
<select id= "selectDebtByShopId" resultMap= "DebtResultMap" >
SELECT
tc.id as supplier_id,
tc.consignee_name,
td.amount_owed as no_pay
FROM
t_supplier tc
LEFT JOIN t_debt td ON tc.id = td.user_id
WHERE
tc.del_flag = '0'
and tc.shop_id = #{queryParams.shopId}
order by no_earn desc
</select>
<select id= "getPurchaseList" parameterType= "cc.hiver.mall.pojo.query.PurchasePageQuery" resultMap= "BaseResultMap" >
select
<include refid= "Base_Column_List" />
from t_purchase
where del_flag = '0'
and shop_id = #{queryParams.shopId}
<if test= "queryParams.startDate != null and queryParams.startDate != '' and queryParams.endDate != null and queryParams.endDate != ''" >
and create_time BETWEEN #{queryParams.startDate} AND #{queryParams.endDate}
</if>
<if test= "queryParams.isAiList != null and queryParams.isAiList != ''" >
<!-- 查询ai列表 -->
and in_storage_status in ('2','3','4')
</if>
<if test= "queryParams.searchStr != null and queryParams.searchStr != ''" >
and (id in(
select purchase_id from t_purchase_detail
where product_id in (
select id from t_product
where product_name like concat('%',#{queryParams.searchStr},'%')
or product_sn like concat('%',#{queryParams.searchStr},'%')
)
group by purchase_id
)
or supplier_name like concat('%',#{queryParams.searchStr},'%')
)
</if>
order by create_time desc
</select>
<select id= "getPurchaseListByProductId" resultMap= "BaseResultMap" >
select
<include refid= "Base_Column_List" />
from t_purchase
where del_flag ='0'
and in_storage_status = 1
and id in (select purchase_id from t_purchase_detail where del_flag ='0' and product_id =#{productId})
order by create_time desc
</select>
<select id= "getPurchasingCost" resultType= "java.math.BigDecimal" >
select
IFNULL(sum(should_pay),0.00) as purchasingCost
from t_purchase
where del_flag = '0'
and shop_id = #{shopId}
and create_time BETWEEN #{startTime} AND #{endTime}
</select>
<update id= "updateInStorageStatus" >
update t_purchase
set
in_storage_status = #{inStorageStatus,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id= "deleteByPurchaseId" >
update t_purchase
set
del_flag = '1'
where id = #{id,jdbcType=VARCHAR}
</update>
<select id= "purchasingCostDetail" resultType= "cc.hiver.mall.pojo.vo.PurchasingCostDetailVo" >
select
tp.id as purchase_id,
tp.create_by,
tp.create_by_name,
tp.supplier_id,
tp.supplier_name,
tp.create_time as purchase_date,
cb.total_cost,
cb.product_count,
cb.product_num
from
t_purchase tp
left join
(select purchase_id, sum(price) as total_cost,count(product_id) as product_num,sum(product_count) as product_count from t_purchase_detail tpd where shop_id = #{purchasePageQuery.shopId} group by tpd.purchase_id) cb
on tp.id = cb.purchase_id
WHERE
del_flag ='0'
and in_storage_status = '1'
and shop_id = #{purchasePageQuery.shopId}
<if test= 'purchasePageQuery.createByName !=null and purchasePageQuery.createByName !=""' >
and create_by_name like concat('%',#{purchasePageQuery.createByName},'%')
</if>
<if test= 'purchasePageQuery.supplierName !=null and purchasePageQuery.supplierName !=""' >
and supplier_name like concat('%',#{purchasePageQuery.supplierName},'%')
</if>
<if test= 'purchasePageQuery.startDate !=null and purchasePageQuery.endDate !=null' >
and create_time BETWEEN #{purchasePageQuery.startDate} AND #{purchasePageQuery.endDate}
</if>
order by purchase_date desc
</select>
</mapper>