package com.bonus.core.notice.notice.v2.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.constant.LeConstants;
import com.bonus.core.notice.notice.v2.dto.InformHistoryAppletPageDTO;
import com.bonus.core.notice.notice.v2.mapper.InformHistoryMapper;
import com.bonus.core.notice.notice.v2.model.InformHistory;
import com.bonus.core.notice.notice.v2.model.InformRange;
import com.bonus.core.notice.notice.v2.service.InformHistoryService;
import com.bonus.core.notice.notice.v2.service.InformRangeService;
import com.bonus.core.notice.notice.v2.vo.InformHistoryAppletPageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

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

@Service
public class InformHistoryServiceImpl extends ServiceImpl<InformHistoryMapper, InformHistory> implements InformHistoryService {
   private static final Logger log = LoggerFactory.getLogger(InformHistoryServiceImpl.class);
   @Resource
   @Lazy
   private InformRangeService informRangeService;


   @Override
   public List<InformHistoryAppletPageVO> queryAppletPageList(InformHistoryAppletPageDTO content) {
      List<InformHistoryAppletPageVO> historyList = ((InformHistoryMapper)this.baseMapper).queryApplietPageList(content);
      if (ObjectUtil.isNotEmpty(historyList)) {
         this.informRangeService.update(Wrappers.lambdaUpdate(InformRange.class)
                 .set(InformRange::getWhether, LeConstants.COMMON_YES)
                 .eq(InformRange::getCustId, content.getCustId())
                 .eq(InformRange::getWhether, LeConstants.COMMON_NO));
      }

      return historyList;
   }

}
