package cn.pluss.platform.controller.merchantRejectDesc;


import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.entity.MerchantRejectDesc;
import cn.pluss.platform.merchantRejectDesc.MerchantRejectDescService;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bzg
 * @since 2021-01-11
 */
@Controller
@RequestMapping("/merchantRejectDesc")
public class MerchantRejectDescController extends BaseModelController<MerchantRejectDescService, MerchantRejectDesc> {

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/index")
    public String index(HttpServletRequest request) {
        Integer sort = this.baseService.getMaxSort();
        request.setAttribute("sort",sort);
        return "merchantRejectDesc/list";
    }


    @Override
    public Result<Page<MerchantRejectDesc>> page(Page<MerchantRejectDesc> page, MerchantRejectDesc condition, OrderItem orderItem) {
        orderItem.setAsc(false).setColumn("sort");
        return super.page(page, condition, orderItem);
    }

    @PostMapping("saveOrUpdate")
    @ResponseBody
    public Result<String> saveOrUpdate(@RequestBody MerchantRejectDesc merchantRejectDesc) {
        if (merchantRejectDesc.getId() != null){
            this.baseService.updateById(merchantRejectDesc);
        }else {
            this.baseService.save(merchantRejectDesc);
        }
        return ResultGenerator.genSuccessResult("保存成功");
    }
}
