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

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;

/**
 * 云代配置
 * 服务实现类
 */
@Service
public class BdBonusCloudServiceImpl extends ServiceImpl<BdBonusCloudMapper, BdBonusCloud> implements IBdBonusCloudService {

    @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;
    }
}
