package cn.pluss.platform.controller.openAccount;


import cn.pluss.platform.api.Result;
import cn.pluss.platform.areaCity.AreaCityService;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.openAccount.OpenAccountConfigService;
import cn.pluss.platform.user.UserRoleService;
import com.alibaba.fastjson.JSON;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 开户奖配置表 前端控制器
 * </p>
 *
 * @author crystal
 * @since 2022-06-14
 */
@Controller
@RequestMapping("/openAccountConfig")
public class OpenAccountConfigController extends BaseModelController<OpenAccountConfigService, OpenAccountConfig> {

    @Resource
    private UserRoleService userRoleService;

    @Resource
    private AreaCityService areaCityService;

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/index")
    public String index(HttpServletRequest request) {
        List<UserRole> list = userRoleService.list();
        request.setAttribute("roleList", JSON.toJSONString(list));
        return "openAccount/configList";
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = {"/detail/{id}", "/detail"})
    public String detail(HttpServletRequest request, @PathVariable(value = "id", required = false) Integer id) {
        List<AreaCity> areaCities = areaCityService.queryOnlyProvince();
        List<UserRole> list = userRoleService.list();
        if (id != null) {
            OpenAccountConfig entity = baseService.getById(id);
            request.setAttribute("entity", entity);
        }
        request.setAttribute("roleList",list);
        request.setAttribute("pList", areaCities);
        return "openAccount/configDetail";
    }

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

}
