package com.cool.store.dao;

import com.cool.store.entity.PointDetailInfoDO;
import com.cool.store.mapper.PointDetailInfoMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: ShopPointDetailInfoDAO
 * @Description:
 * @date 2024-03-29 10:15
 */
@Repository
public class PointDetailInfoDAO {

    @Resource
    private PointDetailInfoMapper pointDetailInfoMapper;

    /**
     * 新增点位详情
     * @param shopPointDetailInfo
     * @return
     */
    public Long addPointDetailInfo(PointDetailInfoDO shopPointDetailInfo) {
        pointDetailInfoMapper.insertSelective(shopPointDetailInfo);
        return shopPointDetailInfo.getId();
    }

    /**
     * 更新点位详情
     * @param shopPointDetailInfo
     * @return
     */
    public Integer updatePointDetailInfo(PointDetailInfoDO shopPointDetailInfo) {
        if(Objects.isNull(shopPointDetailInfo.getId()) && Objects.nonNull(shopPointDetailInfo.getPointId())){
            Long pointDetailId = getPointDetailIdByPointId(shopPointDetailInfo.getPointId());
            shopPointDetailInfo.setId(pointDetailId);
        }
        return pointDetailInfoMapper.updateByPrimaryKeySelective(shopPointDetailInfo);
    }

    public Integer updatePartFieldPointDetail(PointDetailInfoDO shopPointDetailInfo) {
        if(Objects.isNull(shopPointDetailInfo.getId()) && Objects.nonNull(shopPointDetailInfo.getPointId())){
            Long pointDetailId = getPointDetailIdByPointId(shopPointDetailInfo.getPointId());
            shopPointDetailInfo.setId(pointDetailId);
        }
        return pointDetailInfoMapper.updatePartFieldPointDetail(shopPointDetailInfo);
    }

    public Long getPointDetailIdByPointId(Long pointId){
        return pointDetailInfoMapper.getPointDetailIdByPointId(pointId);
    }

    public PointDetailInfoDO getPointDetailInfoByPointId(Long pointId) {
        return pointDetailInfoMapper.getShopPointDetailInfoByPointId(pointId);
    }


}
