package com.zhiqiyun.open.router.apis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dliyun.oap.framework.annotation.ServiceMethod;
import com.dliyun.oap.framework.annotation.ServiceMethodBean;
import com.dliyun.oap.framework.response.OapResponse;
import com.zhiqiyun.open.core.models.category.CategoryMaterial;
import com.zhiqiyun.open.core.models.category.CategoryOccupation;
import com.zhiqiyun.open.core.service.CategoryMaterialService;
import com.zhiqiyun.open.core.service.CategoryOccupationService;
import com.zhiqiyun.open.router.request.category.CategoryMaterialRequest;
import com.zhiqiyun.open.router.request.category.CategoryOccupationRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@ServiceMethodBean
public class CategoryApi {

    @Autowired
    private CategoryMaterialService categoryMaterialService;

    @Autowired
    private CategoryOccupationService categoryOccupationService;

    @ServiceMethod(method = "list.category.occupation", title = "查询文旅岗位目录")
    public OapResponse listCategoryOccupation(CategoryOccupationRequest request) {
        QueryWrapper<CategoryOccupation> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getName())) {
            queryWrapper.like("name", request.getName());
        }

        queryWrapper.orderByDesc("sort_number");
        queryWrapper.orderByDesc("id");

        List<CategoryOccupation> listData = this.categoryOccupationService.list(queryWrapper);

        return OapResponse.success().setBody(listData);
    }

    @ServiceMethod(method = "list.category.material", title = "物务资源目录")
    public OapResponse listPageSceneryInfo(CategoryMaterialRequest request) {
        QueryWrapper<CategoryMaterial> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getName())) {
            queryWrapper.like("name", request.getName());
        }

        queryWrapper.orderByDesc("sort_number");
        queryWrapper.orderByDesc("id");

        List<CategoryMaterial> listData = this.categoryMaterialService.list(queryWrapper);

        return OapResponse.success().setBody(listData);
    }

}
