AxCtl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. package com.xt.jygl.gkjcxx.ax.ctl;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.io.UnsupportedEncodingException;
  8. import java.net.URLEncoder;
  9. import java.text.SimpleDateFormat;
  10. import java.util.ArrayList;
  11. import java.util.Date;
  12. import java.util.List;
  13. import java.util.Map;
  14. import javax.persistence.criteria.CriteriaBuilder;
  15. import javax.persistence.criteria.CriteriaBuilder.In;
  16. import javax.persistence.criteria.CriteriaQuery;
  17. import javax.persistence.criteria.Predicate;
  18. import javax.persistence.criteria.Root;
  19. import javax.servlet.ServletOutputStream;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import net.sf.json.JSONArray;
  23. import net.sf.json.JSONObject;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.data.domain.Page;
  27. import org.springframework.data.jpa.domain.Specification;
  28. import org.springframework.stereotype.Controller;
  29. import org.springframework.ui.Model;
  30. import org.springframework.web.bind.annotation.RequestMapping;
  31. import org.springframework.web.bind.annotation.RequestParam;
  32. import org.springframework.web.bind.annotation.ResponseBody;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import cache.CacheSearchCondition;
  35. import com.fasterxml.jackson.core.JsonProcessingException;
  36. import com.xt.jygl.common.BaseWebCtl;
  37. import com.xt.jygl.common.Constants;
  38. import com.xt.jygl.common.GlobalData;
  39. import com.xt.jygl.common.SearchCondition;
  40. import com.xt.jygl.common.Utils;
  41. import com.xt.jygl.gkjcxx.ax.client.AxWebService;
  42. import com.xt.jygl.gkjcxx.ax.entity.AxEntity;
  43. import com.xt.jygl.gkjcxx.ax.service.AxService;
  44. import com.xt.jygl.gkjcxx.ax.vo.AxVo;
  45. import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
  46. import com.xt.jygl.gkjcxx.gk.service.GkService;
  47. import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
  48. import com.xt.jygl.gkjcxx.gq.service.GqService;
  49. import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.entity.GkjyrEntity;
  50. import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.service.GkjyrService;
  51. import com.xtframe.core.anon.auth.RequiresPermissions;
  52. import com.xtframe.core.base.ctl.WebJsonResult;
  53. import com.xtframe.core.support.SecurityMgr;
  54. import com.xtframe.sec.code.entity.CodeEntity;
  55. import com.xtframe.sec.common.BaseEntity;
  56. import com.xtframe.sec.common.QueryService;
  57. import com.xtframe.sec.common.SimplePageRequest;
  58. import com.xtframe.sec.utils.SecUtils;
  59. import com.xtframe.util.StringUtils;
  60. @Controller
  61. @RequestMapping("/ax")
  62. public class AxCtl extends BaseWebCtl {
  63. @Autowired
  64. private SecurityMgr securityMgr;
  65. @Autowired
  66. private QueryService query;
  67. @Autowired
  68. private AxService axService;
  69. @Autowired
  70. private GkService gkService;
  71. @Autowired
  72. private GqService gqService;
  73. @Autowired
  74. private GkjyrService gkjyrService;
  75. /**
  76. * 一览页面
  77. * @param page 分页
  78. * @param model
  79. * @param request
  80. * @param axmc 岸线名称
  81. * @param szdid 所在地ID
  82. * @param szgkid 所在港口ID
  83. * @param szgqid 所在港区ID
  84. * @param ssjyr 经营人
  85. * @param menuid
  86. * @param lyztid
  87. * @return
  88. * @throws JsonProcessingException
  89. */
  90. @RequestMapping(value = "/main")
  91. @RequiresPermissions("ax:main")
  92. public String main(SimplePageRequest page, Model model, final HttpServletRequest request, final String axmc, final String szdid, final String szgkid, final String szgqid, final String ssjyr, String menuid,final String lyztid) throws JsonProcessingException {
  93. final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request,"ax");
  94. Specification<AxEntity> spec = new Specification<AxEntity>() {
  95. // 查询条件
  96. @Override
  97. public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  98. List<Predicate> list = new ArrayList<Predicate>();
  99. if (StringUtils.isNotEmpty(axmc)) {
  100. list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
  101. } else if (isGET(request)) {
  102. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, null,"axmc");
  103. }
  104. if (StringUtils.isNotEmpty(szdid)) {
  105. list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
  106. } else if (isGET(request)) {
  107. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szd","szdid");
  108. }
  109. if (StringUtils.isNotEmpty(szgkid)) {
  110. list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
  111. } else if (isGET(request)) {
  112. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szgk","szgkid");
  113. }
  114. if (StringUtils.isNotEmpty(szgqid)) {
  115. list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
  116. } else if (isGET(request)) {
  117. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szgq","szgqid");
  118. }
  119. if (StringUtils.isNotEmpty(ssjyr)) {
  120. list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
  121. } else if (isGET(request)) {
  122. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "gkjyr","ssjyr");
  123. }
  124. if (StringUtils.isNotEmpty(lyztid)) {
  125. list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
  126. } else if (isGET(request)) {
  127. CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","lyzt","lyztid");
  128. }
  129. // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
  130. if (isJyr()) {
  131. list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
  132. } else {
  133. In<String> in = cb.in(root.get("szgq").get("id").as(String.class));
  134. @SuppressWarnings("unchecked")
  135. List<String> gqlist = (List<String>) Utils.getSession()
  136. .getAttribute("gqList");
  137. if (gqlist != null && gqlist.size() > 0) {
  138. for (int i = 0; i < gqlist.size(); i++) {
  139. in.value(gqlist.get(i));
  140. }
  141. list.add(in);
  142. }
  143. }
  144. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_DELETE));
  145. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
  146. return cb.and(list.toArray(new Predicate[] {}));
  147. }
  148. };
  149. if(page.getPage() <1){
  150. page.setPage(SearchCondition.axpage);
  151. }
  152. page.setSort("id");
  153. page.setOrder("desc");
  154. Page<AxEntity> list = query.findAll(spec, toPageRequest(page), AxEntity.class);
  155. List<AxVo> voList = new ArrayList<AxVo>();
  156. for (AxEntity entity : list) {
  157. AxVo vo = new AxVo();
  158. if (null != entity) {
  159. BeanUtils.copyProperties(entity, vo);
  160. vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
  161. vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
  162. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  163. vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
  164. vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
  165. vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
  166. vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
  167. vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
  168. vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
  169. vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
  170. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  171. vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
  172. vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
  173. vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
  174. vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
  175. vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
  176. voList.add(vo);
  177. }
  178. }
  179. if (isPOST(request)) {
  180. SearchCondition.axpage=page.getPage();
  181. //cacheSCmap.put("axpage", page.getPage());
  182. CacheSearchCondition.putCacheSCmap(request.getParameterMap(), cacheSCmap);
  183. }
  184. model.addAttribute("list", voList);
  185. model.addAttribute("axmc", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "axmc"));
  186. model.addAttribute("szd", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szdid"));
  187. model.addAttribute("szgk", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid"));
  188. model.addAttribute("szgq", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgqid"));
  189. model.addAttribute("ssjyr", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "ssjyr"));
  190. model.addAttribute("lyzt",CacheSearchCondition.cacheSCmapVal(cacheSCmap, "lyztid"));
  191. List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
  192. model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
  193. model.addAttribute("menuid", menuid);
  194. // 翻页共通
  195. putPageInfo(model, page, list);
  196. return "gkjcxx/ax/axmain";
  197. }
  198. //删除
  199. @RequestMapping(value = "/delete")
  200. @RequiresPermissions("ax:delete")
  201. @ResponseBody
  202. public WebJsonResult logicdelete(Model model, String id) {
  203. WebJsonResult wr = success();
  204. try {
  205. // 逻辑删除
  206. axService.logicDelete(id);
  207. // 如果是市级删除,省级也删除
  208. AxEntity ax = axService.findOne(id);
  209. try {
  210. if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
  211. AxWebService webService = axService.getWebService(null);
  212. webService.delete(id);
  213. ax.setTbzt(Constants.NO);
  214. axService.save(ax);
  215. }
  216. } catch (Exception e) {
  217. ax.setTbzt(Constants.NO);
  218. axService.save(ax);
  219. }
  220. } catch (Exception e) {
  221. wr.setSuccess(false);
  222. wr.setMessage("操作失败!");
  223. e.printStackTrace();
  224. }
  225. return wr;
  226. }
  227. //保存
  228. @RequestMapping(value = "/save")
  229. @ResponseBody
  230. @RequiresPermissions("ax:add")
  231. public WebJsonResult save(Model model, AxEntity code, String szdid, String szgkid, String szgqid, String ssjyrid, String axlxid, String axgnid, String lyztid,String nbaid) {
  232. // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
  233. // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
  234. WebJsonResult wr = success();
  235. // 必填字段的后台验证
  236. if (StringUtils.isEmpty(szdid)) {
  237. wr.setSuccess(false);
  238. wr.setMessage("请选择所在地");
  239. return wr;
  240. }
  241. if (StringUtils.isEmpty(szgkid)) {
  242. wr.setSuccess(false);
  243. wr.setMessage("请选择所在港口");
  244. return wr;
  245. }
  246. if (StringUtils.isEmpty(szgqid)) {
  247. wr.setSuccess(false);
  248. wr.setMessage("请选择所在港区");
  249. return wr;
  250. }
  251. if (StringUtils.isEmpty(ssjyrid)) {
  252. wr.setSuccess(false);
  253. wr.setMessage("请选择所属经营人");
  254. return wr;
  255. }
  256. AxEntity axEntity = new AxEntity();
  257. try {
  258. if (!StringUtils.isEmpty(code.getId())) {
  259. // 修改
  260. axEntity = axService.findOne(code.getId());
  261. }
  262. axEntity.setAxcd(code.getAxcd());
  263. axEntity.setAxmc(code.getAxmc());
  264. GkEntity szgk = new GkEntity();
  265. szgk.setId(szgkid);
  266. axEntity.setSzgk(szgk);
  267. GqEntity szgq = new GqEntity();
  268. szgq.setId(szgqid);
  269. axEntity.setSzgq(szgq);
  270. GkjyrEntity ssjyr = new GkjyrEntity();
  271. ssjyr.setId(ssjyrid);
  272. axEntity.setSsjyr(ssjyr);
  273. // 非必填字段的验证,如为空则不验证,不为空则验证
  274. if (!StringUtils.isEmpty(axlxid)) {
  275. CodeEntity axlx = new CodeEntity(axlxid);
  276. axEntity.setAxlx(axlx);
  277. }
  278. if (!StringUtils.isEmpty(axgnid)) {
  279. CodeEntity axgn = new CodeEntity(axgnid);
  280. axEntity.setAxgn(axgn);
  281. }
  282. if (!StringUtils.isEmpty(lyztid)) {
  283. CodeEntity lyzt = new CodeEntity(lyztid);
  284. axEntity.setLyzt(lyzt);
  285. }
  286. if (!StringUtils.isEmpty(nbaid)) {
  287. CodeEntity nba = new CodeEntity(nbaid);
  288. axEntity.setNba(nba);
  289. }
  290. axEntity.setZyid(code.getZyid());
  291. axEntity.setJzrq(code.getJzrq());
  292. axEntity.setAxcd(code.getAxcd());
  293. axEntity.setQdzb(code.getQdzb());
  294. axEntity.setZdzb(code.getZdzb());
  295. axEntity.setAxpb(code.getAxpb());
  296. axEntity.setBz(code.getBz());
  297. axEntity.setWaterarea(code.getWaterarea());
  298. axEntity.setLandarea(code.getLandarea());
  299. axEntity.setLinelength(code.getLinelength());
  300. axEntity.setQdzby(code.getQdzby());
  301. axEntity.setZdzby(code.getZdzby());
  302. axEntity.setAxwzms(code.getAxwzms());
  303. GqEntity gq = gqService.findOne(szgqid);
  304. axEntity.setSsgkglbm(gq != null ? gq.getSsgkglbm() : null);
  305. CodeEntity szd = new CodeEntity(szdid);
  306. axEntity.setSzd(szd);
  307. axService.save(axEntity);
  308. } catch (Exception e) {
  309. wr.setSuccess(false);
  310. wr.setMessage("操作失败!");
  311. e.printStackTrace();
  312. }
  313. return wr;
  314. }
  315. //编辑
  316. @RequestMapping(value = "/edit")
  317. @RequiresPermissions("ax:edit")
  318. public String edit(Model model, String id) {
  319. List<CodeEntity> axlxlist = securityMgr.codeService().findValidCodesByGroupCode("AXLX");
  320. model.addAttribute("axlxlist", JSONArray.fromObject(axlxlist, config).toString());
  321. List<CodeEntity> axgnlist = securityMgr.codeService().findValidCodesByGroupCode("AXGN");
  322. model.addAttribute("axgnlist", JSONArray.fromObject(axgnlist, config).toString());
  323. List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
  324. model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
  325. List<CodeEntity> nbalist = securityMgr.codeService().findValidCodesByGroupCode("NBA");
  326. model.addAttribute("nbalist",JSONArray.fromObject(nbalist,config).toString());
  327. AxEntity entity = axService.findOne(id);
  328. AxVo vo = new AxVo();
  329. BeanUtils.copyProperties(entity, vo);
  330. vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
  331. vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
  332. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  333. vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
  334. vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
  335. vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
  336. vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
  337. vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
  338. vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
  339. vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
  340. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  341. vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
  342. vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
  343. vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
  344. vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
  345. vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
  346. if(StringUtils.isEmpty(vo.getZyid())){
  347. SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  348. String zyid = dateTimeFormat.format(new Date());
  349. vo.setZyid(zyid);
  350. }
  351. model.addAttribute("record", vo);
  352. model.addAttribute("jyr", getSsjyr() != null ? JSONObject.fromObject(getSsjyr()).toString() : null);
  353. return "gkjcxx/ax/axedit";
  354. }
  355. //查看
  356. @RequestMapping(value = "/view")
  357. @RequiresPermissions("ax:main")
  358. public String view(Model model, String id) {
  359. AxVo vo = new AxVo();
  360. AxEntity entity = axService.findOne(id);
  361. if (entity != null) {
  362. BeanUtils.copyProperties(entity, vo);
  363. vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
  364. vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
  365. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  366. vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
  367. vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
  368. vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
  369. vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
  370. vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
  371. vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
  372. vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
  373. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  374. vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
  375. vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
  376. vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
  377. vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
  378. vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
  379. if (null != entity.getJzrq()) {
  380. vo.setJzrqfmt(new SimpleDateFormat("yyyy-MM-dd").format(entity.getJzrq()));
  381. }
  382. }
  383. model.addAttribute("record", vo);
  384. return "gkjcxx/ax/axview";
  385. }
  386. //新增
  387. @RequestMapping(value = "/add")
  388. @RequiresPermissions("ax:add")
  389. public String add(Model model) {
  390. List<CodeEntity> axlxlist = securityMgr.codeService().findValidCodesByGroupCode("AXLX");
  391. model.addAttribute("axlxlist", JSONArray.fromObject(axlxlist, config).toString());
  392. List<CodeEntity> axgnlist = securityMgr.codeService().findValidCodesByGroupCode("AXGN");
  393. model.addAttribute("axgnlist", JSONArray.fromObject(axgnlist, config).toString());
  394. List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
  395. model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
  396. List<CodeEntity> nbalist = securityMgr.codeService().findValidCodesByGroupCode("NBA");
  397. model.addAttribute("nbalist",JSONArray.fromObject(nbalist, config).toString());
  398. model.addAttribute("jyr", getSsjyr() != null ? JSONObject.fromObject(getSsjyr()).toString() : null);
  399. if(SecUtils.getCurrUser() != null){
  400. List<CodeEntity> list = securityMgr.codeService().findValidCodesByGroupCodeAndCity(Constants.GROUP_CODE_SZD, GlobalData.CITY_CODE);
  401. model.addAttribute("sz",list.size()==1?list.get(0).getId():"");
  402. if(list.size()==1){
  403. List<GkEntity> gklist = gkService.findBySzd(list.get(0).getId());
  404. model.addAttribute("gk",gklist.size()==1?gklist.get(0).getId():"");
  405. }
  406. }
  407. SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  408. String zyid = dateTimeFormat.format(new Date());
  409. model.addAttribute("zyid", zyid);
  410. return "gkjcxx/ax/axadd";
  411. }
  412. /**
  413. * 导出全部数据到excel
  414. *
  415. * @param response
  416. * @return
  417. */
  418. @RequestMapping(value = "/exportExcelAll")
  419. public String exportExcelAll(HttpServletResponse response, final String axmc, final String szdid, final String szgkid, final String szgqid, final String ssjyr, final String lyztid) {
  420. Specification<AxEntity> spec = new Specification<AxEntity>() {
  421. // 查询条件
  422. @Override
  423. public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  424. List<Predicate> list = new ArrayList<Predicate>();
  425. if (StringUtils.isNotEmpty(axmc)) {
  426. list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
  427. }
  428. if (StringUtils.isNotEmpty(szdid)) {
  429. list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
  430. }
  431. if (StringUtils.isNotEmpty(szgkid)) {
  432. list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
  433. }
  434. if (StringUtils.isNotEmpty(szgqid)) {
  435. list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
  436. }
  437. if (StringUtils.isNotEmpty(ssjyr)) {
  438. list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
  439. }
  440. if (StringUtils.isNotEmpty(lyztid)) {
  441. list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
  442. }
  443. // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
  444. if (isJyr()) {
  445. list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
  446. } else {
  447. In<String> in = cb.in(root.get("szgq").get("id").as(String.class));
  448. @SuppressWarnings("unchecked")
  449. List<String> gqlist = (List<String>) Utils.getSession()
  450. .getAttribute("gqList");
  451. if (gqlist != null && gqlist.size() > 0) {
  452. for (int i = 0; i < gqlist.size(); i++) {
  453. in.value(gqlist.get(i));
  454. }
  455. list.add(in);
  456. }
  457. }
  458. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_DELETE));
  459. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
  460. return cb.and(list.toArray(new Predicate[] {}));
  461. }
  462. };
  463. List<AxEntity> list = query.findAll(spec, AxEntity.class);
  464. List<AxVo> voList = new ArrayList<AxVo>();
  465. for (AxEntity entity : list) {
  466. AxVo vo = new AxVo();
  467. if (null != entity) {
  468. BeanUtils.copyProperties(entity, vo);
  469. vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
  470. vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
  471. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  472. vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
  473. vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
  474. vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
  475. vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
  476. vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
  477. vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
  478. vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
  479. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  480. vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
  481. vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
  482. vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
  483. vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
  484. vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
  485. voList.add(vo);
  486. }
  487. }
  488. response.setContentType("application/binary;charset=iso-8859-1");
  489. try {
  490. ServletOutputStream outputStream = response.getOutputStream();
  491. String fileName = new String(("岸线信息全部").getBytes(), "iso-8859-1");
  492. response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
  493. String[] titles = { "序号", "岸线名称", "所在港口", "所在港区", "所属经营人", "利用状态" };
  494. axService.exportExcelAll(voList, titles, outputStream);
  495. } catch (IOException e) {
  496. e.printStackTrace();
  497. }
  498. return null;
  499. }
  500. /**
  501. * 导出当前页数据到excel
  502. *
  503. * @param response
  504. * @param axmc
  505. * @param szdid
  506. * @param szgkid
  507. * @param szgqid
  508. * @param ssjyr
  509. * @return
  510. */
  511. @RequestMapping(value = "/exportExcelthisPage")
  512. public String exportExcelthisPage(SimplePageRequest page, HttpServletResponse response, final String axmc, final String szdid, final String szgkid, final String szgqid, final String ssjyr, int pageNum, int pageSize, final String lyztid) {
  513. Specification<AxEntity> spec = new Specification<AxEntity>() {
  514. @Override
  515. public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  516. List<Predicate> list = new ArrayList<Predicate>();
  517. if (StringUtils.isNotEmpty(axmc)) {
  518. list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
  519. }
  520. if (StringUtils.isNotEmpty(szdid)) {
  521. list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
  522. }
  523. if (StringUtils.isNotEmpty(szgkid)) {
  524. list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
  525. }
  526. if (StringUtils.isNotEmpty(szgqid)) {
  527. list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
  528. }
  529. if (StringUtils.isNotEmpty(ssjyr)) {
  530. list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
  531. }
  532. if (StringUtils.isNotEmpty(lyztid)) {
  533. list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
  534. }
  535. // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
  536. if (isJyr()) {
  537. list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
  538. } else {
  539. In<String> in = cb.in(root.get("szgq").get("id").as(String.class));
  540. @SuppressWarnings("unchecked")
  541. List<String> gqlist = (List<String>) Utils.getSession()
  542. .getAttribute("gqList");
  543. if (gqlist != null && gqlist.size() > 0) {
  544. for (int i = 0; i < gqlist.size(); i++) {
  545. in.value(gqlist.get(i));
  546. }
  547. list.add(in);
  548. }
  549. }
  550. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_DELETE));
  551. list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
  552. return cb.and(list.toArray(new Predicate[] {}));
  553. }
  554. };
  555. page.setPage(pageNum);
  556. page.setRows(pageSize);
  557. page.setSort("id");
  558. page.setOrder("desc");
  559. Page<AxEntity> list = query.findAll(spec, toPageRequest(page), AxEntity.class);
  560. List<AxVo> voList = new ArrayList<AxVo>();
  561. for (AxEntity entity : list) {
  562. AxVo vo = new AxVo();
  563. if (null != entity) {
  564. BeanUtils.copyProperties(entity, vo);
  565. vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
  566. vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
  567. vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
  568. vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
  569. vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
  570. vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
  571. vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
  572. vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
  573. vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
  574. vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
  575. vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
  576. vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
  577. vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
  578. vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
  579. vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
  580. vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
  581. voList.add(vo);
  582. }
  583. }
  584. response.setContentType("application/binary;charset=iso-8859-1");
  585. try {
  586. ServletOutputStream outputStream = response.getOutputStream();
  587. String fileName = new String(("岸线信息单页").getBytes(), "iso-8859-1");
  588. response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
  589. String[] titles = { "序号", "岸线名称", "所在港口", "所在港区", "所属经营人", "利用状态" };
  590. axService.exportExcelthisPage(voList, titles, outputStream);
  591. } catch (IOException e) {
  592. e.printStackTrace();
  593. }
  594. return null;
  595. }
  596. /**
  597. * 打开批量导入页面
  598. *
  599. * @param model
  600. * @return
  601. */
  602. @RequestMapping(value = "/inputAll")
  603. public String inputAll(Model model) {
  604. return "gkjcxx/ax/inputAll";
  605. }
  606. /**
  607. * 批量导入excel数据
  608. *
  609. * @param model
  610. * @return
  611. */
  612. @SuppressWarnings("unchecked")
  613. @RequestMapping(value = "/report")
  614. @ResponseBody
  615. public WebJsonResult report(@RequestParam MultipartFile file) throws IOException {
  616. WebJsonResult wr = success();
  617. try {
  618. Map<String, Object> map = axService.readReport(file.getInputStream());
  619. if (((List<String>) map.get("error")).size() > 0) {
  620. List<String> errorList = (List<String>) map.get("error");
  621. for (int j = 0; j < errorList.size(); j++) {
  622. File file1 = new File("D:/bug.txt");
  623. if (!file1.exists()) {
  624. file1.createNewFile();
  625. }
  626. FileOutputStream fos = new FileOutputStream("D:/bug.txt", true);
  627. fos.write(errorList.get(j).getBytes());
  628. fos.flush();
  629. fos.close();
  630. }
  631. wr.setMessage("导入文件有错误,请根据操作日志修改正确后重新导入!");
  632. } else {
  633. List<AxEntity> axList = (List<AxEntity>) map.get("axList");
  634. for (int i = 0; i < axList.size(); i++) {
  635. axService.save(axList.get(i));
  636. }
  637. wr.setMessage("数据导入成功!");
  638. }
  639. } catch (Exception e) {
  640. wr.setSuccess(false);
  641. wr.setMessage("操作失败!");
  642. e.printStackTrace();
  643. }
  644. return wr;
  645. }
  646. /**
  647. * 下载错误日志
  648. *
  649. * @param request
  650. * @param response
  651. * @throws UnsupportedEncodingException
  652. */
  653. @RequestMapping(value = "/downLoadTxt")
  654. public void DownLoadTxt(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
  655. response.setCharacterEncoding("utf-8");
  656. response.setContentType("multipart/form-data");
  657. String fileName = "错误日志.txt";
  658. if ("FF".equals(getBrowser(request))) {
  659. // 针对火狐浏览器处理方式不一样了
  660. fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
  661. } else {
  662. fileName = URLEncoder.encode(fileName, "UTF-8");
  663. }
  664. response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
  665. File file = new File("D:/bug.txt");
  666. try {
  667. FileReader reader = new FileReader(file);
  668. BufferedReader br = new BufferedReader(reader);
  669. String line = br.readLine();
  670. while (line != null) {
  671. response.getOutputStream().write(line.getBytes());
  672. line = br.readLine();
  673. }
  674. br.close();
  675. file.delete();
  676. return;
  677. } catch (IOException e) {
  678. // TODO Auto-generated catch block
  679. e.printStackTrace();
  680. }
  681. }
  682. /**
  683. * 服务器端判断客户端浏览器类型(IE/FF/SF)
  684. *
  685. * @param request
  686. * @return
  687. */
  688. public static String getBrowser(HttpServletRequest request) {
  689. String UserAgent = request.getHeader("USER-AGENT").toLowerCase();
  690. if (UserAgent != null) {
  691. if (UserAgent.indexOf("msie") >= 0)
  692. return "IE";
  693. if (UserAgent.indexOf("firefox") >= 0)
  694. return "FF";
  695. if (UserAgent.indexOf("safari") >= 0)
  696. return "SF";
  697. }
  698. return null;
  699. }
  700. /***
  701. * 解决js传入参数乱码
  702. *
  703. * @param str
  704. * @return
  705. */
  706. static String enCodeStr(String str) {
  707. if (str == null) {
  708. str = "";
  709. }
  710. try {
  711. return new String(str.getBytes("iso-8859-1"), "UTF-8");
  712. } catch (UnsupportedEncodingException e) {
  713. e.printStackTrace();
  714. return null;
  715. }
  716. }
  717. }