package com.foreverwin.mesnac.equip.service.impl;

import com.foreverwin.mesnac.common.enums.HandleEnum;
import com.foreverwin.mesnac.meapi.model.Resrce;
import com.foreverwin.mesnac.meapi.service.ResrceService;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.FrontPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.foreverwin.mesnac.equip.model.ResourceInspectResource;
import com.foreverwin.mesnac.equip.mapper.ResourceInspectResourceMapper;
import com.foreverwin.mesnac.equip.service.ResourceInspectResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
 * <p>
 * 设备检验计划从表 服务实现类
 * </p>
 *
 * @author pavel.Liu
 * @since 2021-06-11
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ResourceInspectResourceServiceImpl extends ServiceImpl<ResourceInspectResourceMapper, ResourceInspectResource> implements ResourceInspectResourceService {


    @Autowired
    private ResourceInspectResourceMapper resourceInspectResourceMapper;
    @Autowired
    private ResrceService resrceService;

    @Override
    public IPage<ResourceInspectResource> selectPage(FrontPage<ResourceInspectResource> frontPage, ResourceInspectResource resourceInspectResource) {
        QueryWrapper<ResourceInspectResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(resourceInspectResource);
        return super.page(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<ResourceInspectResource> selectList(ResourceInspectResource resourceInspectResource) {
        QueryWrapper<ResourceInspectResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(resourceInspectResource);
        return super.list(queryWrapper);
    }

    @Override
    public void deleteAll(ResourceInspectResource resourceInspectResource) {
        QueryWrapper<ResourceInspectResource> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(resourceInspectResource);
        super.remove(queryWrapper);
    }

    @Override
    public List<ResourceInspectResource> getResourceListByResourceType(String resourceTypeNo) {
        String site = CommonMethods.getSite();
        String resourceTypeBo = HandleEnum.RESOURCE_TYPE.getHandle(site, resourceTypeNo);
        List<Resrce> resourceList = resrceService.findResourceListByResourceType(site, resourceTypeBo);
        List<ResourceInspectResource> inspectResourceList = new ArrayList<>();
        for (Resrce resource:resourceList) {
            ResourceInspectResource resourceInspectResource = new ResourceInspectResource();
            resourceInspectResource.setResourceBo(resource.getHandle());
            resourceInspectResource.setResourceNo(resource.getResrce());
            resourceInspectResource.setDescription(resource.getDescription());
            resourceInspectResource.setTaskCreateDate(LocalDateTime.now());
            resourceInspectResource.setStatus("301");
            inspectResourceList.add(resourceInspectResource);
        }
        return inspectResourceList;
    }


}