package com.fs.his.mapper;

import com.fs.his.domain.FsStoreProductPackage;
import com.fs.his.param.FsStoreProductPackageQueryParam;
import com.fs.his.vo.FsStoreProductPacketVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品组合套餐Mapper接口
 *
 * @author fs
 * @date 2022-07-14
 */
public interface FsStoreProductPackageMapper
{
    /**
     * 查询商品组合套餐
     *
     * @param packageId 商品组合套餐ID
     * @return 商品组合套餐
     */
    public FsStoreProductPackage selectFsStoreProductPackageById(Long packageId);

    /**
     * 查询商品组合套餐列表
     *
     * @param fsStoreProductPackage 商品组合套餐
     * @return 商品组合套餐集合
     */
    public List<FsStoreProductPackage> selectFsStoreProductPackageList(FsStoreProductPackage fsStoreProductPackage);

    /**
     * 新增商品组合套餐
     *
     * @param fsStoreProductPackage 商品组合套餐
     * @return 结果
     */
    public int insertFsStoreProductPackage(FsStoreProductPackage fsStoreProductPackage);

    /**
     * 修改商品组合套餐
     *
     * @param fsStoreProductPackage 商品组合套餐
     * @return 结果
     */
    public int updateFsStoreProductPackage(FsStoreProductPackage fsStoreProductPackage);

    /**
     * 删除商品组合套餐
     *
     * @param packageId 商品组合套餐ID
     * @return 结果
     */
    public int deleteFsStoreProductPackageById(Long packageId);

    /**
     * 批量删除商品组合套餐
     *
     * @param packageIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsStoreProductPackageByIds(Long[] packageIds);

    @Select({"<script> " +
            "select p.*,c.company_name,d.dept_name  from fs_store_product_package p   left join company_dept d on d.dept_id=p.dept_id left join company c on c.company_id=p.company_id  " +
            "where 1=1 " +
            "<if test = 'maps.title != null and  maps.title !=\"\"    '> " +
            "and p.title like CONCAT('%',#{maps.title},'%') " +
            "</if>" +
            "<if test = 'maps.cateId != null      '> " +
            "and p.cate_id =#{maps.cateId} " +
            "</if>" +
            "<if test = 'maps.companyId != null      '> " +
            "and (p.company_id =#{maps.companyId} or p.company_id=0) " +
            "</if>" +
            "<if test = 'maps.status != null      '> " +
            "and p.status =#{maps.status} " +
            "</if>" +
//            " ${maps.params.dataScope} "+
            " order by p.sort asc,p.package_id desc "+
            "</script>"})
    List<FsStoreProductPacketVO> selectFsStoreProductPackageListVO(@Param("maps") FsStoreProductPackage fsStoreProductPackage);
    @Select({"<script> " +
            "select p.*,c.company_name,d.dept_name  from fs_store_product_package p   left join company_dept d on d.dept_id=p.dept_id left join company c on c.company_id=p.company_id  " +
            "where 1=1 " +
            "<if test = 'maps.title != null and  maps.title !=\"\"    '> " +
            "and p.title like CONCAT('%',#{maps.title},'%') " +
            "</if>" +
            "<if test = 'maps.cateId != null and maps.cateId!=0      '> " +
            "and p.cate_id =#{maps.cateId} " +
            "</if>" +
            "<if test = 'maps.status != null        '> " +
            "and p.status =#{maps.status} " +
            "</if>" +
            " order by p.pay_money desc "+
            "</script>"})
    List<FsStoreProductPacketVO> selectFsStoreProductPackageListQueryVO(@Param("maps") FsStoreProductPackageQueryParam param);
    @Update({"<script> " +
            "update fs_store_product_package " +
            "set products= REPLACE ( products, '\"id\":${oldValId}}' ,'\"id\":${newValId}}' ) " +
            "</script>"})
    int updateProducts(@Param("oldValId") Long oldId, @Param("newValId") Long newId);
    @Select({"<script> " +
            "select p.*  from fs_store_product_package p    " +
            "where products like concat('%\"id\":',#{id},'%') " +
            "</script>"})
    List<FsStoreProductPackage> selectFsStoreProductPackageByProductId(Long id);

    /**
     * 批量修改商品组合套餐
     *
     * @param packageIds 需要修改的数据ID
     * @return 结果
     */
    public int updateFsStoreProductPackages(@Param("packageIds") Long[] orderIds, @Param("status") Long status);
}
