package com.scm.contract.web.purchase;

import com.scm.contract.model.purchase.TagProvider;
import com.scm.contract.service.purchase.TagProviderService;
import com.scm.contract.tools.HumpLineAdopter;
import com.set.direwolf.core.mybatis.Page;
import com.set.direwolf.core.web.OperationResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 供应商信息
 *
 * @author zuo
 * @date 2024/6/7 11:09
 */

@Controller
@RequestMapping("${adminPath}/tag/provider")
public class TagProviderController {

    private final TagProviderService tagProviderService;

    @Autowired
    public TagProviderController(TagProviderService tagProviderService) {
        this.tagProviderService = tagProviderService;
    }

    @PostMapping("/list")
    public @ResponseBody OperationResult List() {
        return OperationResult.buildSuccessResult("获取标签供应商信息成功", tagProviderService.list());
    }

    /**
     * 分页查询数据获取
     *
     * @param entity   参数实体
     * @param request  请求
     * @param response 响应
     * @return Page
     */
    @PostMapping("/page")
    public @ResponseBody OperationResult page(@RequestBody TagProvider entity, HttpServletRequest request, HttpServletResponse response) {
        Page<TagProvider> page = Page.bootstrapPage(request, response);
        List<List<String>> orderList = entity.getOrder();
        String defaultOrder = HumpLineAdopter.humpToLine(orderList);
        if (StringUtils.isNotEmpty(defaultOrder)) {
            page.setOrderBy(defaultOrder);
        }
        return OperationResult.buildSuccessResult("获取标签供应商分页查询信息成功", tagProviderService.findPage(page, entity));
    }
}
