import * as asyncHandler from 'express-async-handler'
import { eccReqParamater } from '../util/verificationParam';
import * as diKuaiBiz from '../biz/diKuai';
import * as userBiz from '../biz/user';
import * as zhongYangBiz from '../biz/zhongYang';
import * as nongziBiz from '../biz/nongzi';
import * as nongShiBiz from '../biz/nongShi';
import * as publicRouters from './public';
import * as caiShouBiz from '../biz/caiShou';
import * as xiaoShouBiz from '../biz/xiaoShou';
import { checkAdminUserToken } from '../middleware/user';
import * as dataOutBiz from '../biz/dataOut';

export function setRouter(httpServer){
    /**地块 */
    httpServer.post('/zjnt/xcxadmin/dikuai/add', checkAdminUserToken,  asyncHandler(dikuai_add));//地块添加 '/zjnt/xcxadmin/dikuai/add'
    httpServer.post('/zjnt/xcxadmin/dikuai/update', checkAdminUserToken,  asyncHandler(dikuai_update));//地块修改 '/zjnt/xcxadmin/dikuai/update'
    httpServer.post('/zjnt/xcxadmin/dikuai/info', checkAdminUserToken,  asyncHandler(dikuai_info));//地块回显 '/zjnt/xcxadmin/dikuai/info'
    httpServer.post('/zjnt/xcxadmin/dikuai/list', checkAdminUserToken, asyncHandler(dikuai_list));//地块列表 '/zjnt/xcxadmin/dikuai/list'

    /**种养 */
    httpServer.post('/zjnt/xcxadmin/zhongyang/add', checkAdminUserToken,  asyncHandler(zhongyang_add));//种养添加 '/zjnt/xcxadmin/zhongyang/add'
    httpServer.post('/zjnt/xcxadmin/zhongyang/update', checkAdminUserToken,  asyncHandler(zhongyang_update));//种养修改 '/zjnt/xcxadmin/zhongyang/update'
    httpServer.post('/zjnt/xcxadmin/zhongyang/info', checkAdminUserToken,  asyncHandler(zhongyang_info));//种养回显 '/zjnt/xcxadmin/zhongyang/info'
    httpServer.post('/zjnt/xcxadmin/zhongyang/list', checkAdminUserToken, asyncHandler(zhongyang_list));//种养列表 '/zjnt/xcxadmin/zhongyang/list'
    httpServer.post('/zjnt/xcxadmin/zhongyang/del', checkAdminUserToken, asyncHandler(zhongyang_del));//种养删除 '/zjnt/xcxadmin/zhongyang/del'

    /**农资 */
    httpServer.post('/zjnt/xcxadmin/nongzi/add', checkAdminUserToken,  asyncHandler(nongzi_add));//农资添加 '/zjnt/xcxadmin/nongzi/add'
    httpServer.post('/zjnt/xcxadmin/nongzi/update', checkAdminUserToken,  asyncHandler(nongzi_update));//农资修改 '/zjnt/xcxadmin/nongzi/update'
    httpServer.post('/zjnt/xcxadmin/nongzi/info', checkAdminUserToken,  asyncHandler(nongzi_info));//农资回显 '/zjnt/xcxadmin/nongzi/info'
    httpServer.post('/zjnt/xcxadmin/nongzi/list', checkAdminUserToken, asyncHandler(nongzi_list));//农资列表 '/zjnt/xcxadmin/nongzi/list'
    httpServer.post('/zjnt/xcxadmin/nongzi/del', checkAdminUserToken, asyncHandler(nongzi_del));//农资删除 '/zjnt/xcxadmin/nongzi/del'


    /**农事 */
    httpServer.post('/zjnt/xcxadmin/nongshi/add', checkAdminUserToken,  asyncHandler(nongshi_add));//农事添加 '/zjnt/xcxadmin/nongshi/add'
    httpServer.post('/zjnt/xcxadmin/nongshi/update', checkAdminUserToken,  asyncHandler(nongshi_update));//农事修改 '/zjnt/xcxadmin/nongshi/update'
    httpServer.post('/zjnt/xcxadmin/nongshi/info', checkAdminUserToken,  asyncHandler(nongshi_info));//农事回显 '/zjnt/xcxadmin/nongshi/info'
    httpServer.post('/zjnt/xcxadmin/nongshi/list', checkAdminUserToken, asyncHandler(nongshi_list));//农事列表 '/zjnt/xcxadmin/nongshi/list'
    httpServer.post('/zjnt/xcxadmin/nongshi/del', checkAdminUserToken, asyncHandler(nongshi_del));//农事删除 '/zjnt/xcxadmin/nongshi/del'

    /**采收 */
    httpServer.post('/zjnt/xcxadmin/caishou/add', checkAdminUserToken,  asyncHandler(caishou_add));//采收添加 '/zjnt/xcxadmin/caishou/add'
    httpServer.post('/zjnt/xcxadmin/caishou/update', checkAdminUserToken,  asyncHandler(caishou_update));//采收修改 '/zjnt/xcxadmin/caishou/update'
    httpServer.post('/zjnt/xcxadmin/caishou/info', checkAdminUserToken,  asyncHandler(caishou_info));//采收回显 '/zjnt/xcxadmin/caishou/info'
    httpServer.post('/zjnt/xcxadmin/caishou/list', checkAdminUserToken, asyncHandler(caishou_list));//采收列表 '/zjnt/xcxadmin/caishou/list'
    httpServer.post('/zjnt/xcxadmin/caishou/del', checkAdminUserToken, asyncHandler(caishou_del));//采收删除 '/zjnt/xcxadmin/caishou/del'

    /**销售 */
    httpServer.post('/zjnt/xcxadmin/xiaoshou/add', checkAdminUserToken,  asyncHandler(xiaoshou_add));//销售添加 '/zjnt/xcxadmin/xiaoshou/add'
    httpServer.post('/zjnt/xcxadmin/xiaoshou/update', checkAdminUserToken,  asyncHandler(xiaoshou_update));//销售修改 '/zjnt/xcxadmin/xiaoshou/update'
    httpServer.post('/zjnt/xcxadmin/xiaoshou/info', checkAdminUserToken,  asyncHandler(xiaoshou_info));//销售回显 '/zjnt/xcxadmin/xiaoshou/info'
    httpServer.post('/zjnt/xcxadmin/xiaoshou/list', checkAdminUserToken, asyncHandler(xiaoshou_list));//销售列表 '/zjnt/xcxadmin/xiaoshou/list'
    httpServer.post('/zjnt/xcxadmin/xiaoshou/del', checkAdminUserToken, asyncHandler(xiaoshou_del));//销售删除 '/zjnt/xcxadmin/xiaoshou/del'
    /**登录登出 */
    httpServer.post('/zjnt/xcxadmin/user/login', asyncHandler(user_login));//登录  '/zjnt/xcxadmin/user/login'
    httpServer.post('/zjnt/xcxadmin/user/logout', checkAdminUserToken, asyncHandler(user_logout));//登出  '/zjnt/xcxadmin/user/logout'

}

