package com.gyee.runeconomy.service.update;/*
@author   谢生杰
@date   2023/5/16-10:10
*/

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.model.StringUtils;
import com.gyee.common.util.CommonUtils;
import com.gyee.runeconomy.model.auto.ProEconTargetdataFrist;
import com.gyee.runeconomy.service.auto.IProEconTargetdataFristService;
import com.gyee.runeconomy.util.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class TargetdataFristService {

    @Resource
    private IProEconTargetdataFristService proEconTargetdataFristService;


    public boolean save(ProEconTargetdataFrist data) {
        data.setId(CommonUtils.getUUID());
        return proEconTargetdataFristService.save(data);
    }

    public boolean update(ProEconTargetdataFrist data) {
        return proEconTargetdataFristService.saveOrUpdate(data);
    }

    public boolean delete(String ids) {
        String[] split = ids.split(",");
        List<String> list = Arrays.asList(split);
        return proEconTargetdataFristService.removeByIds(list);
    }

    public List<ProEconTargetdataFrist> get(String date) {
        Date date1 = DateUtils.pareDateNoHours(date);
        QueryWrapper<ProEconTargetdataFrist> query = new QueryWrapper<>();

        query.lambda().eq(ProEconTargetdataFrist::getRecordDate, date1);

        List<ProEconTargetdataFrist> list = proEconTargetdataFristService.list(query);
        return list;
    }

    public List<ProEconTargetdataFrist> getByDateAndName(String name, Date date) {

        List<ProEconTargetdataFrist> list = new ArrayList<>();
        if (StringUtils.notEmp(name) && StringUtils.notEmp(date)) {

            QueryWrapper<ProEconTargetdataFrist> query = new QueryWrapper<>();

            query.lambda().eq(ProEconTargetdataFrist::getRecordDate, date);
            query.lambda().eq(ProEconTargetdataFrist::getName, name);
            list = proEconTargetdataFristService.list(query);
        }

        return list;
    }
}
