123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- package com.zhcs.dt.controller.system.dictionaries;
- 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 net.sf.json.JSONArray;
- import org.springframework.beans.propertyeditors.CustomDateEditor;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- 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.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
- import com.zhcs.dt.controller.base.BaseController;
- import com.zhcs.dt.entity.Page;
- import com.zhcs.dt.entity.system.Dictionaries;
- import com.zhcs.dt.service.system.dictionaries.DictionariesManager;
- import com.zhcs.dt.util.AppUtil;
- import com.zhcs.dt.util.Jurisdiction;
- import com.zhcs.dt.util.PageData;
- import com.zhcs.dt.util.Tools;
- /**
- * 说明:数据字典
- * 创建人:FH Q313596790
- * 创建时间:2015-12-16
- */
- @Controller
- @RequestMapping(value="/dictionaries")
- public class DictionariesController extends BaseController {
-
- String menuUrl = "dictionaries/list.do"; //菜单地址(权限用)
- @Resource(name="dictionariesService")
- private DictionariesManager dictionariesService;
-
- /**获取连级数据
- * @return
- */
- @RequestMapping(value="/getLevels")
- @ResponseBody
- public Object getLevels(){
- Map<String,Object> map = new HashMap<String,Object>();
- String errInfo = "success";
- PageData pd = new PageData();
- try{
- pd = this.getPageData();
- String DICTIONARIES_ID = pd.getString("DICTIONARIES_ID");
- DICTIONARIES_ID = Tools.isEmpty(DICTIONARIES_ID)?"0":DICTIONARIES_ID;
- List<Dictionaries> varList = dictionariesService.listSubDictByParentId(DICTIONARIES_ID); //用传过来的ID获取此ID下的子列表数据
- List<PageData> pdList = new ArrayList<PageData>();
- for(Dictionaries d :varList){
- PageData pdf = new PageData();
- pdf.put("DICTIONARIES_ID", d.getDICTIONARIES_ID());
- pdf.put("BIANMA", d.getBIANMA());
- pdf.put("NAME", d.getNAME());
- pdList.add(pdf);
- }
- map.put("list", pdList);
- } catch(Exception e){
- errInfo = "error";
- logger.error(e.toString(), e);
- }
- map.put("result", errInfo); //返回结果
- return AppUtil.returnObject(new PageData(), map);
- }
-
- /**保存
- * @param
- * @throws Exception
- */
- @RequestMapping(value="/save")
- public ModelAndView save() throws Exception{
- logBefore(logger, Jurisdiction.getUsername()+"新增Dictionaries");
- if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;} //校验权限
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- pd.put("DICTIONARIES_ID", this.get32UUID()); //主键
- dictionariesService.save(pd);
- mv.addObject("msg","success");
- mv.setViewName("save_result");
- return mv;
- }
-
- /**
- * 删除
- * @param DICTIONARIES_ID
- * @param
- * @throws Exception
- */
- @RequestMapping(value="/delete")
- @ResponseBody
- public Object delete(@RequestParam String DICTIONARIES_ID) throws Exception{
- if(!Jurisdiction.buttonJurisdiction(menuUrl, "del")){return null;} //校验权限
- logBefore(logger, Jurisdiction.getUsername()+"删除Dictionaries");
- Map<String,String> map = new HashMap<String,String>();
- PageData pd = new PageData();
- pd.put("DICTIONARIES_ID", DICTIONARIES_ID);
- String errInfo = "success";
- if(dictionariesService.listSubDictByParentId(DICTIONARIES_ID).size() > 0){//判断是否有子级,是:不允许删除
- errInfo = "false";
- }else{
- pd = dictionariesService.findById(pd); //根据ID读取
- if("yes".equals(pd.getString("YNDEL")))return null; //当禁止删除字段值为yes, 则禁止删除,只能从手动从数据库删除
- if(null != pd.get("TBSNAME") && !"".equals(pd.getString("TBSNAME"))){
- String TBFIELD = pd.getString("TBFIELD");
- if(Tools.isEmpty(TBFIELD))TBFIELD = "BIANMA"; //如果关联字段没有设置,就默认字段为 BIANMA
- pd.put("TBFIELD", TBFIELD);
- String[] table = pd.getString("TBSNAME").split(",");
- for(int i=0;i<table.length;i++){
- pd.put("thisTable", table[i]);
- try {
- if(Integer.parseInt(dictionariesService.findFromTbs(pd).get("zs").toString())>0){//判断是否被占用,是:不允许删除(去排查表检查字典表中的编码字段)
- errInfo = "false";
- break;
- }
- } catch (Exception e) {
- errInfo = "false2";
- break;
- }
- }
- }
- }
- if("success".equals(errInfo)){
- dictionariesService.delete(pd); //执行删除
- }
- map.put("result", errInfo);
- return AppUtil.returnObject(new PageData(), map);
- }
-
- /**修改
- * @param
- * @throws Exception
- */
- @RequestMapping(value="/edit")
- public ModelAndView edit() throws Exception{
- logBefore(logger, Jurisdiction.getUsername()+"修改Dictionaries");
- if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- dictionariesService.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()+"列表Dictionaries");
- 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());
- }
- String DICTIONARIES_ID = null == pd.get("DICTIONARIES_ID")?"":pd.get("DICTIONARIES_ID").toString();
- if(null != pd.get("id") && !"".equals(pd.get("id").toString())){
- DICTIONARIES_ID = pd.get("id").toString();
- }
- pd.put("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
- page.setPd(pd);
- List<PageData> varList = dictionariesService.list(page); //列出Dictionaries列表
- mv.addObject("pd", dictionariesService.findById(pd)); //传入上级所有信息
- mv.addObject("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
- mv.setViewName("system/dictionaries/dictionaries_list");
- mv.addObject("varList", varList);
- mv.addObject("QX",Jurisdiction.getHC()); //按钮权限
- return mv;
- }
-
- /**
- * 显示列表ztree
- * @param model
- * @return
- */
- @RequestMapping(value="/listAllDict")
- public ModelAndView listAllDict(Model model,String DICTIONARIES_ID)throws Exception{
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- try{
- JSONArray arr = JSONArray.fromObject(dictionariesService.listAllDict("0"));
- String json = arr.toString();
- json = json.replaceAll("DICTIONARIES_ID", "id").replaceAll("PARENT_ID", "pId").replaceAll("NAME", "name").replaceAll("subDict", "nodes").replaceAll("hasDict", "checked").replaceAll("treeurl", "url");
- model.addAttribute("zTreeNodes", json);
- mv.addObject("DICTIONARIES_ID",DICTIONARIES_ID);
- mv.addObject("pd", pd);
- mv.setViewName("system/dictionaries/dictionaries_ztree");
- } catch(Exception e){
- logger.error(e.toString(), e);
- }
- return mv;
- }
-
- /**
- * 显示列表ztree (用于代码生成器引用数据字典)
- * @param model
- * @return
- */
- @RequestMapping(value="/listAllDictToCreateCode")
- public ModelAndView listAllDictToCreateCode(Model model)throws Exception{
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- try{
- JSONArray arr = JSONArray.fromObject(dictionariesService.listAllDictToCreateCode("0"));
- String json = arr.toString();
- json = json.replaceAll("DICTIONARIES_ID", "id").replaceAll("PARENT_ID", "pId").replaceAll("NAME", "name").replaceAll("subDict", "nodes").replaceAll("hasDict", "checked").replaceAll("treeurl", "url");
- model.addAttribute("zTreeNodes", json);
- mv.addObject("pd", pd);
- mv.setViewName("system/dictionaries/dictionaries_ztree_windows");
- } catch(Exception e){
- logger.error(e.toString(), e);
- }
- return mv;
- }
-
- /**去新增页面
- * @param
- * @throws Exception
- */
- @RequestMapping(value="/goAdd")
- public ModelAndView goAdd()throws Exception{
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- String DICTIONARIES_ID = null == pd.get("DICTIONARIES_ID")?"":pd.get("DICTIONARIES_ID").toString();
- pd.put("DICTIONARIES_ID", DICTIONARIES_ID); //上级ID
- mv.addObject("pds",dictionariesService.findById(pd)); //传入上级所有信息
- mv.addObject("DICTIONARIES_ID", DICTIONARIES_ID); //传入ID,作为子级ID用
- mv.setViewName("system/dictionaries/dictionaries_edit");
- mv.addObject("msg", "save");
- return mv;
- }
-
- /**去修改页面
- * @param
- * @throws Exception
- */
- @RequestMapping(value="/goEdit")
- public ModelAndView goEdit()throws Exception{
- ModelAndView mv = this.getModelAndView();
- PageData pd = new PageData();
- pd = this.getPageData();
- String DICTIONARIES_ID = pd.getString("DICTIONARIES_ID");
- pd = dictionariesService.findById(pd); //根据ID读取
- mv.addObject("pd", pd); //放入视图容器
- pd.put("DICTIONARIES_ID",pd.get("PARENT_ID").toString()); //用作上级信息
- mv.addObject("pds",dictionariesService.findById(pd)); //传入上级所有信息
- mv.addObject("DICTIONARIES_ID", pd.get("PARENT_ID").toString()); //传入上级ID,作为子ID用
- pd.put("DICTIONARIES_ID",DICTIONARIES_ID); //复原本ID
- mv.setViewName("system/dictionaries/dictionaries_edit");
- mv.addObject("msg", "edit");
- return mv;
- }
- /**判断编码是否存在
- * @return
- */
- @RequestMapping(value="/hasBianma")
- @ResponseBody
- public Object hasBianma(){
- Map<String,String> map = new HashMap<String,String>();
- String errInfo = "success";
- PageData pd = new PageData();
- try{
- pd = this.getPageData();
- if(dictionariesService.findByBianma(pd) != null){
- errInfo = "error";
- }
- } catch(Exception e){
- logger.error(e.toString(), e);
- }
- map.put("result", errInfo); //返回结果
- return AppUtil.returnObject(new PageData(), map);
- }
-
- @InitBinder
- public void initBinder(WebDataBinder binder){
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
- }
- }
|