INSERT INTO goods
(goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,tax_stock_count_,sell_count_,market_price_,
discount_price_,group_purchase_price_,brief_,desc_,is_new_,is_top_,status_,memo_,publish_time_,
complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_,stock_warning_,stock_type_
,student_show_organ_id_,education_show_organ_id_,replacement_show_organ_id_,course_fee_show_organ_id_,member_fee_show_organ_id_,free_fee_show_organ_id_,tenant_id_)
VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{taxStockCount},#{sellCount},#{marketPrice},
#{discountPrice},#{groupPurchasePrice},#{brief},#{desc},
#{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
#{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice},
#{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
#{studentShowOrganId},#{educationShowOrganId},#{replacementShowOrganId},#{courseFeeShowOrganId},#{memberFeeShowOrganId},#{freeFeeShowOrganId},#{tenantId})
INSERT INTO goods
(goods_category_id_,name_,brand_,specification_,image_,market_price_,
discount_price_,group_purchase_price_,brief_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
stock_count_,tax_stock_count_,stock_warning_,stock_type_
,student_show_organ_id_,education_show_organ_id_,replacement_show_organ_id_,course_fee_show_organ_id_,member_fee_show_organ_id_,free_fee_show_organ_id_,tenant_id_)
VALUES
(#{goods.goodsCategoryId},#{goods.name},#{goods.brand},#{goods.specification},#{goods.image},#{goods.marketPrice},
#{goods.discountPrice},#{goods.groupPurchasePrice},#{goods.brief},#{goods.desc},now(),now(),
#{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},
#{goods.stockCount},#{goods.taxStockCount},
#{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
#{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
#{goods.studentShowOrganId},#{goods.educationShowOrganId},#{goods.replacementShowOrganId},#{goods.courseFeeShowOrganId},#{goods.memberFeeShowOrganId},,#{goods.freeFeeShowOrganId},#{goods.tenantId}
)
UPDATE goods
student_show_organ_id_ = #{studentShowOrganId},
education_show_organ_id_ = #{educationShowOrganId},
replacement_show_organ_id_ = #{replacementShowOrganId},
course_fee_show_organ_id_ = #{courseFeeShowOrganId},
member_fee_show_organ_id_ = #{memberFeeShowOrganId},
free_fee_show_organ_id_ = #{freeFeeShowOrganId},
agree_cost_price_ = #{agreeCostPrice},
specification_ = #{specification},
status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
sn_ = #{sn},
market_price_ = #{marketPrice},
memo_ = #{memo},
is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
group_purchase_price_ = #{groupPurchasePrice},
name_ = #{name},
stock_count_ = #{stockCount},
goods_category_id_ = #{goodsCategoryId},
brand_ = #{brand},
brief_ = #{brief},
discount_price_ = #{discountPrice},
sell_count_ = #{sellCount},
image_ = #{image},
desc_ = #{desc},
publish_time_ = #{publishTime},
complement_goods_id_list_ = #{complementGoodsIdList},
tax_stock_count_ = #{taxStockCount},
stock_warning_ = #{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
stock_type_ = #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
update_time_ = NOW()
WHERE id_ = #{id} and tenant_id_ = #{tenantId}
UPDATE goods
student_show_organ_id_ = #{goods.studentShowOrganId},
education_show_organ_id_ = #{goods.educationShowOrganId},
replacement_show_organ_id_ = #{goods.replacementShowOrganId},
course_fee_show_organ_id_ = #{goods.courseFeeShowOrganId},
member_fee_show_organ_id_ = #{goods.memberFeeShowOrganId},
free_fee_show_organ_id_ = #{goods.freeFeeShowOrganId},
agree_cost_price_ = #{goods.agreeCostPrice},
specification_ = #{goods.specification},
status_ = #{goods.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
is_top_ = #{goods.isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
type_ = #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
sn_ = #{goods.sn},
market_price_ = #{goods.marketPrice},
memo_ = #{goods.memo},
is_new_ = #{goods.isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
group_purchase_price_ = #{goods.groupPurchasePrice},
name_ = #{goods.name},
stock_count_ = #{goods.stockCount},
goods_category_id_ = #{goods.goodsCategoryId},
brand_ = #{goods.brand},
brief_ = #{goods.brief},
discount_price_ = #{goods.discountPrice},
sell_count_ = #{goods.sellCount},
image_ = #{goods.image},
desc_ = #{goods.desc},
publish_time_ = #{goods.publishTime},
complement_goods_id_list_ = #{goods.complementGoodsIdList},
tax_stock_count_ = #{goods.taxStockCount},
stock_warning_ = #{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
stock_type_ = #{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
update_time_ = NOW()
WHERE id_ = #{goods.id} and tenant_id_ = #{goods.tenantId}
DELETE FROM goods WHERE id_ = #{id}
g.tenant_id_ = #{tenantId}
AND g.goods_category_id_ = #{goodsCategoryId}
AND g.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
AND g.is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
AND g.is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
AND g.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
AND g.complement_goods_id_list_ IS NULL
AND g.complement_goods_id_list_ IS NOT NULL
AND INTE_ARRAY(#{studentShowOrganId},g.student_show_organ_id_)
AND INTE_ARRAY(#{educationShowOrganId},g.education_show_organ_id_)
AND INTE_ARRAY(#{courseFeeShowOrganId},g.course_fee_show_organ_id_)
AND INTE_ARRAY(#{memberFeeShowOrganId},g.member_fee_show_organ_id_)
AND INTE_ARRAY(#{freeFeeShowOrganId},g.free_fee_show_organ_id_)
AND INTE_ARRAY(#{replacementShowOrganId},g.replacement_show_organ_id_)
AND INTE_ARRAY (#{organId},CONCAT_WS(',',
CASE WHEN member_fee_show_organ_id_ = '' THEN NULL ELSE member_fee_show_organ_id_ END,
CASE WHEN course_fee_show_organ_id_ = '' THEN NULL ELSE course_fee_show_organ_id_ END,
CASE WHEN free_fee_show_organ_id_ = '' THEN NULL ELSE free_fee_show_organ_id_ END,
CASE WHEN education_show_organ_id_ = '' THEN NULL ELSE education_show_organ_id_ END,
CASE WHEN student_show_organ_id_ = '' THEN NULL ELSE student_show_organ_id_ END,
CASE WHEN replacement_show_organ_id_ = '' THEN NULL ELSE replacement_show_organ_id_ END))
AND (g.sn_=#{search} OR g.id_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%'))
AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId}
AND sgm.subject_id_ = #{goodsQuery.subjectId}
AND g.type_ = #{goodsQuery.type}
AND FIND_IN_SET(#{goodsQuery.studentShowOrganId},g.student_show_organ_id_)
AND FIND_IN_SET(#{goodsQuery.educationShowOrganId},g.education_show_organ_id_)
AND FIND_IN_SET(#{goodsQuery.courseFeeShowOrganId},g.course_fee_show_organ_id_)
AND FIND_IN_SET(#{goodsQuery.memberFeeShowOrganId},g.member_fee_show_organ_id_)
AND FIND_IN_SET(#{goodsQuery.freeFeeShowOrganId},g.free_fee_show_organ_id_)
AND FIND_IN_SET(#{goodsQuery.replacementShowOrganId},g.replacement_show_organ_id_)
AND FIND_IN_SET (#{goodsQuery.organId},CONCAT_WS(',',
CASE WHEN member_fee_show_organ_id_ = '' THEN NULL ELSE member_fee_show_organ_id_ END,
CASE WHEN course_fee_show_organ_id_ = '' THEN NULL ELSE course_fee_show_organ_id_ END,
CASE WHEN free_fee_show_organ_id_ = '' THEN NULL ELSE free_fee_show_organ_id_ END,
CASE WHEN education_show_organ_id_ = '' THEN NULL ELSE education_show_organ_id_ END,
CASE WHEN student_show_organ_id_ = '' THEN NULL ELSE student_show_organ_id_ END,
CASE WHEN replacement_show_organ_id_ = '' THEN NULL ELSE replacement_show_organ_id_ END))
g.status_ != 0
AND g.type_ = 'INSTRUMENT'
AND gc.del_flag_ = 0 and g.tenant_id_ = #{tenantId}
AND FIND_IN_SET(#{organId},g.replacement_show_organ_id_)
AND sgm.subject_id_ = #{subjectId}
AND g.brand_ = #{brand}
AND g.specification_ = #{specification}