package cn.pluss.platform.controller.cash;


import cn.pluss.platform.api.Result;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.cashAccount.CashAccountService;
import cn.pluss.platform.entity.CashAccount;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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-07-23
 */
@Controller
@RequestMapping("/cashAccount")
public class CashAccountController extends BaseModelController<CashAccountService, CashAccount> {

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/index")
    public String index() {
        return "cash/account/list";
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = {"/detail/{id}", "/detail"})
    public String detail(HttpServletRequest request, @PathVariable(value = "id", required = false) Integer id) {
        if (id != null) {
            CashAccount cashAccount = new CashAccount().setId(id);
            cashAccount = baseService.getOne(new QueryWrapper<>(cashAccount));
            request.setAttribute("entity", cashAccount);
        }
        return "cash/account/detail";
    }

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