GqCtl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. package com.xt.jygl.gkjcxx.gq.ctl;
  2. import java.text.SimpleDateFormat;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.persistence.criteria.CriteriaBuilder;
  8. import javax.persistence.criteria.CriteriaQuery;
  9. import javax.persistence.criteria.Predicate;
  10. import javax.persistence.criteria.Root;
  11. import javax.persistence.criteria.CriteriaBuilder.In;
  12. import javax.servlet.http.HttpServletRequest;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.data.domain.Page;
  16. import org.springframework.data.jpa.domain.Specification;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.ui.Model;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import cache.CacheSearchCondition;
  22. import com.fasterxml.jackson.core.JsonProcessingException;
  23. import com.xt.jygl.common.BaseWebCtl;
  24. import com.xt.jygl.common.Constants;
  25. import com.xt.jygl.common.GlobalData;
  26. import com.xt.jygl.common.Utils;
  27. import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
  28. import com.xt.jygl.gkjcxx.gk.service.GkService;
  29. import com.xt.jygl.gkjcxx.gq.client.GqWebService;
  30. import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
  31. import com.xt.jygl.gkjcxx.gq.service.GqService;
  32. import com.xt.jygl.gkjcxx.gq.vo.GqVo;
  33. import com.xt.jygl.gkjcxx.xzdwxxgl.xzglbmxx.entity.XzglbmxxEntity;
  34. import com.xt.jygl.gkjcxx.xzdwxxgl.xzglbmxx.service.XzglbmxxService;
  35. import com.xtframe.core.anon.auth.RequiresPermissions;
  36. import com.xtframe.core.base.ctl.WebJsonResult;
  37. import com.xtframe.core.support.SecurityMgr;
  38. import com.xtframe.sec.code.entity.CodeEntity;
  39. import com.xtframe.sec.common.BaseEntity;
  40. import com.xtframe.sec.common.QueryService;
  41. import com.xtframe.sec.common.SimplePageRequest;
  42. import com.xtframe.sec.utils.SecUtils;
  43. import com.xtframe.util.StringUtils;
  44. /**
  45. * 港区管理Controller
  46. *
  47. * @author zhaohang
  48. *
  49. */
  50. @Controller
  51. @RequestMapping("/gq")
  52. public class GqCtl extends BaseWebCtl {
  53. @Autowired
  54. private SecurityMgr securityMgr;
  55. @Autowired
  56. private QueryService query;
  57. @Autowired
  58. private GqService gqService;
  59. @Autowired
  60. private GkService gkService;
  61. @Autowired
  62. private XzglbmxxService xzglbmService;
  63. /**
  64. * 显示港区
  65. */
  66. @RequestMapping(value = "/main")
  67. @RequiresPermissions("gqgl:main")
  68. public String main(SimplePageRequest page, Model model, final HttpServletRequest request, final String szgkid, final String szd, final String ssgkglbm, final String gqmc, final String gqszsylx, String menuid) throws JsonProcessingException {
  69. final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request, "gqgl");
  70. // 查询条件
  71. Specification<GqEntity> spec = new Specification<GqEntity>() {
  72. @Override
  73. public Predicate toPredicate(Root<GqEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  74. List<Predicate> list = new ArrayList<Predicate>();
  75. if (StringUtils.isNotEmpty(gqmc)) {
  76. list.add(cb.like(root.get("gqmc").as(String.class), "%" + gqmc + "%"));
  77. } else if (isGET(request)) {
  78. // list.add(cb.like(root.get("gqmc").as(String.class), "%" +
  79. // SearchCondition.gqmc + "%"));
  80. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, null, "gqmc");
  81. }
  82. if (StringUtils.isNotEmpty(gqszsylx)) {
  83. list.add(cb.like(root.get("gqszsylx").get("id").as(String.class), "%" + gqszsylx + "%"));
  84. } else if (isGET(request)) {
  85. // list.add(cb.like(root.get("gqszsylx").get("id").as(String.class),
  86. // "%" + SearchCondition.gqszsylx + "%"));
  87. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "gqszsylx");
  88. }
  89. if (StringUtils.isNotEmpty(szgkid)) {
  90. list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
  91. } else if (isGET(request)) {
  92. // list.add(cb.like(root.get("szgk").get("id").as(String.class),
  93. // "%" + SearchCondition.gqszgk + "%"));
  94. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "szgk", "szgkid");
  95. }
  96. if (StringUtils.isNotEmpty(szd)) {
  97. list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szd + "%"));
  98. } else if (isGET(request)) {
  99. // list.add(cb.like(root.get("szd").get("id").as(String.class),
  100. // "%" + SearchCondition.gqszd + "%"));
  101. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "szd");
  102. }
  103. if (StringUtils.isNotEmpty(ssgkglbm)) {
  104. list.add(cb.like(root.get("ssgkglbm").get("id").as(String.class), "%" + ssgkglbm + "%"));
  105. } else if (isGET(request)) {
  106. // list.add(cb.like(root.get("ssgkglbm").get("id").as(String.class),
  107. // "%" + SearchCondition.gqssgkglbm + "%"));
  108. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "ssgkglbm");
  109. }
  110. if (isJyr()) {
  111. //list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
  112. } else {
  113. In<String> in = cb.in(root.get("id").as(String.class));
  114. @SuppressWarnings("unchecked")
  115. List<String> gqlist = (List<String>) Utils.getSession().getAttribute("gqList");
  116. if (gqlist != null && gqlist.size() > 0) {
  117. for (int i = 0; i < gqlist.size(); i++) {
  118. in.value(gqlist.get(i));
  119. }
  120. list.add(in);
  121. }
  122. }
  123. list.add(cb.notEqual(root.get("recordStatus").as(String.class), BaseEntity.RECORD_STATE_DELETE));
  124. return cb.and(list.toArray(new Predicate[] {}));
  125. }
  126. };
  127. /*
  128. * String user1 = (String) Utils.getSession().getAttribute("user");
  129. * String user2 = SecUtils.getCurrUser().getId(); if(user2!=null){
  130. * if(!user2.equals(user1)){ SearchCondition.gqpage = 1;
  131. * SearchCondition.gqmc = ""; SearchCondition.gqszd = "";
  132. * SearchCondition.gqssgkglbm = ""; SearchCondition.gqszgk = "";
  133. * SearchCondition.gqszsylx = ""; }
  134. *
  135. * } Utils.getSession().setAttribute("user", user2);
  136. */
  137. /*
  138. * if (page.getPage() < 1) { page.setPage(SearchCondition.gqpage); }
  139. */
  140. if (page.getPage() < 1) {
  141. Object gqpage = CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqpage");
  142. if (StringUtils.isEmpty(gqpage) || !org.apache.commons.lang.StringUtils.isNumeric(String.valueOf(gqpage))) {
  143. gqpage = "1";
  144. }
  145. page.setPage(Integer.valueOf(String.valueOf(gqpage)));
  146. }
  147. page.setSort("gqmc");
  148. page.setOrder("desc");
  149. Page<GqEntity> list = query.findAll(spec, toPageRequest(page), GqEntity.class);
  150. List<GqVo> voList = new ArrayList<GqVo>();
  151. for (GqEntity entity : list) {
  152. GqVo vo = new GqVo();
  153. BeanUtils.copyProperties(entity, vo);
  154. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  155. vo.setSsgkglbmzw(entity.getSsgkglbm() != null ? entity.getSsgkglbm().getGkglbmqc() : "");
  156. vo.setGqszsylxzw(entity.getGqszsylx() != null ? entity.getGqszsylx().getText() : "");
  157. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  158. vo.setSsgkglbm(entity.getSsgkglbm() != null ? entity.getSsgkglbm().getId() : "");
  159. vo.setGqszsylx(entity.getGqszsylx() != null ? entity.getGqszsylx().getId() : "");
  160. voList.add(vo);
  161. }
  162. if (isPOST(request)) {
  163. cacheSCmap.put("gqpage", page.getPage());
  164. CacheSearchCondition.putCacheSCmap(request.getParameterMap(), cacheSCmap);
  165. }
  166. List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
  167. model.addAttribute("listSylx", listSylx);
  168. model.addAttribute("gqmc", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqmc"));
  169. model.addAttribute("szgk", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid"));
  170. model.addAttribute("gqszsylx", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqszsylx"));
  171. model.addAttribute("szd", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szd"));
  172. model.addAttribute("ssgkglbm", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "ssgkglbm"));
  173. model.addAttribute("list", voList);
  174. model.addAttribute("menuid", menuid);
  175. /*
  176. * if (isPOST(request)) { SearchCondition.gqpage = page.getPage();
  177. * SearchCondition.gqmc = gqmc; SearchCondition.gqszd = szd;
  178. * SearchCondition.gqssgkglbm = ssgkglbm; SearchCondition.gqszgk =
  179. * szgkid; SearchCondition.gqszsylx = gqszsylx;
  180. *
  181. * }
  182. */
  183. // 翻页共通
  184. putPageInfo(model, page, list);
  185. return "gkjcxx/gq/gqmain";
  186. }
  187. /**
  188. * 保存
  189. *
  190. * @param model
  191. * @param code
  192. * @return
  193. */
  194. @RequestMapping(value = "/save")
  195. @RequiresPermissions("gqgl:add")
  196. @ResponseBody
  197. public WebJsonResult save(Model model, GqEntity code, String szdid, String szgkid, String ssgkglbmid, String gqszsylxid) {
  198. // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
  199. // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
  200. WebJsonResult wr = success();
  201. if (StringUtils.isEmpty(szdid)) {
  202. wr.setSuccess(false);
  203. wr.setMessage("请选择所在地");
  204. return wr;
  205. }
  206. if (StringUtils.isEmpty(ssgkglbmid)) {
  207. wr.setSuccess(false);
  208. wr.setMessage("请选择港口所属管理部门");
  209. return wr;
  210. }
  211. if (StringUtils.isEmpty(szgkid)) {
  212. wr.setSuccess(false);
  213. wr.setMessage("请选择所在港口");
  214. return wr;
  215. }
  216. GqEntity entity = new GqEntity();
  217. try {
  218. if (!StringUtils.isEmpty(code.getId())) {
  219. entity = gqService.findOne(code.getId());
  220. }
  221. entity.setGqmc(code.getGqmc());
  222. if (!StringUtils.isEmpty(gqszsylxid)) {
  223. CodeEntity gqszsylx = new CodeEntity(gqszsylxid);
  224. entity.setGqszsylx(gqszsylx);
  225. }
  226. entity.setGqmj(code.getGqmj());
  227. entity.setLymj(code.getLymj());
  228. entity.setSyfw(code.getSyfw());
  229. entity.setSymj(code.getSymj());
  230. entity.setGqghmj(code.getGqghmj());
  231. entity.setGhlymj(code.getGhlymj());
  232. entity.setLymj(code.getLymj());
  233. entity.setFgyscydghmj(code.getFgyscydghmj());
  234. entity.setGhsymj(code.getGhsymj());
  235. entity.setGqzraxcd(code.getGqzraxcd());
  236. entity.setGymtaxcd(code.getGymtaxcd());
  237. entity.setGqgkaxcd(code.getGqgkaxcd());
  238. entity.setGkssysyaxcd(code.getGkssysyaxcd());
  239. entity.setGqdmbdzdz(code.getGqdmbdzdz());
  240. entity.setBz(code.getBz());
  241. GkEntity szgk = new GkEntity();
  242. szgk.setId(szgkid);
  243. entity.setSzgk(szgk);
  244. XzglbmxxEntity ssgkglbm = new XzglbmxxEntity();
  245. ssgkglbm.setId(ssgkglbmid);
  246. entity.setSsgkglbm(ssgkglbm);
  247. entity.setGqdm(code.getGqdm());
  248. entity.setGqnhhddm(code.getGqnhhddm());
  249. entity.setDlwzwd(code.getDlwzwd());
  250. entity.setDlwzjd(code.getDlwzjd());
  251. entity.setGqms(code.getGqms());
  252. CodeEntity szd = new CodeEntity(szdid);
  253. entity.setSzd(szd);
  254. entity.setZyid(code.getZyid());
  255. gqService.save(entity);
  256. // 如果是市级新增或者修改,保存后同步到省级
  257. /*try {
  258. if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
  259. GqWebService webService = gqService.getWebService(null);
  260. webService.save(code);
  261. code.setTbzt(Constants.YES);
  262. gqService.save(code);
  263. }
  264. } catch (Exception e) {
  265. code.setTbzt(Constants.NO);
  266. gqService.save(code);
  267. }*/
  268. } catch (Exception e) {
  269. wr.setSuccess(false);
  270. wr.setMessage("操作失败!");
  271. e.printStackTrace();
  272. }
  273. return wr;
  274. }
  275. @RequestMapping(value = "/edit")
  276. @RequiresPermissions("gqgl:edit")
  277. public String edit(Model model, String id) {
  278. GqEntity gq = gqService.findOne(id);
  279. List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
  280. model.addAttribute("listSylx", listSylx);
  281. GqVo vo = new GqVo();
  282. BeanUtils.copyProperties(gq, vo);
  283. /*
  284. * vo.setSzgk(gq.getSzgk().getId());
  285. * vo.setSsgkglbm(gq.getSsgkglbm().getId());
  286. * vo.setGqszsylx(gq.getGqszsylx().getId());
  287. * vo.setSzd(gq.getSzd().getId());
  288. */
  289. vo.setSzgk(gq.getSzgk() != null ? gq.getSzgk().getId() : "");
  290. vo.setSsgkglbm(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getId() : "");
  291. vo.setGqszsylx(gq.getGqszsylx() != null ? gq.getGqszsylx().getId() : "");
  292. vo.setSzd(gq.getSzd() != null ? gq.getSzd().getId() : "");
  293. vo.setSzdzw(gq.getSzd() != null ? gq.getSzd().getText() : "");
  294. vo.setSzgkzw(gq.getSzgk() != null ? gq.getSzgk().getGkmc() : "");
  295. vo.setSsgkglbmzw(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getGkglbmqc() : "");
  296. vo.setGqszsylxzw(gq.getGqszsylx() != null ? gq.getGqszsylx().getText() : "");
  297. if (StringUtils.isEmpty(vo.getZyid())) {
  298. SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  299. String zyid = dateTimeFormat.format(new Date());
  300. vo.setZyid(zyid);
  301. }
  302. model.addAttribute("record", vo);
  303. return "gkjcxx/gq/gqedit";
  304. }
  305. @RequestMapping(value = "/view")
  306. @RequiresPermissions("gqgl:main")
  307. public String view(Model model, String id) {
  308. GqEntity gq = gqService.findOne(id);
  309. List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode("GQSZSYLX");
  310. model.addAttribute("listSylx", listSylx);
  311. GqVo vo = new GqVo();
  312. BeanUtils.copyProperties(gq, vo);
  313. vo.setSzgk(gq.getSzgk() != null ? gq.getSzgk().getId() : "");
  314. vo.setSsgkglbm(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getId() : "");
  315. vo.setGqszsylx(gq.getGqszsylx() != null ? gq.getGqszsylx().getId() : "");
  316. vo.setSzd(gq.getSzd() != null ? gq.getSzd().getId() : "");
  317. vo.setSzdzw(gq.getSzd() != null ? gq.getSzd().getText() : "");
  318. vo.setSzgkzw(gq.getSzgk() != null ? gq.getSzgk().getGkmc() : "");
  319. vo.setSsgkglbmzw(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getGkglbmqc() : "");
  320. vo.setGqszsylxzw(gq.getGqszsylx() != null ? gq.getGqszsylx().getText() : "");
  321. model.addAttribute("record", vo);
  322. return "gkjcxx/gq/gqview";
  323. }
  324. @RequestMapping(value = "/add")
  325. @RequiresPermissions("gqgl:add")
  326. public String add(Model model) {
  327. List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
  328. model.addAttribute("listSylx", listSylx);
  329. if (SecUtils.getCurrUser() != null) {
  330. List<CodeEntity> list = securityMgr.codeService().findValidCodesByGroupCodeAndCity(Constants.GROUP_CODE_SZD, GlobalData.CITY_CODE);
  331. model.addAttribute("sz", list.size() == 1 ? list.get(0).getId() : "");
  332. if (list.size() == 1) {
  333. List<GkEntity> gklist = gkService.findBySzd(list.get(0).getId());
  334. model.addAttribute("gk", gklist.size() == 1 ? gklist.get(0).getId() : "");
  335. }
  336. }
  337. SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  338. String zyid = dateTimeFormat.format(new Date());
  339. model.addAttribute("zyid", zyid);
  340. return "gkjcxx/gq/gqadd";
  341. }
  342. /**
  343. * 删除
  344. */
  345. @RequestMapping(value = "/delete")
  346. @ResponseBody
  347. @RequiresPermissions("gqgl:delete")
  348. public WebJsonResult delete(Model model, String id) {
  349. WebJsonResult wr = success();
  350. try {
  351. // 子类一并删除
  352. gqService.logicDelete(id);
  353. // 如果是市级刪除,省级也刪除
  354. GqEntity gq = gqService.findOne(id);
  355. try {
  356. if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
  357. GqWebService webService = gqService.getWebService(null);
  358. webService.delete(id);
  359. gq.setTbzt(Constants.YES);
  360. gqService.save(gq);
  361. }
  362. } catch (Exception e) {
  363. gq.setTbzt(Constants.NO);
  364. gqService.save(gq);
  365. }
  366. } catch (Exception e) {
  367. wr.setSuccess(false);
  368. wr.setMessage("删除失败!");
  369. e.printStackTrace();
  370. }
  371. return wr;
  372. }
  373. }