package io.hmit.test;

import io.hmit.modules.serviceOrder.dto.PensionServiceDTO;
import io.hmit.modules.serviceOrder.dto.PensionServiceTypeDTO;
import io.hmit.modules.serviceOrder.dto.RoleDTO;
import io.hmit.modules.serviceOrder.dto.RoleServiceDTO;
import io.hmit.modules.serviceOrder.service.PensionServiceService;
import io.hmit.modules.serviceOrder.service.PensionServiceTypeService;
import io.hmit.modules.serviceOrder.service.RoleService;
import io.hmit.modules.serviceOrder.service.RoleServiceService;
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 javax.management.relation.Role;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Eve
 * @email mengmengeve@gmail.com
 * @create 2021/1/27
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class TypeServiceTest {
    @Autowired
    private PensionServiceTypeService pensionServiceTypeService;

    @Autowired
    private PensionServiceService pensionServiceService;

    @Autowired
    private RoleServiceService roleServiceService;

    @Autowired
    private RoleService roleService;

    @Test
    public void test(){
        System.out.println("hello world!!");
    }
    @Test
    public void getList(){
        List<Long> roleIds = new ArrayList<>();
        roleIds.add(1354991196866453506L);
        roleIds.add(1354991197348798465L);

        Map<String, Object> params = new HashMap<>();

        List<Long> servicesTypeIds =pensionServiceTypeService.list(params).stream().map(PensionServiceTypeDTO::getId).collect(Collectors.toList());

        roleIds.forEach(roleId -> {
            for (Long typeId:servicesTypeIds){
                RoleServiceDTO roleServiceDTO = new RoleServiceDTO();
                roleServiceDTO.setRoleId(roleId);
                roleServiceDTO.setServiceTypeId(typeId);
                roleServiceService.save(roleServiceDTO);
            }
        });


    }


    @Test
    public void updateTime(){
        Map<String, Object> params = new HashMap<>();
        List<PensionServiceDTO> pensionServiceDTOS =pensionServiceService.list(params);

        pensionServiceDTOS.stream().forEach(item ->{
            item.setServiceTime("周一 ～ 周日 09:00-18:00");
            item.setTimesNum(18);
            item.setRemark("为老人提供免费的"+item.getServiceName()+"服务");
            pensionServiceService.update(item);
        });
    }

    @Test
    public void saveServiceType(){
        List<String> names = new ArrayList<>();
        names.add("健康检查");
        names.add("家政服务");
        names.add("心理慰藉");
        names.add("理发");
        names.add("送药上门");
        names.add("健康养生");
        names.add("临终关怀");
        names.forEach(name ->{
            PensionServiceTypeDTO pensionServiceTypeDTO = new PensionServiceTypeDTO();
            pensionServiceTypeDTO.setName(name);
            pensionServiceTypeDTO.setSort(1);
            pensionServiceTypeDTO.setIcon("");
            pensionServiceTypeDTO.setRemark("");
            pensionServiceTypeService.save(pensionServiceTypeDTO);
        });

    }
}
