package com.fh.controller.dst.datasource2; 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.util.AppUtil; import com.fh.util.ObjectExcelView; import com.fh.util.PageData; import com.fh.util.Jurisdiction; import com.fh.service.dst.datasource2.DataSource2Manager; /** * 说明:第2数据源例子 * 创建时间:2016-04-29 */ @Controller @RequestMapping(value="/datasource2") public class DataSource2Controller extends BaseController { String menuUrl = "datasource2/list.do"; //菜单地址(权限用) @Resource(name="datasource2Service") private DataSource2Manager datasource2Service; /**保存 * @param * @throws Exception */ @RequestMapping(value="/save") public ModelAndView save() throws Exception{ logBefore(logger, Jurisdiction.getUsername()+"新增DataSource2"); if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;} //校验权限 ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); pd.put("DATASOURCE2_ID", this.get32UUID()); //主键 datasource2Service.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()+"删除DataSource2"); if(!Jurisdiction.buttonJurisdiction(menuUrl, "del")){return;} //校验权限 PageData pd = new PageData(); pd = this.getPageData(); datasource2Service.delete(pd); out.write("success"); out.close(); } /**修改 * @param * @throws Exception */ @RequestMapping(value="/edit") public ModelAndView edit() throws Exception{ logBefore(logger, Jurisdiction.getUsername()+"修改DataSource2"); if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限 ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); datasource2Service.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()+"列表DataSource2"); //if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;} //校验权限(无权查看时页面会有提示,如果不注释掉这句代码就无法进入列表页面,所以根据情况是否加入本句代码) 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 varList = datasource2Service.list(page); //列出DataSource2列表 mv.setViewName("dst/datasource2/datasource2_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("dst/datasource2/datasource2_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 = datasource2Service.findById(pd); //根据ID读取 mv.setViewName("dst/datasource2/datasource2_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()+"批量删除DataSource2"); if(!Jurisdiction.buttonJurisdiction(menuUrl, "del")){return null;} //校验权限 PageData pd = new PageData(); Map map = new HashMap(); pd = this.getPageData(); List pdList = new ArrayList(); String DATA_IDS = pd.getString("DATA_IDS"); if(null != DATA_IDS && !"".equals(DATA_IDS)){ String ArrayDATA_IDS[] = DATA_IDS.split(","); datasource2Service.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()+"导出DataSource2到excel"); if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;} ModelAndView mv = new ModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); Map dataMap = new HashMap(); List titles = new ArrayList(); titles.add("标题"); //1 titles.add("内容"); //2 dataMap.put("titles", titles); List varOList = datasource2Service.listAll(pd); List varList = new ArrayList(); for(int i=0;i