package com.ho.flow;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.ho.business.vo.resp.InverterResp.ModelInverter;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.constant.RedisKeyConstant;
import com.ho.common.tools.entity.WorkOrderPicture;
import com.ho.common.tools.service.RedisService;
import com.ho.flow.service.WorkOrderPictureService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author fancl
 * @desc:
 * @date 2023/2/15
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class RedisConvertTest {

    @Autowired
    RedisService redisService;

    @Autowired
    WorkOrderPictureService workOrderPictureService;

    @Test
    public void redis() {
        String inverterRedisKey = RedisKeyConstant.INVERTER + 251 + ":" + 4;
        //创建返回对象
        ModelInverter modelInverter = new ModelInverter();
        if (redisService.hasKey(inverterRedisKey)) {
            Map<Object, Object> inverterMap = redisService.hgetall(inverterRedisKey);
            if(inverterMap!=null){
                ModelInverter modelInverter1 = JSON.parseObject(JSON.toJSONString(inverterMap), ModelInverter.class);
                System.out.println();
            }

        }
        System.out.println();

    }

    @Test
    public void week(){
        String date = "2023-03-17 00:00:00";
        DateTime parse = DateUtil.parse(date, CommonConstant.DATE);
        int i = DateUtil.dayOfWeek(parse);
        int i1 = DateUtil.dayOfMonth(parse);
        System.out.println();
    }

    @Test
    public void deletedFile(){
        //查询全部数据
        List<WorkOrderPicture> workOrderPictures = workOrderPictureService.selectAll();
        //筛选未关联的工单号的图片和文件数据
        workOrderPictures = workOrderPictures.stream().filter(s -> {
            return s.getWorkOrderId() == null;
        }).collect(Collectors.toList());

        System.out.println();
    }

}
