InstantQuestionDataSource1Controller.java 7.36 KB
package com.fh.controller.sunvote.instantquestiondatasource1;

import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.service.sunvote.instantquestiondatasource1.InstantQuestionDataSource1Manager;
import com.fh.util.AppUtil;
import com.fh.util.Jurisdiction;
import com.fh.util.ObjectExcelView;
import com.fh.util.PageData;

/** 
 * 说明:即时测题库1
 * 创建人:FH Q313596790
 * 创建时间:2019-05-29
 */
@Controller
@RequestMapping(value="/instantquestiondatasource1")
public class InstantQuestionDataSource1Controller extends BaseController {
	
	String menuUrl = "instantquestiondatasource1/list.do"; //菜单地址(权限用)
	@Resource(name="instantquestiondatasource1Service")
	private InstantQuestionDataSource1Manager instantquestiondatasource1Service;
	
	/**保存
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/save")
	public ModelAndView save() throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"新增InstantQuestionDataSource1");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("INSTANTQUESTIONDATASOURCE1_ID", this.get32UUID());	//主键
		instantquestiondatasource1Service.save(pd);
		mv.addObject("msg","success");
		mv.setViewName("save_result");
		return mv;
	}
	
	/**删除
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	public void delete(PrintWriter out) throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"删除InstantQuestionDataSource1");
		PageData pd = new PageData();
		pd = this.getPageData();
		instantquestiondatasource1Service.delete(pd);
		out.write("success");
		out.close();
	}
	
	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	public ModelAndView edit() throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"修改InstantQuestionDataSource1");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		instantquestiondatasource1Service.edit(pd);
		mv.addObject("msg","success");
		mv.setViewName("save_result");
		return mv;
	}
	
	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	public ModelAndView list(Page page) throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"列表InstantQuestionDataSource1");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		String keywords = pd.getString("keywords");				//关键词检索条件
		if(null != keywords && !"".equals(keywords)){
			pd.put("keywords", keywords.trim());
		}
		page.setPd(pd);
		List<PageData>	varList = instantquestiondatasource1Service.list(page);	//列出InstantQuestionDataSource1列表
		mv.setViewName("sunvote/instantquestiondatasource1/instantquestiondatasource1_list");
		mv.addObject("varList", varList);
		mv.addObject("pd", pd);
		mv.addObject("QX",Jurisdiction.getHC());	//按钮权限
		return mv;
	}
	
	/**去新增页面
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goAdd")
	public ModelAndView goAdd()throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		mv.setViewName("sunvote/instantquestiondatasource1/instantquestiondatasource1_edit");
		mv.addObject("msg", "save");
		mv.addObject("pd", pd);
		return mv;
	}	
	
	 /**去修改页面
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	public ModelAndView goEdit()throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = instantquestiondatasource1Service.findById(pd);	//根据ID读取
		mv.setViewName("sunvote/instantquestiondatasource1/instantquestiondatasource1_edit");
		mv.addObject("msg", "edit");
		mv.addObject("pd", pd);
		return mv;
	}	
	
	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public Object deleteAll() throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"批量删除InstantQuestionDataSource1");
		PageData pd = new PageData();		
		Map<String,Object> map = new HashMap<String,Object>();
		pd = this.getPageData();
		List<PageData> pdList = new ArrayList<PageData>();
		String DATA_IDS = pd.getString("DATA_IDS");
		if(null != DATA_IDS && !"".equals(DATA_IDS)){
			String ArrayDATA_IDS[] = DATA_IDS.split(",");
			instantquestiondatasource1Service.deleteAll(ArrayDATA_IDS);
			pd.put("msg", "ok");
		}else{
			pd.put("msg", "no");
		}
		pdList.add(pd);
		map.put("list", pdList);
		return AppUtil.returnObject(pd, map);
	}
	
	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excel")
	public ModelAndView exportExcel() throws Exception{
		logBefore(logger, Jurisdiction.getUsername()+"导出InstantQuestionDataSource1到excel");
		ModelAndView mv = new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		Map<String,Object> dataMap = new HashMap<String,Object>();
		List<String> titles = new ArrayList<String>();
		titles.add("图片路径");	//1
		titles.add("分数");	//2
		titles.add("答案内容");	//3
		titles.add("标准答案");	//4
		titles.add("标签");	//5
		titles.add("权限");	//6
		titles.add("科目");	//7
		titles.add("年级");	//8
		titles.add("学校");	//9
		titles.add("用户ID");	//10
		titles.add("创建时间");	//11
		titles.add("班级");	//12
		dataMap.put("titles", titles);
		List<PageData> varOList = instantquestiondatasource1Service.listAll(pd);
		List<PageData> varList = new ArrayList<PageData>();
		for(int i=0;i<varOList.size();i++){
			PageData vpd = new PageData();
			vpd.put("var1", varOList.get(i).getString("IMAGE_URL"));	    //1
			vpd.put("var2", varOList.get(i).get("SCORE").toString());	//2
			vpd.put("var3", varOList.get(i).getString("ANSWER_CONTENT"));	    //3
			vpd.put("var4", varOList.get(i).getString("RIGHT_ANSWER"));	    //4
			vpd.put("var5", varOList.get(i).getString("TAG"));	    //5
			vpd.put("var6", varOList.get(i).getString("PERMISSION"));	    //6
			vpd.put("var7", varOList.get(i).getString("SUBJECT_ID"));	    //7
			vpd.put("var8", varOList.get(i).getString("GRADE_ID"));	    //8
			vpd.put("var9", varOList.get(i).getString("SCHOOL_ID"));	    //9
			vpd.put("var10", varOList.get(i).getString("USER_ID"));	    //10
			vpd.put("var11", varOList.get(i).getString("CREATE_DATE"));	    //11
			vpd.put("var12", varOList.get(i).getString("CLASS_ID"));	    //12
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}
	
	@InitBinder
	public void initBinder(WebDataBinder binder){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
	}
}