package com.yc.ship.module.marketing.service.policydetail;

import com.yc.ship.framework.common.util.collection.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.yc.ship.module.marketing.controller.admin.policydetail.vo.*;
import com.yc.ship.module.marketing.dal.dataobject.policydetail.PolicyDetailDO;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.pojo.PageParam;
import com.yc.ship.framework.common.util.object.BeanUtils;

import com.yc.ship.module.marketing.dal.mysql.policydetail.PolicyDetailMapper;

import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yc.ship.module.marketing.enums.ErrorCodeConstants.*;

/**
 * 政策详情 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class PolicyDetailServiceImpl implements PolicyDetailService {

    @Resource
    private PolicyDetailMapper policyDetailMapper;

    @Override
    public Long createPolicyDetail(PolicyDetailSaveReqVO createReqVO) {
        // 插入
        PolicyDetailDO policyDetail = BeanUtils.toBean(createReqVO, PolicyDetailDO.class);
        policyDetailMapper.insert(policyDetail);
        // 返回
        return policyDetail.getId();
    }

    @Override
    public void updatePolicyDetail(PolicyDetailSaveReqVO updateReqVO) {
        // 更新
        PolicyDetailDO updateObj = BeanUtils.toBean(updateReqVO, PolicyDetailDO.class);
        policyDetailMapper.updateById(updateObj);
    }

    @Override
    public void deletePolicyDetail(Long id) {
        // 删除
        policyDetailMapper.deleteById(id);
    }


    @Override
    public PolicyDetailDO getPolicyDetail(Long id) {
        return policyDetailMapper.selectById(id);
    }

    @Override
    public PageResult<PolicyDetailDO> getPolicyDetailPage(PolicyDetailPageReqVO pageReqVO) {
        return policyDetailMapper.selectPage(pageReqVO);
    }

    @Override
    public List<PolicyDetailDO> getByPolicyId(Long policyId) {
        return policyDetailMapper.selectByPolicyId(policyId);
    }

    @Override
    public List<PolicyDetailDO> getByPolicyIds(List<Long> policyIds) {
        if(CollectionUtils.isAnyEmpty(policyIds)) {
            return Collections.emptyList();
        }
        return policyDetailMapper.selectByPolicyIds(policyIds);
    }

}