package com.hzs.system.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.domain.system.config.BdBonusCloud;
import com.hzs.common.domain.system.config.ext.BdBonusCloudExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.mapper.BdBonusCloudMapper;
import com.hzs.system.config.service.IBdBonusCloudService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  云代配置
 服务实现类
 * </p>
 *
 * @author zhangjing
 * @since 2022-11-01
 */
@Service
public class BdBonusCloudServiceImpl extends ServiceImpl<BdBonusCloudMapper, BdBonusCloud> implements IBdBonusCloudService {

    @Override
    public List<BdBonusCloud> queryBdBonusCloud() {
        QueryWrapper<BdBonusCloud> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("CLOUD_TYPE,CLOUD_RATIO,PK_COUNTRY");
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * @description: 新增云代配置
     * @author: zhang jing
     * @date: 2022/11/1 17:11
     * @param: [bonusCloudExt]
     * @return: boolean
     **/
    @Override
    public boolean saveBonusCloud(BdBonusCloudExt bonusCloudExt) {
        for(BdBonusCloud bonusCloud:bonusCloudExt.getBonusCloudList()){
            bonusCloud.setPkCountry(SecurityUtils.getPkCountry());
            if(StringUtils.isNotNull(bonusCloud.getPkId())){
                bonusCloud.setPkModified(SecurityUtils.getUserId());
                bonusCloud.setModifiedTime(new Date());
                baseMapper.updateById(bonusCloud);
            }else{
                bonusCloud.setPkCreator(SecurityUtils.getUserId());
                bonusCloud.setCreationTime(new Date());
                baseMapper.insert(bonusCloud);
            }
        }
        return false;
    }

    @Override
    public boolean updateBonusCloud(BdBonusCloudExt bonusCloudExt) {
        for(BdBonusCloud bonusCloud:bonusCloudExt.getBonusCloudList()){
            bonusCloud.setPkCountry(SecurityUtils.getPkCountry());
            bonusCloud.setPkModified(SecurityUtils.getUserId());
            bonusCloud.setModifiedTime(new Date());
            baseMapper.updateById(bonusCloud);
        }
        return false;
    }
}
