JeecgFormDemoController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. package com.jeecg.demo.controller;
  2. import java.io.IOException;
  3. import java.util.*;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import javax.xml.ws.Response;
  7. import net.sf.json.JSONArray;
  8. import org.apache.log4j.Logger;
  9. import org.jeecgframework.core.common.controller.BaseController;
  10. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  11. import org.jeecgframework.core.common.model.common.UploadFile;
  12. import org.jeecgframework.core.common.model.json.AjaxJson;
  13. import org.jeecgframework.core.common.model.json.ComboTree;
  14. import org.jeecgframework.core.common.model.json.DataGrid;
  15. import org.jeecgframework.core.common.model.json.TreeGrid;
  16. import org.jeecgframework.core.constant.Globals;
  17. import org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil;
  18. import org.jeecgframework.core.util.*;
  19. import org.jeecgframework.tag.core.easyui.TagUtil;
  20. import org.jeecgframework.tag.vo.datatable.SortDirection;
  21. import org.jeecgframework.tag.vo.easyui.ComboTreeModel;
  22. import org.jeecgframework.tag.vo.easyui.TreeGridModel;
  23. import org.jeecgframework.web.system.pojo.base.TSDepart;
  24. import org.jeecgframework.web.system.pojo.base.TSFunction;
  25. import org.jeecgframework.web.system.pojo.base.TSType;
  26. import org.jeecgframework.web.system.pojo.base.TSTypegroup;
  27. import org.jeecgframework.web.system.service.SystemService;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Controller;
  30. import org.springframework.ui.ModelMap;
  31. import org.springframework.web.bind.annotation.RequestMapping;
  32. import org.springframework.web.bind.annotation.RequestMethod;
  33. import org.springframework.web.bind.annotation.RequestParam;
  34. import org.springframework.web.bind.annotation.ResponseBody;
  35. import org.springframework.web.servlet.ModelAndView;
  36. import com.alibaba.fastjson.JSONObject;
  37. import com.jeecg.demo.dao.JeecgMinidaoDao;
  38. import com.jeecg.demo.entity.TSDocument;
  39. /**
  40. * @ClassName: JeecgFormDemoController
  41. * @Description: TODO(演示例子处理类)
  42. * @author jeecg
  43. */
  44. @Controller
  45. @RequestMapping("/jeecgFormDemoController")
  46. public class JeecgFormDemoController extends BaseController {
  47. private static final Logger logger = Logger.getLogger(JeecgFormDemoController.class);
  48. @Autowired
  49. private SystemService systemService;
  50. @Autowired
  51. private JeecgMinidaoDao jeecgMinidaoDao;
  52. @RequestMapping(params = "uitag")
  53. public ModelAndView uitag(HttpServletRequest request) {
  54. return new ModelAndView("com/jeecg/demo/form_uitag");
  55. }
  56. @RequestMapping(params = "formValidDemo")
  57. public ModelAndView formValidDemo(HttpServletRequest request) {
  58. return new ModelAndView("com/jeecg/demo/form_valid");
  59. }
  60. @RequestMapping(params = "testsubmit=1",method ={RequestMethod.GET, RequestMethod.POST})
  61. public ModelAndView testsubmit(HttpServletRequest request) {
  62. logger.info("请求成功byebye");
  63. return new ModelAndView("com/jeecg/demo/form_valid");
  64. }
  65. @RequestMapping(params = "nature")
  66. public ModelAndView easyDemo(HttpServletRequest request) {
  67. logger.info("demo-nature");
  68. //ztree同步加载
  69. JSONArray jsonArray=JSONArray.fromObject(getZtreeData());
  70. request.setAttribute("regions", jsonArray.toString().replaceAll("pid","pId"));
  71. return new ModelAndView("com/jeecg/demo/form_nature");
  72. }
  73. //update-begin--Author:dangzhenghui Date:20170408 for:TASK #1836 【demo】动态创建多tab demo,参考截图效果
  74. @RequestMapping(params = "ueditor")
  75. public ModelAndView ueditor(HttpServletRequest request) {
  76. logger.info("ueditor");
  77. return new ModelAndView("com/jeecg/demo/ueditor");
  78. }
  79. //update-end--Author:dangzhenghui Date:20170408 for:TASK #1836 【demo】动态创建多tab demo,参考截图效果
  80. /**
  81. *下拉联动数据---省市区
  82. */
  83. @RequestMapping(params="regionSelect",method = RequestMethod.GET)
  84. @ResponseBody
  85. public List<Map<String, String>> cityselect(HttpServletRequest req) throws Exception{
  86. logger.info("----省市区联动-----");
  87. String pid=req.getParameter("pid");
  88. List<Map<String, String>> list=jeecgMinidaoDao.getProCity(pid);
  89. return jeecgMinidaoDao.getProCity(pid);
  90. }
  91. /**
  92. * Ztree
  93. * 获取所有的省市区数据
  94. * @return
  95. */
  96. public List<Map<String, String>> getZtreeData(){
  97. return jeecgMinidaoDao.getAllRegions();
  98. }
  99. /**
  100. * 父级DEMO下拉菜单
  101. */
  102. @RequestMapping(params = "getComboTreeData")
  103. @ResponseBody
  104. public List<ComboTree> getComboTreeData(HttpServletRequest request, ComboTree comboTree) {
  105. CriteriaQuery cq = new CriteriaQuery(TSDepart.class);
  106. if (comboTree.getId() != null) {
  107. cq.eq("TSPDepart.id", comboTree.getId());
  108. }
  109. if (comboTree.getId() == null) {
  110. cq.isNull("TSPDepart");
  111. }
  112. cq.add();
  113. List<TSDepart> demoList = systemService.getListByCriteriaQuery(cq, false);
  114. List<ComboTree> comboTrees = new ArrayList<ComboTree>();
  115. ComboTreeModel comboTreeModel = new ComboTreeModel("id", "departname", "TSDeparts");
  116. comboTrees = systemService.ComboTree(demoList, comboTreeModel, null, false);
  117. return comboTrees;
  118. }
  119. /**
  120. * 加载ztree
  121. * @param response
  122. * @param request
  123. * @return
  124. */
  125. @RequestMapping(params="getTreeData",method ={RequestMethod.GET, RequestMethod.POST})
  126. @ResponseBody
  127. public AjaxJson getTreeData(TSDepart depatr,HttpServletResponse response,HttpServletRequest request ){
  128. AjaxJson j = new AjaxJson();
  129. try{
  130. List<TSDepart> depatrList = new ArrayList<TSDepart>();
  131. StringBuffer hql = new StringBuffer(" from TSDepart t");
  132. //hql.append(" and (parent.id is null or parent.id='')");
  133. depatrList = this.systemService.findHql(hql.toString());
  134. List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
  135. Map<String,Object> map = null;
  136. for (TSDepart tsdepart : depatrList) {
  137. String sqls = null;
  138. Object[] paramss = null;
  139. map = new HashMap<String,Object>();
  140. map.put("id", tsdepart.getId());
  141. map.put("name", tsdepart.getDepartname());
  142. if (tsdepart.getTSPDepart() != null) {
  143. map.put("pId", tsdepart.getTSPDepart().getId());
  144. map.put("open",false);
  145. }else {
  146. map.put("pId", "1");
  147. map.put("open",false);
  148. }
  149. sqls = "select count(1) from t_s_depart t where t.parentdepartid = ?";
  150. paramss = new Object[]{tsdepart.getId()};
  151. long counts = this.systemService.getCountForJdbcParam(sqls, paramss);
  152. if(counts>0){
  153. dataList.add(map);
  154. }else{
  155. TSDepart de = this.systemService.get(TSDepart.class, tsdepart.getId());
  156. if (de != null) {
  157. map.put("id", de.getId());
  158. map.put("name", de.getDepartname());
  159. if(tsdepart.getTSPDepart()!=null){
  160. map.put("pId", tsdepart.getTSPDepart().getId());
  161. map.put("open",false);
  162. }else{
  163. map.put("pId", "1");
  164. map.put("open",false);
  165. }
  166. dataList.add(map);
  167. }else{
  168. map.put("open",false);
  169. dataList.add(map);
  170. }
  171. }
  172. }
  173. j.setObj(dataList);
  174. }catch(Exception e){
  175. e.printStackTrace();
  176. }
  177. return j;
  178. }
  179. /**
  180. * 自动完成请求返回数据
  181. * @param request
  182. * @param responss
  183. */
  184. @RequestMapping(params = "getAutocompleteData",method ={RequestMethod.GET, RequestMethod.POST})
  185. public void getAutocompleteData(HttpServletRequest request, HttpServletResponse response) {
  186. String searchVal = request.getParameter("searchVal");
  187. String hql = "from TSUser where userName like '%"+searchVal+"%'";
  188. List autoList = systemService.findHql(hql);
  189. try {
  190. response.setContentType("application/json;charset=UTF-8");
  191. response.setHeader("Pragma", "No-cache");
  192. response.setHeader("Cache-Control", "no-cache");
  193. response.setDateHeader("Expires", 0);
  194. response.getWriter().write(JSONHelper.listtojson(new String[]{"userName"},1,autoList));
  195. response.getWriter().flush();
  196. } catch (Exception e1) {
  197. e1.printStackTrace();
  198. }finally{
  199. try {
  200. response.getWriter().close();
  201. } catch (IOException e) {
  202. }
  203. }
  204. }
  205. //update-begin--Author:dangzhenghui Date:20170429 for:TASK #1904 【demo】电子签章
  206. @RequestMapping(params = "eSign")
  207. public ModelAndView eSignDemo(HttpServletRequest request) {
  208. return new ModelAndView("com/jeecg/demo/zsign");
  209. }
  210. //update-end--Author:dangzhenghui Date:20170429 for:TASK #1904 【demo】电子签章
  211. //add-begin--Author:xuelin Date:20170503 for:#1903 【demo】左右布局demo--------------------
  212. @RequestMapping(params = "siteSelect")
  213. public ModelAndView siteSelect(HttpServletRequest request) {
  214. logger.info("----左右布局 demo转入页面-----");
  215. return new ModelAndView("com/jeecg/demo/siteSelect");
  216. }
  217. //add-end--Author:xuelin Date:20170503 for:#1903 【demo】左右布局demo----------------------
  218. //add-begin--Author:xuelin Date:20170506 for:TASK #1902 【demo】上下特殊布局--------------------
  219. /**
  220. * 上下特殊布局
  221. */
  222. @RequestMapping(params = "specialLayout")
  223. public ModelAndView rowListDemo(HttpServletRequest request) {
  224. logger.info("----上下特殊布局 demo转入页面-----");
  225. return new ModelAndView("com/jeecg/demo/specialLayout");
  226. }
  227. //add-end--Author:xuelin Date:20170506 for:TASK #1902 【demo】上下特殊布局----------------------
  228. //update--begin--author:zhangjiaqiang date:20170618 for:通用上传demo
  229. @RequestMapping(params = "commonUpload")
  230. public ModelAndView commonUploadDemo(){
  231. return new ModelAndView("system/commonupload/commonUploadFile");
  232. }
  233. /**
  234. *
  235. * @return
  236. */
  237. @RequestMapping(params = "saveUploadFile")
  238. @ResponseBody
  239. public AjaxJson saveUploadFile(String documentTitle,String filename){
  240. AjaxJson ajaxJson = new AjaxJson();
  241. try {
  242. TSTypegroup tsTypegroup=systemService.getTypeGroup("fieltype","文档分类");
  243. TSType tsType = systemService.getType("files","附件", tsTypegroup);
  244. TSDocument document = new TSDocument();
  245. document.setDocumentTitle(documentTitle);
  246. document.setRealpath(filename);
  247. document.setSubclassname(MyClassLoader.getPackPath(document));
  248. document.setCreatedate(DateUtils.gettimestamp());
  249. document.setTSType(tsType);
  250. //update--begin--author:zhangjiaqiang date:20170621 for:修订通用文件上传之后,下载和预览异常
  251. String fileName = filename.substring(filename.lastIndexOf("/")+1,filename.lastIndexOf("."));
  252. document.setAttachmenttitle(fileName);
  253. document.setExtend(filename.substring(filename.lastIndexOf(".") + 1));
  254. //update--end--author:zhangjiaqiang date:20170621 for:修订通用文件上传之后,下载和预览异常
  255. systemService.save(document);
  256. } catch (Exception e) {
  257. e.printStackTrace();
  258. ajaxJson.setSuccess(false);
  259. ajaxJson.setMsg("失败:"+e.getMessage());
  260. }
  261. return ajaxJson;
  262. }
  263. //update--end--author:zhangjiaqiang date:20170618 for:通用上传demo
  264. //update-begin--Author:dangzhenghui Date:20170524 for:TASK #1901 【demo】文档管理demo
  265. /**
  266. * 文件添加跳转
  267. *
  268. * @param req
  269. * @return
  270. */
  271. @RequestMapping(params = "addFiles")
  272. public ModelAndView addFiles(HttpServletRequest req) {
  273. return new ModelAndView("system/document/files");
  274. }
  275. /**
  276. * 文件编辑跳转
  277. *
  278. * @return
  279. */
  280. @RequestMapping(params = "editFiles")
  281. public ModelAndView editFiles(TSDocument doc, ModelMap map) {
  282. if (StringUtil.isNotEmpty(doc.getId())) {
  283. doc = systemService.getEntity(TSDocument.class, doc.getId());
  284. map.put("doc", doc);
  285. }
  286. return new ModelAndView("system/document/files");
  287. }
  288. /**
  289. * 保存文件
  290. *
  291. * @param document
  292. * @return
  293. * @throws Exception
  294. */
  295. @RequestMapping(params = "saveFiles", method = RequestMethod.POST)
  296. @ResponseBody
  297. public AjaxJson saveFiles(HttpServletRequest request, HttpServletResponse response, TSDocument document) {
  298. AjaxJson j = new AjaxJson();
  299. Map<String, Object> attributes = new HashMap<String, Object>();
  300. TSTypegroup tsTypegroup=systemService.getTypeGroup("fieltype","文档分类");
  301. TSType tsType = systemService.getType("files","附件", tsTypegroup);
  302. String fileKey = oConvertUtils.getString(request.getParameter("fileKey"));// 文件ID
  303. String documentTitle = oConvertUtils.getString(request.getParameter("documentTitle"));// 文件标题
  304. if (StringUtil.isNotEmpty(fileKey)) {
  305. document.setId(fileKey);
  306. document = systemService.getEntity(TSDocument.class, fileKey);
  307. document.setDocumentTitle(documentTitle);
  308. }
  309. document.setSubclassname(MyClassLoader.getPackPath(document));
  310. document.setCreatedate(DateUtils.gettimestamp());
  311. document.setTSType(tsType);
  312. UploadFile uploadFile = new UploadFile(request, document);
  313. uploadFile.setCusPath("files");
  314. //设置weboffice转化【不设置该字段,则不做在线预览转化】
  315. uploadFile.setSwfpath("swfpath");
  316. document = systemService.uploadFile(uploadFile);
  317. attributes.put("url", document.getRealpath());
  318. attributes.put("fileKey", document.getId());
  319. attributes.put("name", document.getAttachmenttitle());
  320. attributes.put("viewhref", "commonController.do?objfileList&fileKey=" + document.getId());
  321. attributes.put("delurl", "commonController.do?delObjFile&fileKey=" + document.getId());
  322. j.setMsg("文件添加成功");
  323. j.setAttributes(attributes);
  324. return j;
  325. }
  326. /**
  327. * 新闻法规文件列表
  328. */
  329. @RequestMapping(params = "documentList")
  330. public void documentList(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  331. CriteriaQuery cq = new CriteriaQuery(TSDocument.class, dataGrid);
  332. String typecode = oConvertUtils.getString(request.getParameter("typecode"));
  333. cq.createAlias("TSType", "TSType");
  334. cq.eq("TSType.typecode", typecode);
  335. cq.add();
  336. this.systemService.getDataGridReturn(cq, true);
  337. TagUtil.datagrid(response, dataGrid);
  338. }
  339. /**
  340. * 删除文档
  341. *
  342. * @param document
  343. * @return
  344. */
  345. @RequestMapping(params = "delDocument")
  346. @ResponseBody
  347. public AjaxJson delDocument(TSDocument document, HttpServletRequest request) {
  348. String message = null;
  349. AjaxJson j = new AjaxJson();
  350. document = systemService.getEntity(TSDocument.class, document.getId());
  351. message = "" + document.getDocumentTitle() + "被删除成功";
  352. systemService.delete(document);
  353. systemService.addLog(message, Globals.Log_Type_DEL,
  354. Globals.Log_Leavel_INFO);
  355. j.setSuccess(true);
  356. j.setMsg(message);
  357. return j;
  358. }
  359. //update-end--Author:dangzhenghui Date:20170524 for:TASK #1901 【demo】文档管理demo
  360. //update-begin--Author:dangzhenghui Date:20170531 for:TASK #2038 【demo】树形列表 分页demo
  361. /**
  362. * 权限列表
  363. */
  364. @RequestMapping(params = "functionGrid")
  365. @ResponseBody
  366. public Object functionGrid(HttpServletRequest request,TreeGrid treegrid, Integer type,HttpServletResponse response, DataGrid dataGrid) {
  367. CriteriaQuery cq = new CriteriaQuery(TSFunction.class,dataGrid);
  368. boolean pageflag=true;
  369. String selfId = request.getParameter("selfId");
  370. if (selfId != null) {
  371. cq.notEq("id", selfId);
  372. }
  373. if (treegrid.getId() != null) {
  374. pageflag=false;
  375. cq.eq("TSFunction.id", treegrid.getId());
  376. }
  377. if (treegrid.getId() == null) {
  378. cq.isNull("TSFunction");
  379. }
  380. if(type != null){
  381. cq.eq("functionType", type.shortValue());
  382. }
  383. cq.addOrder("functionOrder", SortDirection.asc);
  384. cq.add();
  385. //update--begin------author:scott--------------date:20151208-----------for:手工加载数据权限条件--------
  386. //获取装载数据权限的条件HQL
  387. cq = HqlGenerateUtil.getDataAuthorConditionHql(cq, new TSFunction());
  388. cq.add();
  389. //update--end------author:scott--------------date:20151208-----------for:手工加载数据权限条件--------
  390. List<TSFunction> functionList = systemService.getListByCriteriaQuery(cq, pageflag);
  391. Long total=systemService.getCountForJdbc("select count(*) from t_s_function where functionlevel=0");
  392. // update-start-Author:zhangguoming Date:20140914 for:菜单管理页面:菜单排序
  393. Collections.sort(functionList, new NumberComparator());
  394. // update-end-Author:zhangguoming Date:20140914 for:菜单管理页面:菜单排序
  395. List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
  396. TreeGridModel treeGridModel = new TreeGridModel();
  397. treeGridModel.setIcon("TSIcon_iconPath");
  398. treeGridModel.setTextField("functionName");
  399. treeGridModel.setParentText("TSFunction_functionName");
  400. treeGridModel.setParentId("TSFunction_id");
  401. treeGridModel.setSrc("functionUrl");
  402. treeGridModel.setIdField("id");
  403. treeGridModel.setChildList("TSFunctions");
  404. // 添加排序字段
  405. treeGridModel.setOrder("functionOrder");
  406. // update-begin--Author:chenj Date:20160722 for:添加菜单图标样式
  407. treeGridModel.setIconStyle("functionIconStyle");
  408. // update-end--Author:chenj Date:20160722 for:添加菜单图标样式
  409. treeGridModel.setFunctionType("functionType");
  410. treeGrids = systemService.treegrid(functionList, treeGridModel);
  411. MutiLangUtil.setMutiTree(treeGrids);
  412. JSONObject jsonObject=new JSONObject();
  413. jsonObject.put("rows",treeGrids);
  414. jsonObject.put("total",total);
  415. if (pageflag){
  416. return jsonObject;
  417. }
  418. return treeGrids;
  419. }
  420. /**
  421. * 权限列表页面跳转
  422. *
  423. * @return
  424. */
  425. @RequestMapping(params = "function")
  426. public ModelAndView function(ModelMap model) {
  427. return new ModelAndView("com/jeecg/demo/functionList");
  428. }
  429. //update-end--Author:dangzhenghui Date:20170531 for:TASK #2038 【demo】树形列表 分页demo
  430. }