123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- package com.xt.jygl.gkjcxx.jghd.ctl;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import javax.persistence.criteria.CriteriaBuilder;
- import javax.persistence.criteria.CriteriaQuery;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
- import javax.persistence.criteria.CriteriaBuilder.In;
- import javax.servlet.http.HttpServletRequest;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import cache.CacheSearchCondition;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.xt.jygl.common.BaseWebCtl;
- import com.xt.jygl.common.Constants;
- import com.xt.jygl.common.GlobalData;
- import com.xt.jygl.common.SearchCondition;
- import com.xt.jygl.common.Utils;
- import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
- import com.xt.jygl.gkjcxx.gk.service.GkService;
- import com.xt.jygl.gkjcxx.gq.service.GqService;
- import com.xt.jygl.gkjcxx.jghd.entity.JghdEntity;
- import com.xt.jygl.gkjcxx.jghd.service.JghdService;
- import com.xt.jygl.gkjcxx.jghd.vo.JghdVo;
- import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.service.GkjyrService;
- import com.xtframe.core.anon.auth.RequiresPermissions;
- import com.xtframe.core.base.ctl.WebJsonResult;
- import com.xtframe.core.support.SecurityMgr;
- import com.xtframe.sec.code.entity.CodeEntity;
- import com.xtframe.sec.common.BaseEntity;
- import com.xtframe.sec.common.QueryService;
- import com.xtframe.sec.common.SimplePageRequest;
- import com.xtframe.sec.utils.SecUtils;
- import com.xtframe.util.StringUtils;
- @Controller
- @RequestMapping("/jghd")
- public class JghdCtl extends BaseWebCtl {
- @Autowired
- private SecurityMgr securityMgr;
- @Autowired
- private QueryService query;
- @Autowired
- private JghdService jghdService;
- @Autowired
- private GkService gkService;
- @Autowired
- private GqService gqService;
- @Autowired
- private GkjyrService gkjyrService;
- /**
- * 一览页面
- * @param page 分页
- * @param model
- * @param request
- * @param szdid 所在地ID
- * @param szgkid 所在港口ID
- * @param hdmc 航道名称
- * @param hdlx
- * @param menuid
- * @return
- * @throws JsonProcessingException
- */
- @RequestMapping(value = "/main")
- @RequiresPermissions("jghd:main")
- public String main(SimplePageRequest page, Model model,final HttpServletRequest request, final String szdid, final String szgkid, final String hdmc, final String hdlx, String menuid) throws JsonProcessingException {
- final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request,"jghd");
- Specification<JghdEntity> spec = new Specification<JghdEntity>() {
- // 查询条件
- @Override
- public Predicate toPredicate(Root<JghdEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> list = new ArrayList<Predicate>();
- if (StringUtils.isNotEmpty(szdid)) {
- list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
- }else if(isGET(request)){
- //list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + SearchCondition.hdszdid + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szd","szdid");
- }
- if (StringUtils.isNotEmpty(szgkid)) {
- list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
- }else if(isGET(request)){
- //list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + SearchCondition.hdszgkid + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szgk","szgkid");
- }
- if (StringUtils.isNotEmpty(hdmc)) {
- list.add(cb.like(root.get("hdmc").as(String.class), "%" + hdmc + "%"));
- }else if(isGET(request)){
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, null,"hdmc");
- }
- if (StringUtils.isNotEmpty(hdlx)) {
- list.add(cb.like(root.get("hdlx").as(String.class), "%" + hdlx + "%"));
- }
- if (isJyr()) {
- //list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
- } else {
- In<String> in = cb.in(root.get("szgq").as(String.class));
- @SuppressWarnings("unchecked")
- List<String> gqlist = (List<String>) Utils.getSession().getAttribute("gqList");
- if (gqlist != null && gqlist.size() > 0) {
- for (int i = 0; i < gqlist.size(); i++) {
- in.value(gqlist.get(i));
- }
- list.add(in);
- }
- }
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORD_STATE_DELETE));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
-
- if(page.getPage()<1){
- page.setPage(SearchCondition.hdpage);
- }
-
- page.setSort("id");
- page.setOrder("desc");
- Page<JghdEntity> list = query.findAll(spec, toPageRequest(page), JghdEntity.class);
- List<JghdVo> voList = new ArrayList<JghdVo>();
- for (JghdEntity entity : list) {
- JghdVo vo = new JghdVo();
- if (null != entity) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- voList.add(vo);
- }
- }
-
- if (isPOST(request)) {
- SearchCondition.hdpage=page.getPage();
- //cacheSCmap.put("hdpage", page.getPage());
- CacheSearchCondition.putCacheSCmap(request.getParameterMap(), cacheSCmap);
- }
- model.addAttribute("list", voList);
- model.addAttribute("szd", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szdid"));
- model.addAttribute("szgk",CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid"));
- model.addAttribute("hdmc", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "hdmc"));
- model.addAttribute("hdlx", hdlx);
- model.addAttribute("menuid", menuid);
-
-
- // 翻页共通
- putPageInfo(model, page, list);
- return "gkjcxx/jghd/jghdmain";
- }
- @RequestMapping(value = "/delete")
- @RequiresPermissions("jghd:delete")
- @ResponseBody
- public WebJsonResult logicdelete(Model model, String id) {
- WebJsonResult wr = success();
- try {
- // 逻辑删除
- jghdService.logicDelete(id);
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- /**
- * 保存信息
- * @param model
- * @param code
- * @param szdid
- * @param szgkid
- * @return
- */
- @RequestMapping(value = "/save")
- @RequiresPermissions("jghd:add")
- @ResponseBody
- public WebJsonResult save(Model model, JghdEntity code, String szdid, String szgkid) {
- // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
- // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
- WebJsonResult wr = success();
- if (StringUtils.isEmpty(szdid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在地");
- }
- if (StringUtils.isEmpty(szgkid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在港口");
- }
- JghdEntity jghdEntity = new JghdEntity();
- try {
- if (!StringUtils.isEmpty(code.getId())) {
- // 修改
- jghdEntity = jghdService.findOne(code.getId());
- }
- GkEntity szgk = new GkEntity();
- szgk.setId(szgkid);
- jghdEntity.setSzgk(szgk);
- GkEntity gk = gkService.findOne(szgkid);
- if (gk != null) {
- jghdEntity.setSsgkglbm(gk.getSsgkglbm());
- }
- CodeEntity szd = new CodeEntity(szdid);
- jghdEntity.setSzd(szd);
- jghdEntity.setBz(code.getBz());
- jghdEntity.setHdcd(code.getHdcd());
- jghdEntity.setHddm(code.getHddm());
- jghdEntity.setHdkd(code.getHdkd());
- jghdEntity.setHdmc(code.getHdmc());
- jghdEntity.setHdqdmc(code.getHdqdmc());
- jghdEntity.setHdqdmm(code.getHdqdmm());
- jghdEntity.setHdss(code.getHdss());
- jghdEntity.setHdyxkd(code.getHdyxkd());
- jghdEntity.setHdzdss(code.getHdzdss());
- jghdEntity.setHdtgnl(code.getHdtgnl());
- jghdEntity.setSzgq(code.getSzgq());
- jghdService.save(jghdEntity);
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- /**
- * 编辑
- * @param model
- * @param id
- * @return
- */
- @RequestMapping(value = "/edit")
- @RequiresPermissions("jghd:edit")
- public String edit(Model model, String id) {
- JghdEntity jghd = jghdService.findOne(id);
- JghdVo vo = new JghdVo();
- BeanUtils.copyProperties(jghd, vo);
- vo.setSzd(jghd.getSzd() != null ? jghd.getSzd().getId() : "");
- vo.setSzgk(jghd.getSzgk() != null ? jghd.getSzgk().getId() : "");
- vo.setSzdzw(jghd.getSzd() != null ? jghd.getSzd().getText() : "");
- vo.setSzgkzw(jghd.getSzgk() != null ? jghd.getSzgk().getGkmc() : "");
- model.addAttribute("record", vo);
- return "gkjcxx/jghd/jghdedit";
- }
- /**
- * 查看
- * @param model
- * @param id
- * @return
- */
- @RequestMapping(value = "/view")
- @RequiresPermissions("jghd:main")
- public String view(Model model, String id) {
- JghdVo vo = new JghdVo();
- JghdEntity jghd = jghdService.findOne(id);
- BeanUtils.copyProperties(jghd, vo);
- vo.setSzd(jghd.getSzd() != null ? jghd.getSzd().getId() : "");
- vo.setSzdzw(jghd.getSzd() != null ? jghd.getSzd().getText() : "");
- vo.setSzgk(jghd.getSzgk() != null ? jghd.getSzgk().getId() : "");
- vo.setSzgkzw(jghd.getSzgk() != null ? jghd.getSzgk().getGkmc() : "");
- String gqName = "";
- if (jghd.getSzgq() != null) {
- String[] szgqNameArray = jghd.getSzgq().split(",");
- for (String s : szgqNameArray) {
- gqName += gqService.findOne(s).getGqmc() + " ";
- }
- }
- vo.setSzgqzw(gqName);
- model.addAttribute("record", vo);
- return "gkjcxx/jghd/jghdview";
- }
- /**
- * 新增
- * @param model
- * @return
- */
- @RequestMapping(value = "/add")
- @RequiresPermissions("jghd:add")
- public String add(Model model) {
- if(SecUtils.getCurrUser() != null){
- List<CodeEntity> list = securityMgr.codeService().findValidCodesByGroupCodeAndCity(Constants.GROUP_CODE_SZD, GlobalData.CITY_CODE);
- model.addAttribute("sz",list.size()==1?list.get(0).getId():"");
- if(list.size()==1){
- List<GkEntity> gklist = gkService.findBySzd(list.get(0).getId());
- model.addAttribute("gk",gklist.size()==1?gklist.get(0).getId():"");
- }
- }
- return "gkjcxx/jghd/jghdadd";
- }
- }
|