import asyncHandler = require('express-async-handler');
import { eccReqParamater } from '../util/verificationParam';
import * as diKuaiBiz from '../biz/admin/diKuai';
import * as userBiz from '../biz/admin/user';
import * as zhongYangBiz from '../biz/admin/zhongYang';
import * as nongziBiz from '../biz/admin/nongzi';
import * as caishouBiz from '../biz/admin/caiShou';
import * as nongShiBiz from '../biz/admin/nongShi';
import * as publicRouters from './public';
import * as xiaoShouBiz from '../biz/admin/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/dikuai/xuanze/list', checkAdminUserToken, asyncHandler(xuanze_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;
    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;

    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;

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


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

async function dikuai_list(req, res) {
    let reqConf = {code:'String', area:'String', purpose:'Number', pageNumber:'Number'};
    let { code, area, purpose, pageNumber } = eccReqParamater(reqConf, req.body, ["code", "area", "purpose"]);
    let result = await diKuaiBiz.diKuaiListToPage(code, area, purpose, pageNumber);
    res.success(result);
}

async function xuanze_dikuai_list(req, res) {
    const UserInfo = req.userInfo;
    let reqConf = { zhongYangType:'Number'};
    let { zhongYangType } = eccReqParamater(reqConf, req.body, ["zhongYangType"]);
    let result = await diKuaiBiz.keXuanDiKuaiList(zhongYangType);
    res.success(result);
}



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

    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;
    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", plantType:"Number", dId:"String", plantTime:"Number", pageNumber:"Number"};
    let { zhongYangType, plantType, dId, plantTime, pageNumber } = eccReqParamater(reqConf, req.body, ["dId", "plantType", "zhongYangType", "plantTime"]);
    let result = await zhongYangBiz.zhongYangDangQianListToPage(zhongYangType, plantType, dId, plantTime, 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;
    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;
    let result = await nongziBiz.updateNongZi(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.nongZiInfo(nzId);
    res.success(result);
}

async function nongzi_list(req, res) {
    let reqConf = {nzType:'Number', dIdList:'Number', useTime:'Number', pageNumber:'Number'};
    let { nzType, dIdList, useTime, pageNumber } = eccReqParamater(reqConf, req.body, ["nzType", "dIdList", "useTime"]);
    let result = await nongziBiz.nongZiListToPage(nzType, dIdList, useTime, pageNumber);
    res.success(result);
}


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


//todo
async function nongshi_add(req, res) {
    let reqConf = {param:'Object'};
    let { param } = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers;
    let result = await nongShiBiz.addNongShi(userInfo, param);
    res.success(result);
}


async function nongshi_update(req, res) {
    let reqConf = {param:'Object', nsId:"String"};
    let { param, nsId} = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers;
    let result = await nongShiBiz.updateNongShi(userInfo, nsId, param);
    res.success(result);
}

async function nongshi_info(req, res) {
    let reqConf = {nsId:'String'};
    let { nsId } = eccReqParamater(reqConf, req.body);
    let result = await nongShiBiz.nongShiInfo(nsId);
    res.success(result);
}

async function nongshi_list(req, res) {
    let reqConf = {nsType:'Number', dId:'String', operationTime:'Number', pageNumber:'Number'};
    let { nsType, dId, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["nsType", "dId", "operationTime"]);
    let result = await nongShiBiz.nongShiList(nsType, dId, operationTime, pageNumber);
    res.success(result);
}

async function nongshi_del(req, res) {
    let reqConf = {nsId:'String'};
let { nsId } = eccReqParamater(reqConf, req.body);
let result = await nongShiBiz.deleteNongShi(nsId);
res.success(result);
}

async function caishou_add(req, res) {
    let reqConf = {param: 'Object'};
    const NotMustHaveKeys = [];
    let { param } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);

    const UserInfo = req.userInfo;

    let result = await caishouBiz.addCaiShou(UserInfo, param);
    res.success(result);
}

async function caishou_update(req, res) {
    let reqConf = {param:'Object', csId:"String"};
    let { param, csId} = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers;
    let result = await caishouBiz.updateCaiShou(userInfo, csId, param);
    res.success(result);
}

async function caishou_info(req, res) {
    let reqConf = {csId:'String'};
let { csId } = eccReqParamater(reqConf, req.body);
let result = await caishouBiz.caishouInfo(csId);
res.success(result);
}

async function caishou_list(req, res) {
    let reqConf = {zhongYangType:'Number', dId:'String', plantType:'Number', operationTime:'Number', pageNumber:'Number'};
let { zhongYangType, dId, plantType, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["dId", "plantType", "operationTime"]);
let result = await caishouBiz.caiShouList(zhongYangType, dId, plantType, operationTime, pageNumber);
res.success(result);
}

async function caishou_del(req, res) {
    let reqConf = {csId:'String'};
let { csId } = eccReqParamater(reqConf, req.body);
let result = await caishouBiz.deleteCaiShou(csId);
res.success(result);
}

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

    const UserInfo = req.userInfo;

    let result = await xiaoShouBiz.addXiaoShou(UserInfo, param);
    res.success(result);
}

async function xiaoshou_update(req, res) {
    let reqConf = {param:'Object', xsId:"String"};
    let { param, xsId} = eccReqParamater(reqConf, req.body);
    let userInfo = req.headers;
    let result = await xiaoShouBiz.updateXiaoShou(userInfo, xsId, param);
    res.success(result);
}

async function xiaoshou_info(req, res) {
    let reqConf = {xsId:'String'};
let { xsId } = eccReqParamater(reqConf, req.body);
let result = await xiaoShouBiz.xiaoShouInfo(xsId);
res.success(result);
}

async function xiaoshou_list(req, res) {
    let reqConf = {quXiang:'Number', plantType:'Number', operationTime:'Number', pageNumber:'Number'};
let { quXiang, plantType, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["quXiang", "plantType", "operationTime"]);
let result = await xiaoShouBiz.xiaoShouList(quXiang, plantType, operationTime, pageNumber);
res.success(result);
}

async function xiaoshou_del(req, res) {
    let reqConf = {xsId:'String'};
let { xsId } = eccReqParamater(reqConf, req.body);
let result = await xiaoShouBiz.deleteXiaoShou(xsId);
res.success(result);
}
