package cn.com.countrygarden.bi.main.controller.advise;

import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dto.advise.AfAdviseConfigDTO;
import cn.com.countrygarden.bi.main.dto.advise.param.AdviseConfigParam;
import cn.com.countrygarden.bi.main.model.advise.AfAdviseConfig;
import cn.com.countrygarden.bi.main.service.advise.IAfAdviseConfigService;
import cn.com.countrygarden.bi.main.service.advise.util.AdviseUtil;
import cn.com.countrygarden.bi.main.util.roleUtils.AuthorityCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
/**
 * 建言基础设置-控制层实现
 *
 * @author 木木子
 * @email 944528607@qq.com
 * @url 
 * @date 2019-04-15
 */
@RestController("AfAdviseConfigController")
@RequestMapping("/api/afAdviseConfig")
public class AfAdviseConfigController extends BaseController{
    @Autowired
    private IAfAdviseConfigService afAdviseConfigService;

    @Autowired
    private AdviseUtil adviseUtil;

    @GetMapping(value="/handletimeOut",produces="application/json;charset=utf-8")
    public Result handletimeOut() throws InterruptedException {
    return Response.response(adviseUtil.timeOutAdviseProcess()) ;
    }


    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(AfAdviseConfig afAdviseConfig,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request){
        return  afAdviseConfigService.queryPageList(afAdviseConfig,page,size);
    }
    @AuthorityCheck(authorityArray={"adviseSystemAdmin"} )
    @GetMapping(value = "/one", produces = "application/json;charset=utf-8")
    public Result queryByOne(AdviseConfigParam adviseConfigParam,
                             HttpServletRequest request){
        return  afAdviseConfigService.queryByOne(adviseConfigParam);
    }

    @PostMapping(value = "/addOrEdit")
    public Result add(AfAdviseConfigDTO adviseBranchTypeDTO,
                      HttpServletRequest request){
        return  afAdviseConfigService.addOrEdit(adviseBranchTypeDTO,getAccessToken(request));
    }


    @DeleteMapping(value="/del")
    public Result del(@RequestParam(value = "id", required = true)Integer id){
        return  afAdviseConfigService.del(id);
    }


}