package com.huimv.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.huimv.admin.common.utils.DateUtil;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.EartagHourAct;
import com.huimv.admin.mapper.EartagHourActMapper;
import com.huimv.admin.service.IEartagHourActService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-09-19
 */
@Service
public class EartagHourActServiceImpl extends ServiceImpl<EartagHourActMapper, EartagHourAct> implements IEartagHourActService {
    @Autowired
    private EartagHourActMapper eartagHourActMapper;

    @Override
    public Result getHourAct(String farmCode, String startDate, String endDate, String earmark) throws ParseException {
        QueryWrapper<EartagHourAct> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(farmCode),"farm_code",farmCode);
        queryWrapper.between("add_date",startDate,endDate);
        queryWrapper.eq(StringUtils.isNotBlank(earmark),"earmark",earmark);
        List orderByAscList = new ArrayList();
        orderByAscList.add("add_date");
        orderByAscList.add("hour");
//        queryWrapper.orderByAsc(orderByAscList);
        List<EartagHourAct> eartagHourActList = eartagHourActMapper.selectList(queryWrapper);
        List resultList = new ArrayList();
        DateUtil du = new DateUtil();
        for(EartagHourAct eartagHourAct:eartagHourActList){
            Map map = new HashMap<>();
            resultList.add(map);
            map.put("addDate",du.formatDateText(eartagHourAct.getAddDate()));
            map.put("hour",eartagHourAct.getHour());
            map.put("act",eartagHourAct.getAct());
        }
        return new Result(ResultCode.SUCCESS,resultList);
    }
}
