CsdnTripletDayInfoServiceImpl.java 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
package com.kwan.springbootkwan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.mapper.CsdnTripletDayInfoMapper;
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import org.springframework.stereotype.Service;

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

/**
 * 每日三连监控(CsdnTripletDayInfo)表服务实现类
 *
 * @author makejava
 * @since 2023-10-26 20:55:31
 */
@Service("csdnTripletDayInfoService")
public class CsdnTripletDayInfoServiceImpl extends ServiceImpl<CsdnTripletDayInfoMapper, CsdnTripletDayInfo> implements CsdnTripletDayInfoService {
    @Override
    public CsdnTripletDayInfo todayInfo() {
        Date currentDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = sdf.format(currentDate);
        QueryWrapper<CsdnTripletDayInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        wrapper.eq("triplet_date", formattedDate);
        final CsdnTripletDayInfo one = this.getOne(wrapper);
        if (Objects.isNull(one)) {
            CsdnTripletDayInfo csdnTripletDayInfo = new CsdnTripletDayInfo();
            csdnTripletDayInfo.setTripletDate(new Date());
            csdnTripletDayInfo.setLikeNum(0);
            csdnTripletDayInfo.setCollectNum(0);
            csdnTripletDayInfo.setCommentNum(0);
            csdnTripletDayInfo.setUpdateTime(new Date());
            this.save(csdnTripletDayInfo);
        }
        return one;
    }
}