package com.scm.contract.web.cancel;

import com.scm.contract.model.cancel.TagCancel;
import com.scm.contract.service.cancel.TagCancelService;
import com.scm.contract.tools.HumpLineAdopter;
import com.scm.contract.web.apply.LabelApplicationController;
import com.set.direwolf.core.mybatis.Page;
import com.set.direwolf.core.web.BaseController;
import com.set.direwolf.core.web.OperationResult;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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/7/25 11:54
 */
@Controller
@RequestMapping("${adminPath}/tag/cancel")
public class TagCancelController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(LabelApplicationController.class);

    private final TagCancelService entityService;

    @Autowired
    public TagCancelController(TagCancelService entityService) {
        this.entityService = entityService;
    }

    /**
     * 获取标签作废记录分页查询信息成功
     *
     * @param entity   参数实体
     * @param request  请求
     * @param response 响应
     * @return Page
     */
    @PostMapping("/page")
    public @ResponseBody OperationResult page(@RequestBody TagCancel entity, HttpServletRequest request, HttpServletResponse response) {
        Page<TagCancel> 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("获取标签作废记录分页查询信息成功", entityService.findPage(page, entity));
    }

    /**
     * 新建作废标签
     *
     * @param entity 参数实体
     * @return
     */
    @PostMapping("")
    public @ResponseBody OperationResult saveList(@RequestBody TagCancel entity) {
        entityService.saveTagCancel(entity);
        return OperationResult.buildSuccessResult("新建作废标签成功", true);
    }
}
