package com.xhpc.general.mapper;

import com.xhpc.common.domain.XhpcDictBiz;
import com.xhpc.general.domain.XhpcDictionary;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 业务字典Mapper接口
 *
 * @author yuyang
 * @date 2021-07-19
 */
public interface XhpcDictBizMapper {

    /**
     * 根据code获取数据
     *
     * @param code 字典code
     * @return 电站
     */
    public List<XhpcDictBiz> getCode(String code);

    /**
     * Ensuring the parent name is unique.
     * @param name  is dict_value.
     * @return
     */
    int countParentNameColumns(@Param("id")Long id, @Param("name") String name);

    /**
     * This is to ensure the child keyValue is unique
     * @param id
     * @param name
     * @return
     */
    int countSameParentChildNameColumns(@Param("id") Long id,@Param("name") String name);



    /**
     * Adding a item to the table(xhpc_dict_biz)
     * @param name  the dictionary's name
     * @param code  the dictionary's code
     *
     */
    void insertAParentItemToTable(@Param("name") String name,@Param("code") String code,@Param("sort") Integer sort);
    /**
     * Getting a dictionary data.
     *
     * The id map to dictionary table is dict_biz_id.
     * @param id
     * @return
     */
    XhpcDictionary selectADictionaryItem(@Param("id") Long id);

    /**
     * Adding a childIem to the table(xhpc_dict_biz)
     * @param parentId
     * @param code
     * @param dictKey
     * @param dictValue
     * @return
     */
    void insertAChildItemToTable(@Param("id")Long parentId,@Param("code") String code,@Param("dictKey") String dictKey,@Param("dictValue") String dictValue,@Param("sore") Integer sort);
    /**
     * Deleting a dictionary item by id(dict_biz_id)
     * @param id
     * @return
     */
    int deleteChildDictionaryItemById(@Param("id") Long id);

    void deleteChildItemsFollowParent(@Param("id") Long id);
    /**
     * Getting a list of the parent dict items by code and name.
     * @param code
     * @param name
     * @return
     */
    List<XhpcDictionary> selectParentDictionaryItemsByCodeAndName(@Param("code")String code,@Param("name") String name);

    /**
     * Getting a list of the child dict items by code,code,parentId.
     * @param parentId
     * @param code
     * @param name
     * @return
     */
    List<XhpcDictionary> selectChildDictionaryItemsByCodeAndName(@Param("id") Long parentId, @Param("code") String code, @Param("name") String name);



    /**
     * Updating the main item by code,dictValue,sort
     * @param dictBizId
     * @param code
     * @param keyValue the item's name
     * @param sort
     * @return
     */
    int updateParentItemByCodeDictValueSort(@Param("id") Long id,@Param("code") String code,@Param("dictValue") String dictValue,@Param("sort") Integer sort);

    /**
     * Updating the child item's dict_value, after their father item has changed its dict_value.
     * @param dictBizId
     * @param value
     */
    void  updateChildValue(@Param("id") Long dictBizId,@Param("code") String code);

    /**
     * Updating a child item by value,key.
     * @param id
     * @param value
     * @param key
     * @return
     */
    int  updateChildItem(@Param("id") Long id,@Param("value") String value,@Param("key") String key,@Param("sort") Integer sort);

    /**
     * Deleting a bundle of child item.
     * @param ids
     * @return
     */
    int deleteChildItemByIds(@Param("ids") List<Long> ids);

    /**
     * Deleting a bundle of child item after their parent has been died.
     * @param ids
     * @return
     */
    int deleteChildItemsAfterTheirParentDied(@Param("ids") List<Long> ids);

    /**
     * Getting parent's name's quantity.
     * @param name
     * @return
     */
    int countParentNameQuantity(@Param("name") String name);



    void updateChildCodeAfterParentChanged(@Param("code") String code,@Param("id") Long id);
}
