package com.cool.store.dao;

import com.alibaba.excel.util.CollectionUtils;
import com.aliyun.openservices.shade.com.google.common.collect.Lists;
import com.cool.store.constants.CommonConstants;
import com.cool.store.entity.PointDetailInfoDO;
import com.cool.store.mapper.PointDetailInfoMapper;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
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);
    }

    public List<PointDetailInfoDO> getByPointIdList(List<Long> pointIdList) {
        if (CollectionUtils.isEmpty(pointIdList)){
            return Lists.newArrayList();
        }
        Example example = new Example(PointDetailInfoDO.class);
        example.createCriteria().andIn("pointId", pointIdList);
        return pointDetailInfoMapper.selectByExample(example);
    }

    /**
     * @Auther: wangshuo
     * @Date: 2025/5/9
     * @description: 数据处理用 面积 租金
     */
    public Integer updateMonthRent(List<PointDetailInfoDO> list) {
        if (CollectionUtils.isEmpty(list)){
            return CommonConstants.ZERO;
        }
        return pointDetailInfoMapper.updateMonthRent(list);
    }

}