async function user_login(req, res) {
    let reqConf = {loginId:"String", pwd:"String"};
    let { loginId, pwd } = eccReqParamater(reqConf, req.body);
    let result = await userBiz.adminUserLogin(loginId, pwd);
    res.success(result);
}

async function user_logout(req, res) {
    let userInfo = req.headers.userInfo;
    let result = await userBiz.adminUserLogout(userInfo);
    res.success(result);
}



/** 地块 */
async function dikuai_add(req, res) {
    let reqConf = {plotType:'Number', param:'Object'};
    let { plotType, param } = eccReqParamater(reqConf, req.body);
    
    let userInfo = req.headers.userInfo;

    let result = await diKuaiBiz.addDiKuai(userInfo,  plotType, param);
    res.success(result);
}


async function dikuai_update(req, res) {
    let reqConf = {dId:'String', plotType:'Number', param:'Object'};
    let { dId, param, plotType } = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers.userInfo;

    let result = await diKuaiBiz.updateDiKuai(userInfo, plotType, dId, param);
    res.success(result);
}


async function dikuai_info(req, res) {
    let reqConf = {dId:'Number'};
    let { dId } = eccReqParamater(reqConf, req.body);
    let result = await diKuaiBiz.diKuaiInfo(dId);
    res.success(result);
}

async function  dikuai_list(req, res) {
    let reqConf = {pageNumber:'Number'};
    let { pageNumber } = eccReqParamater(reqConf, req.body);
    let result = await diKuaiBiz.diKuaiListToPage(pageNumber);
    res.success(result);
}



/** 种养*/
async function zhongyang_add(req, res) {
    let reqConf = {param:'Object'};
    let { param } = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers.userInfo;

    let result = await zhongYangBiz.addZhongYang(userInfo, param);
    res.success(result);
}

async function zhongyang_update(req, res) {
    let reqConf = {param:'Object', zId:"String"};
    let { param, zId } = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers.userInfo;
    let result = await zhongYangBiz.updateZhongYang(userInfo, zId, param);
    res.success(result);
}

async function zhongyang_info(req, res) {
    let reqConf = {zId:'String'};
    let { zId } = eccReqParamater(reqConf, req.body);
    let result = await zhongYangBiz.zhognYangInfo(zId);
    res.success(result);
}

async function zhongyang_list(req, res) {
    let reqConf = {zhongYangType:"Number", selectStr:"String", page:"Number"};
    let { zhongYangType, selectStr, pageNumber } = eccReqParamater(reqConf, req.body, ["zhongYangType", "selectStr"]);
    let result = await zhongYangBiz.zhongYangDangQianListToPage(zhongYangType, selectStr, pageNumber);
    res.success(result);
}

async function zhongyang_del(req, res) {
    let reqConf = {zId:'String'};
    let { zId } = eccReqParamater(reqConf, req.body);
    let result = await zhongYangBiz.deleteZhongYang(zId);
    res.success(result);
}



async function nongzi_add(req, res) {
    let reqConf = {param:'Object'};
    let { param } = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers.userInfo;

    let result = await nongziBiz.addNongZi(userInfo, param);
    res.success(result);
}



async function nongzi_update(req, res) {
    let reqConf = {param:'Object', nzId:"String"};
    let { param, nzId} = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers.userInfo;
    let result = await nongziBiz.updateZhongYang(userInfo, nzId, param);
    res.success(result);
}



async function nongzi_info(req, res) {
    let reqConf = {nzId:'String'};
    let { nzId } = eccReqParamater(reqConf, req.body);
    let result = await nongziBiz.zhongYangInfo(nzId);
    res.success(result);
}

async function nongzi_list(req, res) {
    let reqConf = {page:'Number'};
    let { page } = eccReqParamater(reqConf, req.body);
    let result = await nongziBiz.zhongYangListToPage(page);
    res.success(result);
}

//todo

async function nongzi_del(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function nongshi_add(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function nongshi_update(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function nongshi_info(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function nongshi_list(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function nongshi_del(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function caishou_add(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function caishou_update(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function caishou_info(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function caishou_list(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function caishou_del(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function xiaoshou_add(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function xiaoshou_update(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function xiaoshou_info(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function xiaoshou_list(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}

async function xiaoshou_del(req, res) {
    let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
