/**
 * Created by Tony on 2017/4/20.
 */
var express = require("express");
var apiRouter =express.Router();
//var _rootDir = __dirname;
import ViewsController from "../controllers/repository_views_controller";
import RationRepositoryController from "../controllers/ration_repository_controller";
import RationChapterTreeController from "../controllers/ration_section_tree_controller";
import RationController from "../controllers/ration_controller";
import RepositoryGljController from "../controllers/repository_glj_controller";
import CoeListController from "../controllers/coe_controller";
import SearchController from "../controllers/search_controller";
import GljController from "../../std_glj_lib/controllers/gljController";
import InstallationController from '../controllers/installation_controller';
let viewsController = new ViewsController();
let rationRepositoryController = new RationRepositoryController();
let rationChapterTreeController = new RationChapterTreeController();
let rationController = new RationController();
let coeListController = new CoeListController();
let installationController = new InstallationController();
let searchController = new SearchController();
let repositoryGljController = new RepositoryGljController();
let gljController = new GljController();

module.exports =  function (app) {
    app.get('/rationRepository/main', viewsController.auth, viewsController.init, viewsController.redirectMain);
    app.get('/rationRepository/ration',viewsController.auth, viewsController.init, viewsController.redirectRation);
    app.get('/rationRepository/lmm', viewsController.auth, viewsController.init, viewsController.redirectGlj);
    app.get('/rationRepository/coeList', viewsController.auth, viewsController.init, viewsController.redirectCoeList);
    app.get('/rationRepository/installation', viewsController.auth, viewsController.init, viewsController.redirectInstallation);

    apiRouter.post("/prepareInitData", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.prepareInitData);
    apiRouter.post("/getCompilationList", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getCompilationList);
    apiRouter.post("/getRationLibsByCompilation", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLibsByCompilation);
    apiRouter.post("/getRationLib",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLib);

    apiRouter.post("/getRationDisplayNames",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getDisPlayRationLibs);
    apiRouter.post("/editRationLibs",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.updateRationRepositoryName);
    apiRouter.post("/addRationRepository",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.addRationRepository);
    apiRouter.post("/deleteRationLibs",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.deleteRationLib);
    apiRouter.post("/getRealLibName",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRealLibName);
    apiRouter.post("/getLibIDByName",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getLibIDByName);

    apiRouter.get('/sectionTemplateCount/:compilationId', rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.sectionTemplateCount);
    apiRouter.post('/initSectionTemplate', rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.initSectionTemplate);
    apiRouter.post("/getRationTree",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getRationChapterTree);
    apiRouter.post("/getNewRationTreeID",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getNewRationTreeID);
    apiRouter.post("/createNewNode",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.createNewNode);
    apiRouter.post("/updateNodes",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateNodes);
    apiRouter.post("/deleteNodes",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.deleteNodes);
    apiRouter.post("/updateExplanation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateExplanation);
    apiRouter.post("/updateRuleText",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateRuleText);
    apiRouter.post("/updateSituation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateSituation);
    apiRouter.post("/updateAnnoSituation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateAnnoSituation);

    apiRouter.post("/getRationItems",rationController.auth, rationController.init, rationController.getRationItemsBySection);
    apiRouter.post("/getRationItemsByLib",rationController.auth, rationController.init, rationController.getRationItemsByLib);
    apiRouter.post("/mixUpdateRationItems",rationController.auth, rationController.init, rationController.mixUpdateRationItems);
    apiRouter.post("/updateRationBasePrc",rationController.auth, rationController.init, rationController.updateRationBasePrc);
    apiRouter.post("/getRationGljIds",rationController.auth, rationController.init, rationController.getRationGljIds);
    apiRouter.post("/getRationsCodes",rationController.auth, rationController.init, rationController.getRationsCodes);
    apiRouter.post("/updateJobContent",rationController.auth, rationController.init, rationController.updateJobContent);
    apiRouter.post("/updateAnnotation",rationController.auth, rationController.init, rationController.updateAnnotation);
    apiRouter.post("/updateRationTemplate",rationController.auth, rationController.init, rationController.updateRationTemplate);
    apiRouter.post("/updateRationBySection",rationController.auth, rationController.init, rationController.updateRationBySection);

    apiRouter.post("/createNewGljTypeNode",repositoryGljController.auth, gljController.init, gljController.createNewGljTypeNode);
    apiRouter.post("/updateGljNodes",repositoryGljController.auth, gljController.init, gljController.updateGljNodes);
    apiRouter.post("/deleteGljNodes",repositoryGljController.auth, gljController.init, gljController.deleteGljNodes);
    apiRouter.post("/getGljDistType",repositoryGljController.auth, gljController.init, gljController.getGljDistType);
    apiRouter.post("/getGljTree",repositoryGljController.auth, gljController.init, gljController.getGljTree);
    apiRouter.post("/getGljItems",repositoryGljController.auth, gljController.init, gljController.getGljItems);
    apiRouter.post("/mixUpdateGljItems",repositoryGljController.auth, gljController.init, gljController.mixUpdateGljItems);
    apiRouter.post("/getGljItemsByIds",repositoryGljController.auth, gljController.init, gljController.getGljItemsByIds);
    apiRouter.post("/getGljItemsByCodes",repositoryGljController.auth, gljController.init, gljController.getGljItemsByCodes);

    apiRouter.post("/getCoeReference",coeListController.auth, coeListController.init, coeListController.getCoeReference);
    apiRouter.post("/getCoeList",coeListController.auth, coeListController.init, coeListController.getCoeList);
    apiRouter.post("/saveCoeList",coeListController.auth, coeListController.init, coeListController.saveCoeList);
    apiRouter.post("/getCoeItemsByIDs",coeListController.auth, coeListController.init, coeListController.getCoeItemsByIDs);
    apiRouter.post("/getCoeItemsByNos",coeListController.auth, coeListController.init, coeListController.getCoeItemsByNos);

    //安装增加费
    apiRouter.post('/getInstallation', installationController.auth, installationController.init, installationController.getInstallation);
    apiRouter.post('/updateFeeItem', installationController.auth, installationController.init, installationController.updateFeeItem);
    apiRouter.post('/updateSection', installationController.auth, installationController.init, installationController.updateSection);
    apiRouter.post('/batchUpdateInst', installationController.auth, installationController.init, installationController.batchUpdateInst);

    apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
    apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);

    apiRouter.post('/reCalcAll', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.reCalcAll);
    // 导入导出定额库相关
    apiRouter.post('/upload', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.uploadSourceData);
    apiRouter.get('/export', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.exportRationData);

    app.use("/rationRepository/api",apiRouter);
}
