SysMsgController.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. package cn.com.lzt.sysmsg.controller;
  2. import java.io.IOException;
  3. import java.net.URI;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.validation.ConstraintViolation;
  14. import javax.validation.Validator;
  15. import org.apache.commons.lang.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import org.jeecgframework.core.beanvalidator.BeanValidators;
  18. import org.jeecgframework.core.common.controller.BaseController;
  19. import org.jeecgframework.core.common.exception.BusinessException;
  20. import org.jeecgframework.core.common.model.json.AjaxJson;
  21. import org.jeecgframework.core.common.model.json.DataGrid;
  22. import org.jeecgframework.core.common.service.CommonService;
  23. import org.jeecgframework.core.constant.Globals;
  24. import org.jeecgframework.core.util.ExceptionUtil;
  25. import org.jeecgframework.core.util.JeecgDataAutorUtils;
  26. import org.jeecgframework.core.util.MyBeanUtils;
  27. import org.jeecgframework.core.util.ResourceUtil;
  28. import org.jeecgframework.core.util.StringUtil;
  29. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  30. import org.jeecgframework.poi.excel.ExcelImportUtil;
  31. import org.jeecgframework.poi.excel.entity.ExportParams;
  32. import org.jeecgframework.poi.excel.entity.ImportParams;
  33. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  34. import org.jeecgframework.tag.core.easyui.TagUtil;
  35. import org.jeecgframework.web.system.pojo.base.DictEntity;
  36. import org.jeecgframework.web.system.pojo.base.TSUser;
  37. import org.jeecgframework.web.system.service.SystemService;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.http.HttpHeaders;
  40. import org.springframework.http.HttpStatus;
  41. import org.springframework.http.MediaType;
  42. import org.springframework.http.ResponseEntity;
  43. import org.springframework.stereotype.Controller;
  44. import org.springframework.ui.ModelMap;
  45. import org.springframework.web.bind.annotation.PathVariable;
  46. import org.springframework.web.bind.annotation.RequestBody;
  47. import org.springframework.web.bind.annotation.RequestMapping;
  48. import org.springframework.web.bind.annotation.RequestMethod;
  49. import org.springframework.web.bind.annotation.ResponseBody;
  50. import org.springframework.web.bind.annotation.ResponseStatus;
  51. import org.springframework.web.multipart.MultipartFile;
  52. import org.springframework.web.multipart.MultipartHttpServletRequest;
  53. import org.springframework.web.servlet.ModelAndView;
  54. import org.springframework.web.util.UriComponentsBuilder;
  55. import cn.com.lzt.sysmsg.dto.SysMsgDto;
  56. import cn.com.lzt.sysmsg.entity.SysMsgEntity;
  57. import cn.com.lzt.sysmsg.service.SysMsgServiceI;
  58. import cn.com.lzt.sysmsgdetail.entity.SysMsgDetailEntity;
  59. import com.alibaba.fastjson.JSONObject;
  60. /**
  61. * @Title: Controller
  62. * @Description: 系统消息
  63. * @author onlineGenerator
  64. * @date 2017-11-29 19:56:16
  65. * @version V1.0
  66. *
  67. */
  68. @Controller
  69. @RequestMapping("/sysMsgController")
  70. public class SysMsgController extends BaseController {
  71. /**
  72. * Logger for this class
  73. */
  74. private static final Logger logger = Logger.getLogger(SysMsgController.class);
  75. @Autowired
  76. private SysMsgServiceI sysMsgService;
  77. @Autowired
  78. private SystemService systemService;
  79. @Autowired
  80. private Validator validator;
  81. //公共方法类
  82. @Autowired
  83. private CommonService commonService;
  84. /**
  85. * 系统消息列表 页面跳转
  86. *
  87. * @return
  88. */
  89. @RequestMapping(params = "list")
  90. public ModelAndView list(HttpServletRequest request) {
  91. return new ModelAndView("cn/com/lzt/sysmsg/sysMsgList");
  92. }
  93. /**
  94. * easyui AJAX请求数据
  95. *
  96. * @param request
  97. * @param response
  98. * @param dataGrid
  99. */
  100. @RequestMapping(params = "datagrid")
  101. public void datagrid(SysMsgDto sysMsgDto,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  102. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  103. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getSysMsgDtoPage(sysMsgDto, dataGrid.getPage(), dataGrid.getRows(),authSql);
  104. //获取数据字典中消息标题
  105. List<DictEntity> msgTitleList=systemService.queryDict(null, "process", null);
  106. Map<String, String> msgTitleMap=new HashMap<String, String>();
  107. for (int i = 0; i < msgTitleList.size(); i++) {
  108. msgTitleMap.put(msgTitleList.get(i).getTypecode(), msgTitleList.get(i).getTypename());
  109. }
  110. for (int i = 0; i < sysMsgDtoList.getResults().size(); i++) {
  111. if(msgTitleMap.containsKey(sysMsgDtoList.getResults().get(i).getMsgTitle())
  112. &&msgTitleMap.get(sysMsgDtoList.getResults().get(i).getMsgTitle()).length()!=0){
  113. sysMsgDtoList.getResults().get(i).setMsgTitle(msgTitleMap.get(sysMsgDtoList.getResults().get(i).getMsgTitle()));
  114. }
  115. }
  116. dataGrid.setTotal(sysMsgDtoList.getTotal());
  117. dataGrid.setResults(sysMsgDtoList.getResults());
  118. TagUtil.datagrid(response, dataGrid);
  119. /*CriteriaQuery cq = new CriteriaQuery(SysMsgEntity.class, dataGrid);
  120. //查询条件组装器
  121. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, sysMsg, request.getParameterMap());
  122. try{
  123. //自定义追加查询条件
  124. //排序
  125. Map<String, Object> map = new HashMap<String, Object>();
  126. map.put("sendStatus", "asc");
  127. cq.setOrder(map);
  128. }catch (Exception e) {
  129. throw new BusinessException(e.getMessage());
  130. }
  131. cq.add();
  132. this.sysMsgService.getDataGridReturn(cq, true);
  133. TagUtil.datagrid(response, dataGrid);*/
  134. }
  135. /**
  136. * 删除系统消息
  137. *
  138. * @return
  139. */
  140. @RequestMapping(params = "doDel")
  141. @ResponseBody
  142. public AjaxJson doDel(SysMsgEntity sysMsg, HttpServletRequest request) {
  143. String message = null;
  144. AjaxJson j = new AjaxJson();
  145. sysMsg = systemService.getEntity(SysMsgEntity.class, sysMsg.getId());
  146. message = "系统消息删除成功";
  147. try{
  148. sysMsgService.delete(sysMsg);
  149. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  150. }catch(Exception e){
  151. e.printStackTrace();
  152. message = "系统消息删除失败";
  153. throw new BusinessException(e.getMessage());
  154. }
  155. j.setMsg(message);
  156. return j;
  157. }
  158. /**
  159. * 批量删除系统消息
  160. *
  161. * @return
  162. */
  163. @RequestMapping(params = "doBatchDel")
  164. @ResponseBody
  165. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  166. String message = null;
  167. AjaxJson j = new AjaxJson();
  168. message = "系统消息删除成功";
  169. try{
  170. for(String id:ids.split(",")){
  171. SysMsgEntity sysMsg = systemService.getEntity(SysMsgEntity.class,
  172. id
  173. );
  174. sysMsgService.delete(sysMsg);
  175. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  176. }
  177. }catch(Exception e){
  178. e.printStackTrace();
  179. message = "系统消息删除失败";
  180. throw new BusinessException(e.getMessage());
  181. }
  182. j.setMsg(message);
  183. return j;
  184. }
  185. /**
  186. * 添加系统消息
  187. *
  188. * @return
  189. */
  190. @RequestMapping(params = "doAdd")
  191. @ResponseBody
  192. public AjaxJson doAdd(SysMsgEntity sysMsg, HttpServletRequest request) {
  193. String message = null;
  194. AjaxJson j = new AjaxJson();
  195. message = "系统消息添加成功";
  196. try{
  197. sysMsg.setSendStatus(Globals.send_status_0);
  198. sysMsgService.save(sysMsg);
  199. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  200. }catch(Exception e){
  201. e.printStackTrace();
  202. message = "系统消息添加失败";
  203. throw new BusinessException(e.getMessage());
  204. }
  205. j.setMsg(message);
  206. return j;
  207. }
  208. /**
  209. * 更新系统消息
  210. *
  211. * @return
  212. */
  213. @RequestMapping(params = "doUpdate")
  214. @ResponseBody
  215. public AjaxJson doUpdate(SysMsgEntity sysMsg, HttpServletRequest request) {
  216. String message = null;
  217. AjaxJson j = new AjaxJson();
  218. message = "系统消息更新成功";
  219. SysMsgEntity t = sysMsgService.get(SysMsgEntity.class, sysMsg.getId());
  220. try {
  221. MyBeanUtils.copyBeanNotNull2Bean(sysMsg, t);
  222. sysMsgService.saveOrUpdate(t);
  223. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  224. } catch (Exception e) {
  225. e.printStackTrace();
  226. message = "系统消息更新失败";
  227. throw new BusinessException(e.getMessage());
  228. }
  229. j.setMsg(message);
  230. return j;
  231. }
  232. /**
  233. * 系统消息新增页面跳转
  234. *
  235. * @return
  236. */
  237. @RequestMapping(params = "goAdd")
  238. public ModelAndView goAdd(SysMsgEntity sysMsg, HttpServletRequest req) {
  239. if (StringUtil.isNotEmpty(sysMsg.getId())) {
  240. sysMsg = sysMsgService.getEntity(SysMsgEntity.class, sysMsg.getId());
  241. req.setAttribute("sysMsgPage", sysMsg);
  242. }
  243. return new ModelAndView("cn/com/lzt/sysmsg/sysMsg-add");
  244. }
  245. /**
  246. * 系统消息编辑页面跳转
  247. *
  248. * @return
  249. */
  250. @RequestMapping(params = "goUpdate")
  251. public ModelAndView goUpdate(SysMsgEntity sysMsg, HttpServletRequest req) {
  252. if (StringUtil.isNotEmpty(sysMsg.getId())) {
  253. sysMsg = sysMsgService.getEntity(SysMsgEntity.class, sysMsg.getId());
  254. req.setAttribute("sysMsgPage", sysMsg);
  255. }
  256. return new ModelAndView("cn/com/lzt/sysmsg/sysMsg-update");
  257. }
  258. /**
  259. * 系统消息查看
  260. * @author zbw
  261. * 2017-12-25
  262. * @param sysMsg
  263. * @param req
  264. * @return
  265. */
  266. @RequestMapping(params = "sysMsgSee")
  267. public ModelAndView sysMsgSee(SysMsgEntity sysMsg, HttpServletRequest req) {
  268. if (StringUtil.isNotEmpty(sysMsg.getId())) {
  269. sysMsg = sysMsgService.getEntity(SysMsgEntity.class, sysMsg.getId());
  270. req.setAttribute("sysMsgPage", sysMsg);
  271. }
  272. return new ModelAndView("cn/com/lzt/sysmsg/sysMsg-see");
  273. }
  274. /**
  275. * 导入功能跳转
  276. *
  277. * @return
  278. */
  279. @RequestMapping(params = "upload")
  280. public ModelAndView upload(HttpServletRequest req) {
  281. req.setAttribute("controller_name","sysMsgController");
  282. return new ModelAndView("common/upload/pub_excel_upload");
  283. }
  284. /**
  285. * 导出excel
  286. *
  287. * @param request
  288. * @param response
  289. */
  290. @RequestMapping(params = "exportXls")
  291. public String exportXls(SysMsgDto sysMsgDto,HttpServletRequest request,HttpServletResponse response
  292. , DataGrid dataGrid,ModelMap modelMap) {
  293. String ids=request.getParameter("ids");
  294. if(ids!=null&&ids.length()!=0){
  295. sysMsgDto.getSysMsgIdList().addAll(extractIdListByComma(ids));
  296. }
  297. /*//获取发布状态
  298. List<DictEntity> sendStatusList=systemService.queryDict(null, "send_status", null);
  299. Map<String, String> sendStatusMap=new HashMap<String, String>();
  300. for (int i = 0; i < sendStatusList.size(); i++) {
  301. sendStatusMap.put(sendStatusList.get(i).getTypecode(), sendStatusList.get(i).getTypename());
  302. }
  303. //标题 该list中用于存储标题的信息,每一个ExcelExportEntity 表示一列,根据List 的入栈顺序,由左至右,一次排序
  304. List<ExcelExportEntity> entityList = new ArrayList<ExcelExportEntity>();
  305. ExcelExportEntity head1=new ExcelExportEntity("消息标题 ", "msgTitle", 15);
  306. entityList.add(head1);
  307. ExcelExportEntity head2=new ExcelExportEntity("消息内容 ", "msgContent", 15);
  308. entityList.add(head2);
  309. ExcelExportEntity head3=new ExcelExportEntity("发布时间 ", "sendTime", 15);
  310. entityList.add(head3);
  311. ExcelExportEntity head4=new ExcelExportEntity("发布状态", "sendStatus", 15);
  312. entityList.add(head4);
  313. //组建数据集
  314. List<Map<String,Object>> dataResult = new ArrayList<Map<String,Object>>();
  315. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  316. List<SysMsgDto> sysMsgDtoList=sysMsgService.getSysMsgDtoExport(sysMsgDto, authSql);
  317. for (int i = 0; i < sysMsgDtoList.size(); i++) {
  318. Map<String, Object> map = new HashMap<String, Object>();
  319. map.put("msgTitle", sysMsgDtoList.get(i).getMsgTitle());
  320. map.put("msgContent", sysMsgDtoList.get(i).getMsgContent());
  321. map.put("sendTime", sysMsgDtoList.get(i).getSendTime());
  322. map.put("sendStatus", sendStatusMap.get(sysMsgDtoList.get(i).getSendStatus()));
  323. dataResult.add(map);
  324. }
  325. modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
  326. modelMap.put(MapExcelConstants.MAP_LIST, dataResult);
  327. modelMap.put(NormalExcelConstants.FILE_NAME,"系统消息发布");
  328. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("系统消息发布", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  329. "导出信息"));
  330. return MapExcelConstants.JEECG_MAP_EXCEL_VIEW;*/
  331. /*CriteriaQuery cq = new CriteriaQuery(SysMsgEntity.class, dataGrid);
  332. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, sysMsg, request.getParameterMap());
  333. List<SysMsgEntity> sysMsgs = this.sysMsgService.getListByCriteriaQuery(cq,false);
  334. modelMap.put(NormalExcelConstants.FILE_NAME,"系统消息");
  335. modelMap.put(NormalExcelConstants.CLASS,SysMsgEntity.class);
  336. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("系统消息列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  337. "导出信息"));
  338. modelMap.put(NormalExcelConstants.DATA_LIST,sysMsgs);
  339. return NormalExcelConstants.JEECG_EXCEL_VIEW;*/
  340. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  341. List<SysMsgDto> sysMsgDtoList=sysMsgService.getSysMsgDtoExport(sysMsgDto, authSql);
  342. modelMap.put(NormalExcelConstants.FILE_NAME,"系统消息");
  343. modelMap.put(NormalExcelConstants.CLASS,SysMsgDto.class);
  344. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("系统消息列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  345. "导出信息"));
  346. modelMap.put(NormalExcelConstants.DATA_LIST,sysMsgDtoList);
  347. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  348. }
  349. /**
  350. * 导出excel 使模板
  351. *
  352. * @param request
  353. * @param response
  354. */
  355. @RequestMapping(params = "exportXlsByT")
  356. public String exportXlsByT(SysMsgEntity sysMsg,HttpServletRequest request,HttpServletResponse response
  357. , DataGrid dataGrid,ModelMap modelMap) {
  358. modelMap.put(NormalExcelConstants.FILE_NAME,"系统消息");
  359. modelMap.put(NormalExcelConstants.CLASS,SysMsgEntity.class);
  360. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("系统消息列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  361. "导出信息"));
  362. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  363. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  364. }
  365. @SuppressWarnings("unchecked")
  366. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  367. @ResponseBody
  368. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  369. AjaxJson j = new AjaxJson();
  370. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  371. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  372. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  373. MultipartFile file = entity.getValue();// 获取上传文件对象
  374. ImportParams params = new ImportParams();
  375. params.setTitleRows(2);
  376. params.setHeadRows(1);
  377. params.setNeedSave(true);
  378. try {
  379. List<SysMsgEntity> listSysMsgEntitys = ExcelImportUtil.importExcel(file.getInputStream(),SysMsgEntity.class,params);
  380. for (SysMsgEntity sysMsg : listSysMsgEntitys) {
  381. sysMsgService.save(sysMsg);
  382. }
  383. j.setMsg("文件导入成功!");
  384. } catch (Exception e) {
  385. j.setMsg("文件导入失败!");
  386. logger.error(ExceptionUtil.getExceptionMessage(e));
  387. }finally{
  388. try {
  389. file.getInputStream().close();
  390. } catch (IOException e) {
  391. e.printStackTrace();
  392. }
  393. }
  394. }
  395. return j;
  396. }
  397. @RequestMapping(method = RequestMethod.GET)
  398. @ResponseBody
  399. public List<SysMsgEntity> list() {
  400. List<SysMsgEntity> listSysMsgs=sysMsgService.getList(SysMsgEntity.class);
  401. return listSysMsgs;
  402. }
  403. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  404. @ResponseBody
  405. public ResponseEntity<?> get(@PathVariable("id") String id) {
  406. SysMsgEntity task = sysMsgService.get(SysMsgEntity.class, id);
  407. if (task == null) {
  408. return new ResponseEntity(HttpStatus.NOT_FOUND);
  409. }
  410. return new ResponseEntity(task, HttpStatus.OK);
  411. }
  412. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  413. @ResponseBody
  414. public ResponseEntity<?> create(@RequestBody SysMsgEntity sysMsg, UriComponentsBuilder uriBuilder) {
  415. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  416. Set<ConstraintViolation<SysMsgEntity>> failures = validator.validate(sysMsg);
  417. if (!failures.isEmpty()) {
  418. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  419. }
  420. //保存
  421. try{
  422. sysMsgService.save(sysMsg);
  423. } catch (Exception e) {
  424. e.printStackTrace();
  425. return new ResponseEntity(HttpStatus.NO_CONTENT);
  426. }
  427. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  428. String id = sysMsg.getId();
  429. URI uri = uriBuilder.path("/rest/sysMsgController/" + id).build().toUri();
  430. HttpHeaders headers = new HttpHeaders();
  431. headers.setLocation(uri);
  432. return new ResponseEntity(headers, HttpStatus.CREATED);
  433. }
  434. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  435. public ResponseEntity<?> update(@RequestBody SysMsgEntity sysMsg) {
  436. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  437. Set<ConstraintViolation<SysMsgEntity>> failures = validator.validate(sysMsg);
  438. if (!failures.isEmpty()) {
  439. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  440. }
  441. //保存
  442. try{
  443. sysMsgService.saveOrUpdate(sysMsg);
  444. } catch (Exception e) {
  445. e.printStackTrace();
  446. return new ResponseEntity(HttpStatus.NO_CONTENT);
  447. }
  448. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  449. return new ResponseEntity(HttpStatus.NO_CONTENT);
  450. }
  451. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  452. @ResponseStatus(HttpStatus.NO_CONTENT)
  453. public void delete(@PathVariable("id") String id) {
  454. sysMsgService.deleteEntityById(SysMsgEntity.class, id);
  455. }
  456. /**
  457. * 我的消息主页数据查看
  458. * 系统消息列表 页面跳转
  459. *
  460. *
  461. * @return
  462. */
  463. @RequestMapping(params = "myMsgList")
  464. public ModelAndView myMsgList(HttpServletRequest request) {
  465. return new ModelAndView("cn/com/lzt/sysmsg/mymsg/myMsgList");
  466. }
  467. /**
  468. * 获取我的消息未读消息个数
  469. * easyui AJAX请求数据
  470. * @author 刘梦祥
  471. * @date 2022年8月2日14:32:39
  472. */
  473. @RequestMapping(params = "getMyMsgCount")
  474. @ResponseBody
  475. public Object getMyMsgCount() {
  476. TSUser tSUser = ResourceUtil.getSessionUser();
  477. if(tSUser != null){
  478. SysMsgDto sysMsgDto = new SysMsgDto();
  479. sysMsgDto.setReceivedId(tSUser.getId());
  480. sysMsgDto.setReadStatus("0");
  481. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  482. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, 1, 999,authSql);
  483. return sysMsgDtoList.getTotal();
  484. }else{
  485. return 0;
  486. }
  487. }
  488. /**
  489. * 我的消息主页数据查看
  490. * easyui AJAX请求数据
  491. *
  492. * @param request
  493. * @param response
  494. * @param dataGrid
  495. */
  496. @RequestMapping(params = "myMsgDatagrid")
  497. public void myMsgDatagrid(SysMsgDto sysMsgDto,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  498. /*//获取数据字典中的消息标题
  499. List<DictEntity> msgTitleCodeProcessList=systemService.queryDict(null, "process", null);
  500. Map<String, String> msgTitleCodeProcessMap=new HashMap<String, String>();
  501. Map<String, String> msgTitleProcessCodeMap=new HashMap<String, String>();
  502. for (int i = 0; i < msgTitleCodeProcessList.size(); i++) {
  503. msgTitleCodeProcessMap.put(msgTitleCodeProcessList.get(i).getTypename(),msgTitleCodeProcessList.get(i).getTypecode());
  504. msgTitleProcessCodeMap.put(msgTitleCodeProcessList.get(i).getTypecode(), msgTitleCodeProcessList.get(i).getTypename());
  505. }
  506. if(sysMsgDto.getMsgTitle()!=null&&sysMsgDto.getMsgTitle().length()!=0){
  507. if(msgTitleCodeProcessMap.containsKey(sysMsgDto.getMsgTitle())){
  508. sysMsgDto.setMsgTitle(msgTitleCodeProcessMap.get(sysMsgDto.getMsgTitle()));
  509. }
  510. }*/
  511. TSUser tSUser = ResourceUtil.getSessionUser();
  512. sysMsgDto.setReceivedId(tSUser.getId());
  513. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  514. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, dataGrid.getPage(), dataGrid.getRows(),authSql);
  515. dataGrid.setTotal(sysMsgDtoList.getTotal());
  516. dataGrid.setResults(sysMsgDtoList.getResults());
  517. TagUtil.datagrid(response, dataGrid);
  518. /*CriteriaQuery cq = new CriteriaQuery(SysMsgEntity.class, dataGrid);
  519. //查询条件组装器
  520. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, sysMsg, request.getParameterMap());
  521. try{
  522. //自定义追加查询条件
  523. }catch (Exception e) {
  524. throw new BusinessException(e.getMessage());
  525. }
  526. cq.add();
  527. this.sysMsgService.getDataGridReturn(cq, true);
  528. TagUtil.datagrid(response, dataGrid);*/
  529. }
  530. /**
  531. * 我的消息主页数据查看
  532. * easyui AJAX请求数据
  533. */
  534. @RequestMapping(params = "myMsgDatagridToWX")
  535. @ResponseBody
  536. public AjaxJson myMsgDatagridToWX(SysMsgDto sysMsgDto,Integer pageSize,Integer rowsSize) {
  537. AjaxJson j = new AjaxJson();
  538. if(StringUtils.isNotEmpty(sysMsgDto.getReceivedId())){
  539. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, pageSize == null ? 1 : pageSize, rowsSize == null ? 100 : rowsSize,"");
  540. List<SysMsgDto> sysMsgDtos = sysMsgDtoList.getResults();
  541. Map<String,Object> attr = new HashMap<>();
  542. attr.put("pageSize",pageSize == null ? 1 : pageSize);
  543. attr.put("rowsSize",rowsSize == null ? 100 : rowsSize);
  544. attr.put("totalCount",sysMsgDtoList.getTotal());
  545. j.setAttributes(attr);
  546. j.setMsg("请求成功!");
  547. j.setObj(sysMsgDtos);
  548. }else{
  549. j.setMsg("请传入用户id!");
  550. j.setSuccess(false);
  551. }
  552. return j;
  553. }
  554. /**
  555. * 一键已读
  556. * @author 刘梦祥
  557. * @date 2022年8月24日17:00:44
  558. * @return
  559. */
  560. @RequestMapping(params = "doReadToWX")
  561. @ResponseBody
  562. public AjaxJson doReadToWX(String id) {
  563. AjaxJson j = new AjaxJson();
  564. if(StringUtils.isNotEmpty(id)){
  565. String updateMsgReadStatus = "update t_bus_sys_msg_detail set read_status = '1',read_time = NOW() where msg_id = '"+id+"' ";
  566. Integer sqlStatus = systemService.executeSql(updateMsgReadStatus);
  567. j.setMsg(sqlStatus != null && sqlStatus != 0 ? "操作成功!" : "操作失败!");
  568. j.setSuccess(sqlStatus != null && sqlStatus != 0);
  569. }else{
  570. j.setSuccess(false);
  571. j.setMsg("操作失败!请检查消息id!");
  572. }
  573. return j;
  574. }
  575. /**
  576. * 一键全读
  577. * @author 刘梦祥
  578. * @date 2022年8月24日17:00:44
  579. * @return
  580. */
  581. @RequestMapping(params = "readAllMsgToWX")
  582. @ResponseBody
  583. public AjaxJson readAllMsgToWX(String receivedId) {
  584. AjaxJson j = new AjaxJson();
  585. if(StringUtils.isNotEmpty(receivedId)){
  586. SysMsgDto sysMsgDto = new SysMsgDto();
  587. sysMsgDto.setReceivedId(receivedId);
  588. sysMsgDto.setReadStatus("0");
  589. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  590. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, 1, 99999999,authSql);
  591. List<SysMsgDto> sysMsgDtos = sysMsgDtoList.getResults();
  592. if(sysMsgDtos != null && sysMsgDtos.size() > 0){
  593. StringBuffer msgIds = new StringBuffer();
  594. for (SysMsgDto sysMsgDto1 : sysMsgDtos){
  595. msgIds.append("'");
  596. msgIds.append(sysMsgDto1.getId());
  597. msgIds.append("'");
  598. msgIds.append(",");
  599. }
  600. String queryMsgIds = "";
  601. if (msgIds.length() > 0){
  602. queryMsgIds = msgIds.substring(0,msgIds.length() -1).toString();
  603. }
  604. String updateMsgReadStatus = "update t_bus_sys_msg_detail set read_status = '1',read_time = NOW() where msg_id in ("+queryMsgIds+")";
  605. Integer sqlStatus = systemService.executeSql(updateMsgReadStatus);
  606. j.setSuccess(sqlStatus != null && sqlStatus != 0);
  607. j.setMsg(sqlStatus != null && sqlStatus != 0 ? "操作成功!" : "操作失败!");
  608. }
  609. }else{
  610. j.setSuccess(false);
  611. j.setMsg("操作失败!请检查用户id!");
  612. }
  613. return j;
  614. }
  615. /**
  616. * 首页消息通知看板数据
  617. * 只查看最新的10条
  618. * easyui AJAX请求数据
  619. *
  620. * @param request
  621. * @param response
  622. * @param dataGrid
  623. */
  624. @RequestMapping(params = "homePageMyMsg")
  625. @ResponseBody
  626. public String homePageMyMsg(SysMsgDto sysMsgDto,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  627. // AjaxJson j = new AjaxJson();
  628. TSUser tSUser=ResourceUtil.getSessionUser();
  629. sysMsgDto.setReceivedId(tSUser.getId());
  630. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  631. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, 1, 10,authSql);
  632. // Map<String, Object> m=new HashMap<String, Object>();
  633. // SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM-dd");
  634. /*String str="[";
  635. for (int i = 0; i < sysMsgDtoList.getResults().size(); i++) {
  636. String sendTime=simpleDateFormat.format(sysMsgDtoList.getResults().get(i).getSendTime());
  637. String createDate=simpleDateFormat.format(sysMsgDtoList.getResults().get(i).getCreateDate());
  638. JSONObject jsonObject = JSONObject.fromObject(sysMsgDtoList.getResults().get(i));
  639. Map<String, Object> map=jsonObject;
  640. jsonObject.put("sendTime", sendTime);
  641. jsonObject.put("createDate", createDate);
  642. if(str.length()!=1){
  643. str+=",{";
  644. }else{
  645. str+="{";
  646. }
  647. for (Map.Entry<String, Object> m : map.entrySet()) {
  648. if(!str.substring(str.length()-1, str.length()).equals("{")){
  649. if(m.getValue().toString().length()>70){
  650. str+=",'"+m.getKey()+"':'"+m.getValue().toString().subSequence(0, 70)+"...'";
  651. }else{
  652. str+=",'"+m.getKey()+"':'"+m.getValue()+"'";
  653. }
  654. }else{
  655. if(m.getValue().toString().length()>70){
  656. str+="'"+m.getKey()+"':'"+m.getValue().toString().subSequence(0, 70)+"...'";
  657. }else{
  658. str+="'"+m.getKey()+"':'"+m.getValue()+"'";
  659. }
  660. }
  661. }
  662. str+="}";
  663. // m.put(String.valueOf(i), jsonObject.toString());
  664. }
  665. str+="]";*/
  666. String str =JSONObject.toJSONString(sysMsgDtoList);
  667. // j.setAttributes(m);
  668. return str;
  669. }
  670. /**
  671. * 首页消息通知看板数据
  672. * 只查看最新的10条
  673. * easyui AJAX请求数据
  674. *
  675. * @param request
  676. * @param response
  677. * @param dataGrid
  678. * @param user
  679. */
  680. /*@RequestMapping(params = "testGet")
  681. @ResponseBody
  682. public String testGet(HttpServletRequest request, HttpServletResponse response) {
  683. System.out.println("qqqqqqqqqqqqqqq");
  684. System.out.println("qqqqqqqqqqqqqqq");
  685. System.out.println("qqqqqqqqqqqqqqq");
  686. System.out.println("qqqqqqqqqqqqqqq");
  687. System.out.println("qqqqqqqqqqqqqqq");
  688. System.out.println("qqqqqqqqqqqqqqq");
  689. return "qqqqqqqqqqqqqqqqq";
  690. }*/
  691. /**
  692. * 菜单我的消息查看页面跳转
  693. *
  694. * @return
  695. */
  696. @RequestMapping(params = "myMsgSee")
  697. public ModelAndView myMsgSee(SysMsgEntity sysMsg, HttpServletRequest req) {
  698. if (StringUtil.isNotEmpty(sysMsg.getId())) {
  699. sysMsg = sysMsgService.getEntity(SysMsgEntity.class, sysMsg.getId());
  700. req.setAttribute("sysMsgPage", sysMsg);
  701. }
  702. StringBuffer hql = new StringBuffer(" FROM SysMsgDetailEntity where msgId=?");
  703. List<SysMsgDetailEntity> sysMsgDetailEntityList = commonService.findHql(hql.toString(),sysMsg.getId());
  704. if(sysMsgDetailEntityList.size()>0){
  705. sysMsgDetailEntityList.get(0).setReadStatus(Globals.read_status_1);
  706. sysMsgDetailEntityList.get(0).setReadTime(new Date());
  707. systemService.saveOrUpdate(sysMsgDetailEntityList.get(0));
  708. }
  709. return new ModelAndView("cn/com/lzt/sysmsg/mymsg/myMsg-see");
  710. }
  711. /**
  712. * 一键全读
  713. * @author 刘梦祥
  714. * @date 2022年8月24日17:00:44
  715. * @return
  716. */
  717. @RequestMapping(params = "readAllMsg")
  718. @ResponseBody
  719. public AjaxJson readAllMsg() {
  720. AjaxJson j = new AjaxJson();
  721. SysMsgDto sysMsgDto = new SysMsgDto();
  722. TSUser tSUser = ResourceUtil.getSessionUser();
  723. sysMsgDto.setReceivedId(tSUser.getId());
  724. sysMsgDto.setReadStatus("0");
  725. String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  726. MiniDaoPage<SysMsgDto> sysMsgDtoList = sysMsgService.getMyMsgDtoPage(sysMsgDto, 1, 99999999,authSql);
  727. List<SysMsgDto> sysMsgDtos = sysMsgDtoList.getResults();
  728. if(sysMsgDtos != null && sysMsgDtos.size() > 0){
  729. StringBuffer msgIds = new StringBuffer();
  730. for (SysMsgDto sysMsgDto1 : sysMsgDtos){
  731. msgIds.append("'");
  732. msgIds.append(sysMsgDto1.getId());
  733. msgIds.append("'");
  734. msgIds.append(",");
  735. }
  736. String queryMsgIds = "";
  737. if (msgIds.length() > 0){
  738. queryMsgIds = msgIds.substring(0,msgIds.length() -1).toString();
  739. }
  740. String updateMsgReadStatus = "update t_bus_sys_msg_detail set read_status = '1',read_time = NOW() where msg_id in ("+queryMsgIds+")";
  741. Integer sqlStatus = systemService.executeSql(updateMsgReadStatus);
  742. j.setMsg(sqlStatus != null && sqlStatus != 0 ? "操作成功!" : "操作失败!");
  743. }
  744. return j;
  745. }
  746. /**
  747. * 一键已读
  748. * @author 刘梦祥
  749. * @date 2022年8月24日17:00:44
  750. * @return
  751. */
  752. @RequestMapping(params = "doRead")
  753. @ResponseBody
  754. public AjaxJson doRead(String id) {
  755. AjaxJson j = new AjaxJson();
  756. StringBuffer hql = new StringBuffer(" FROM SysMsgDetailEntity where msgId=?");
  757. List<SysMsgDetailEntity> sysMsgDetailEntityList = commonService.findHql(hql.toString(),id);
  758. if(sysMsgDetailEntityList.size()>0){
  759. sysMsgDetailEntityList.get(0).setReadStatus(Globals.read_status_1);
  760. sysMsgDetailEntityList.get(0).setReadTime(new Date());
  761. systemService.saveOrUpdate(sysMsgDetailEntityList.get(0));
  762. }
  763. j.setMsg("操作成功!");
  764. return j;
  765. }
  766. /**
  767. * 首页我的消息查看页面跳转
  768. * @author zbw
  769. * 2018-1-8
  770. * @param sysMsg
  771. * @param req
  772. * @return
  773. */
  774. @RequestMapping(params = "myMsgHomePageSee")
  775. public ModelAndView myMsgHomePageSee(SysMsgEntity sysMsg, HttpServletRequest req) {
  776. if (StringUtil.isNotEmpty(sysMsg.getId())) {
  777. sysMsg = sysMsgService.getEntity(SysMsgEntity.class, sysMsg.getId());
  778. req.setAttribute("sysMsgPage", sysMsg);
  779. }
  780. TSUser tSUser=ResourceUtil.getSessionUser();
  781. String receivedId=tSUser.getId();
  782. StringBuffer hql = new StringBuffer(" FROM SysMsgDetailEntity where msgId=? and receivedId=? ");
  783. List<SysMsgDetailEntity> sysMsgDetailEntityList = commonService.findHql(hql.toString(),sysMsg.getId(),receivedId);
  784. if(sysMsgDetailEntityList.size()>0){
  785. sysMsgDetailEntityList.get(0).setReadStatus(Globals.read_status_1);
  786. sysMsgDetailEntityList.get(0).setReadTime(new Date());
  787. systemService.saveOrUpdate(sysMsgDetailEntityList.get(0));
  788. }
  789. return new ModelAndView("cn/com/lzt/sysmsg/mymsg/myMsgHomePage-see");
  790. }
  791. /**
  792. * 系统消息保存总方法
  793. * @author zbw
  794. * 2017-11-30
  795. * @param sysMsg
  796. * @param request
  797. * @return
  798. */
  799. @RequestMapping(params = "saveSysMsgAndSysMsgDetail")
  800. @ResponseBody
  801. public AjaxJson saveSysMsgAndSysMsgDetail(SysMsgEntity sysMsg, HttpServletRequest request){
  802. AjaxJson j = new AjaxJson();
  803. try {
  804. j=sysMsgService.saveSysMsg(sysMsg);
  805. } catch (Exception e) {
  806. // TODO Auto-generated catch block
  807. e.printStackTrace();
  808. }
  809. return j;
  810. }
  811. /**
  812. * 系统消息发布总方法
  813. * @author zbw
  814. * 2017-11-30
  815. * @param request
  816. * @return
  817. */
  818. @RequestMapping(params = "publishMsg")
  819. @ResponseBody
  820. public AjaxJson publishMsg(String ids,HttpServletRequest request){
  821. AjaxJson j = new AjaxJson();
  822. try {
  823. j=sysMsgService.doBatchPublishSysMsg(ids);
  824. } catch (Exception e) {
  825. // TODO Auto-generated catch block
  826. e.printStackTrace();
  827. }
  828. return j;
  829. }
  830. /**
  831. * 系统消息删除总方法
  832. * @author zbw
  833. * 2017-11-30
  834. * @param request
  835. * @return
  836. */
  837. @RequestMapping(params = "deleteSysMsgAndSysMsgDetail")
  838. @ResponseBody
  839. public AjaxJson deleteSysMsgAndSysMsgDetail(String ids,HttpServletRequest request){
  840. AjaxJson j = new AjaxJson();
  841. try {
  842. j=sysMsgService.doBatchDelSysMsg(ids);
  843. } catch (Exception e) {
  844. // TODO Auto-generated catch block
  845. e.printStackTrace();
  846. }
  847. return j;
  848. }
  849. }