package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.controller.admin.BaseController;
import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSEcologicalCivilizationService;
import com.lightinit.hsdatashow.service.ms.IMSInnovateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedHashMap;
import java.util.List;

@Controller
@RequestMapping(value = "/ms/innovate")
public class MSInnovateController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("R&D人员全时当量","RdPersonnel");
        map.put("科学家和工程师占比","ScientistsEngineers");
        map.put("高技术产品出口占比","TechnicalProducts");
        map.put("万人专利授权数","PatentAuthorization");
        return map;
    }
    @Autowired
    private IMSInnovateService imsInnovateService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/innovate/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/innovate/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=imsInnovateService.list(tableType,pager);
        long total=imsInnovateService.queryCount(tableType);
        pager.setTotal(total);
        modelAndView.addObject("list",list);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

    @RequestMapping(value="add.htm")
    public ModelAndView add(String tableType,Long id){
        ModelAndView modelAndView=new ModelAndView("ms/innovate/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
            obj=imsInnovateService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

    @RequestMapping(value="delete.action")
    @ResponseBody
    public ResultState delete(String tableType, Long id) {
        ResultState resultState =imsInnovateService.delete(tableType,id);
        return resultState;
    }

    @RequestMapping(value="addRdPersonnel.action")
    @ResponseBody
    public ResultState addRdPersonnel(RdPersonnel rdPersonnel){
        boolean isEdit=rdPersonnel.getId()==null?false:true;
        ResultState resultState=imsInnovateService.add(rdPersonnel,isEdit);
        return resultState;
    }

    @RequestMapping(value="addScientistsEngineers.action")
    @ResponseBody
    public ResultState addScientistsEngineers(ScientistsEngineers scientistsEngineers){
        boolean isEdit=scientistsEngineers.getId()==null?false:true;
        ResultState resultState=imsInnovateService.add(scientistsEngineers,isEdit);
        return resultState;
    }

    @RequestMapping(value="addTechnicalProducts.action")
    @ResponseBody
    public ResultState addTechnicalProducts(TechnicalProducts technicalProducts){
        boolean isEdit=technicalProducts.getId()==null?false:true;
        ResultState resultState=imsInnovateService.add(technicalProducts,isEdit);
        return resultState;
    }

    @RequestMapping(value="addPatentAuthorization.action")
    @ResponseBody
    public ResultState addPatentAuthorization(PatentAuthorization patentAuthorization){
        boolean isEdit=patentAuthorization.getId()==null?false:true;
        ResultState resultState=imsInnovateService.add(patentAuthorization,isEdit);
        return resultState;
    }

}
