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

import com.foreverwin.mesnac.meapi.dto.ResrceWorkCenter;
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.meapi.model.Resrce;
import com.foreverwin.mesnac.meapi.mapper.ResrceMapper;
import com.foreverwin.mesnac.meapi.service.ResrceService;
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.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Leon.L
 * @since 2021-05-26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ResrceServiceImpl extends ServiceImpl<ResrceMapper, Resrce> implements ResrceService {


    @Autowired
    private ResrceMapper resrceMapper;

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

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

    @Override
    public List<Resrce> getResourceListByType(String site, String resourceType) {
        return resrceMapper.selectResourceListByType(site, resourceType);
    }

    @Override
    public List<Map<String, Object>> getResourceTypeResourceList(String site) {
        return resrceMapper.selectResourceTypeResourceList(site);
    }

    @Override
    public Resrce findByResrce(String resrce) {
        String site = CommonMethods.getSite();
        Resrce byResrce = resrceMapper.findByResrce(site, resrce);
        return byResrce;
    }

    @Override
    public List<Resrce> findAllResrce() {
        String site = CommonMethods.getSite();
        return resrceMapper.findAllResrce(site);
    }

    @Override
    public void updateResourceStatus(String site, String resource, String status) {
        String statusBo = "StatusBO:" + site + "," + status;
        String resourceBo = "ResourceBO:" + site + "," + resource;

        Resrce resrce = new Resrce();
        resrce.setHandle(resourceBo);
        resrce.setStatusBo(statusBo);
        resrceMapper.updateById(resrce);
    }

    @Override
    public List<Resrce> findResourceListByResourceType(String site, String resourceTypeBo) {
        return resrceMapper.findResourceListByResourceType(site,resourceTypeBo);
    }

    @Override
    public List<Map<String, Object>> getResourceOperation(String resourceBo) {
        return resrceMapper.selectResourceOperation(resourceBo);
    }

    @Override
    public ResrceWorkCenter findResourceAndWorkCenterByResource(Resrce resrce) {
        return resrceMapper.findResourceAndWorkCenterByResource(resrce);
    }

    @Override
    public List<Resrce> getResourceListByUT(String site, String resourceType, String[] userList) {
        return resrceMapper.selectResourceListByUT(site, resourceType, userList);
    }

    @Override
    public List<Resrce> findResourceCustomList(String resource, String customField) {
        String site = CommonMethods.getSite();
        return resrceMapper.findCustomFieldsList(site,resource,customField);
    }


}