package com.tofly.xrtygis.custom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.common.core.util.StringUtil;
import com.tofly.xrtygis.custom.mapper.LscreenMapper;
import com.tofly.xrtygis.custom.mapper.YxdbCustomerRecordMapper;
import com.tofly.xrtygis.custom.service.YxdbCustomerRecordService;
import com.tofly.xrtygis.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 *
 * @author
 * @date
 */
@Service("yxdbCustomerRecordServiceImpl")
@Slf4j
public class YxdbCustomerRecordServiceImpl extends ServiceImpl<YxdbCustomerRecordMapper, YxdbCustomerRecord> implements YxdbCustomerRecordService {
  @Autowired
  private LscreenMapper lscreenMapper;
    @Override
    public boolean saveCustomerData(String recordMonth){
         if(StringUtil.isEmpty(recordMonth)){
           SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
           recordMonth = sdf.format(new Date());
         }
       Integer  userCount=lscreenMapper.getRecordTotal(recordMonth);
        YxdbCustomerRecord yxdbCustomerRecord=this.baseMapper.selectList(
                new QueryWrapper<YxdbCustomerRecord>().lambda().eq(YxdbCustomerRecord::getRecordMonth,recordMonth)).stream().findFirst().orElse(new YxdbCustomerRecord());
        yxdbCustomerRecord.setRecordMonth(recordMonth);
        yxdbCustomerRecord.setUserTotal(userCount);
         return this.saveOrUpdate(yxdbCustomerRecord);
    }

}
