| package com.matrix.system.common.actions; | 
|   | 
| import com.matrix.core.anotations.RemoveRequestToken; | 
| import com.matrix.core.anotations.SaveRequestToken; | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.PaginationVO; | 
| import com.matrix.core.tools.WebUtil; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.hive.action.BaseController; | 
| import com.matrix.system.common.bean.SystemDictionary; | 
| import com.matrix.system.hive.plugin.util.CollectionUtils; | 
| import com.matrix.system.common.service.SystemDictionaryService; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * @description 系统管理使用的数据字典 | 
|  * @author jyy | 
|  * @date 2016-07-12 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/dataDictionary") | 
| public class SystemDictionaryController extends BaseController { | 
|   | 
|   | 
|   | 
|     // 数据字典 | 
|     @Resource | 
|     private SystemDictionaryService currentService; | 
|   | 
|     @RequestMapping(value = "/showList") | 
|     public @ResponseBody | 
|     AjaxResult showList(HttpServletRequest request, SystemDictionary dictionary, | 
|                         PaginationVO pageVo) { | 
|   | 
|         SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         return showList(currentService, dictionary, pageVo); | 
|     } | 
|   | 
|     @RequestMapping(value = "/addOrModify") | 
|     @RemoveRequestToken | 
|     public @ResponseBody AjaxResult addOrModify(SystemDictionary dictionary) { | 
|         SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|   | 
|         if (dictionary.getId() != null) { | 
|             SystemDictionary dataDictionary = currentService.findById(dictionary.getId()); | 
|             if (dataDictionary.getType().equals(dictionary.getType()) && dataDictionary.getName().equals(dictionary.getName())) { | 
|                 return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改成功"); | 
|             } else { | 
|                 List<SystemDictionary> dataDictionaries = currentService.findByModel(dictionary); | 
|                 if (CollectionUtils.isNotEmpty(dataDictionaries)) { | 
|                     return AjaxResult.buildFailInstance("该类型为基础数据或已存在"); | 
|                 } | 
|             } | 
|             return modify(currentService, dictionary, "数据字典"); | 
|         } else { | 
|             List<SystemDictionary> dataDictionary = currentService.findByModel(dictionary); | 
|             if (CollectionUtils.isNotEmpty(dataDictionary)) { | 
|                 return AjaxResult.buildFailInstance("该类型为基础数据或已存在"); | 
|             } | 
|             dictionary.setShopId(sysUsers.getShopId()); | 
|             dictionary.setCompanyId(sysUsers.getCompanyId()); | 
|   | 
|             return add(currentService, dictionary, "数据字典"); | 
|         } | 
|     } | 
|   | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody AjaxResult del(String keys) { | 
|   | 
|         return remove(currentService, keys); | 
|     } | 
|   | 
|     @RequestMapping(value = "/editForm") | 
|     @SaveRequestToken | 
|     public String editForm(Long id, HttpServletRequest request) { | 
|         SystemDictionary dictionary; | 
|         List<String> list = currentService.getDictionaryType(); | 
|         request.setAttribute("dictionarys", list); | 
|         if (id != null) { | 
|             dictionary = currentService.findById(id); | 
|             request.setAttribute("obj", dictionary); | 
|         } | 
|         return "super/dataDictionary-form"; | 
|     } | 
|   | 
|     /** | 
|      * ======================================================= | 
|      * *******************公共的数据访问方法******************** | 
|      * ======================================================= | 
|      */ | 
|   | 
|     @RequestMapping(value = "/all") | 
|     public @ResponseBody AjaxResult all() { | 
|         return findByModel(currentService, null); | 
|     } | 
|   | 
|     /** | 
|      * 显示所有的会员信息前查询 | 
|      */ | 
|     @RequestMapping(value = "/showDataDictionary") | 
|     public @ResponseBody AjaxResult find(SystemDictionary dataDictionary) { | 
|         List<SystemDictionary> dataDictionarys = currentService.findByModel(dataDictionary); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataDictionarys, 0); | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/v2/showDataDictionary") | 
|     public @ResponseBody AjaxResult findAll(@RequestBody SystemDictionary dataDictionary) { | 
|   | 
|         List<SystemDictionary> dataDictionarys = currentService.findByModel(dataDictionary); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataDictionarys, 0); | 
|     } | 
|   | 
|   | 
|   | 
|     /** | 
|      * 查询数据字段类型 | 
|      * | 
|      * @author jyy | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getDictionaryType") | 
|     public @ResponseBody AjaxResult getDictionaryType() { | 
|         List<String> dics = currentService.getDictionaryType(); | 
|         List<SystemDictionary> dictionarys = new ArrayList<SystemDictionary>(); | 
|         SystemDictionary dataDictionary; | 
|         for (String dic : dics) { | 
|             dataDictionary = new SystemDictionary(); | 
|             dataDictionary.setType(dic); | 
|             dictionarys.add(dataDictionary); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS,  dictionarys, 0); | 
|     } | 
|   | 
| } |