123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- package com.xt.jygl.gkjcxx.gq.ctl;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- 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.Utils;
- import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
- import com.xt.jygl.gkjcxx.gk.service.GkService;
- import com.xt.jygl.gkjcxx.gq.client.GqWebService;
- import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
- import com.xt.jygl.gkjcxx.gq.service.GqService;
- import com.xt.jygl.gkjcxx.gq.vo.GqVo;
- import com.xt.jygl.gkjcxx.xzdwxxgl.xzglbmxx.entity.XzglbmxxEntity;
- import com.xt.jygl.gkjcxx.xzdwxxgl.xzglbmxx.service.XzglbmxxService;
- 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
- *
- * @author zhaohang
- *
- */
- @Controller
- @RequestMapping("/gq")
- public class GqCtl extends BaseWebCtl {
- @Autowired
- private SecurityMgr securityMgr;
- @Autowired
- private QueryService query;
- @Autowired
- private GqService gqService;
- @Autowired
- private GkService gkService;
- @Autowired
- private XzglbmxxService xzglbmService;
- /**
- * 显示港区
- */
- @RequestMapping(value = "/main")
- @RequiresPermissions("gqgl:main")
- 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 {
- final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request, "gqgl");
- // 查询条件
- Specification<GqEntity> spec = new Specification<GqEntity>() {
- @Override
- public Predicate toPredicate(Root<GqEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> list = new ArrayList<Predicate>();
- if (StringUtils.isNotEmpty(gqmc)) {
- list.add(cb.like(root.get("gqmc").as(String.class), "%" + gqmc + "%"));
- } else if (isGET(request)) {
- // list.add(cb.like(root.get("gqmc").as(String.class), "%" +
- // SearchCondition.gqmc + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, null, "gqmc");
- }
- if (StringUtils.isNotEmpty(gqszsylx)) {
- list.add(cb.like(root.get("gqszsylx").get("id").as(String.class), "%" + gqszsylx + "%"));
- } else if (isGET(request)) {
- // list.add(cb.like(root.get("gqszsylx").get("id").as(String.class),
- // "%" + SearchCondition.gqszsylx + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "gqszsylx");
- }
- 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.gqszgk + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "szgk", "szgkid");
- }
- if (StringUtils.isNotEmpty(szd)) {
- list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szd + "%"));
- } else if (isGET(request)) {
- // list.add(cb.like(root.get("szd").get("id").as(String.class),
- // "%" + SearchCondition.gqszd + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "szd");
- }
- if (StringUtils.isNotEmpty(ssgkglbm)) {
- list.add(cb.like(root.get("ssgkglbm").get("id").as(String.class), "%" + ssgkglbm + "%"));
- } else if (isGET(request)) {
- // list.add(cb.like(root.get("ssgkglbm").get("id").as(String.class),
- // "%" + SearchCondition.gqssgkglbm + "%"));
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id", "ssgkglbm");
- }
- if (isJyr()) {
- //list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%"));
- } else {
- In<String> in = cb.in(root.get("id").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(String.class), BaseEntity.RECORD_STATE_DELETE));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
- /*
- * String user1 = (String) Utils.getSession().getAttribute("user");
- * String user2 = SecUtils.getCurrUser().getId(); if(user2!=null){
- * if(!user2.equals(user1)){ SearchCondition.gqpage = 1;
- * SearchCondition.gqmc = ""; SearchCondition.gqszd = "";
- * SearchCondition.gqssgkglbm = ""; SearchCondition.gqszgk = "";
- * SearchCondition.gqszsylx = ""; }
- *
- * } Utils.getSession().setAttribute("user", user2);
- */
- /*
- * if (page.getPage() < 1) { page.setPage(SearchCondition.gqpage); }
- */
- if (page.getPage() < 1) {
- Object gqpage = CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqpage");
- if (StringUtils.isEmpty(gqpage) || !org.apache.commons.lang.StringUtils.isNumeric(String.valueOf(gqpage))) {
- gqpage = "1";
- }
- page.setPage(Integer.valueOf(String.valueOf(gqpage)));
- }
- page.setSort("gqmc");
- page.setOrder("desc");
- Page<GqEntity> list = query.findAll(spec, toPageRequest(page), GqEntity.class);
- List<GqVo> voList = new ArrayList<GqVo>();
- for (GqEntity entity : list) {
- GqVo vo = new GqVo();
- BeanUtils.copyProperties(entity, vo);
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsgkglbmzw(entity.getSsgkglbm() != null ? entity.getSsgkglbm().getGkglbmqc() : "");
- vo.setGqszsylxzw(entity.getGqszsylx() != null ? entity.getGqszsylx().getText() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsgkglbm(entity.getSsgkglbm() != null ? entity.getSsgkglbm().getId() : "");
- vo.setGqszsylx(entity.getGqszsylx() != null ? entity.getGqszsylx().getId() : "");
- voList.add(vo);
- }
- if (isPOST(request)) {
- cacheSCmap.put("gqpage", page.getPage());
- CacheSearchCondition.putCacheSCmap(request.getParameterMap(), cacheSCmap);
- }
- List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
- model.addAttribute("listSylx", listSylx);
- model.addAttribute("gqmc", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqmc"));
- model.addAttribute("szgk", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid"));
- model.addAttribute("gqszsylx", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "gqszsylx"));
- model.addAttribute("szd", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szd"));
- model.addAttribute("ssgkglbm", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "ssgkglbm"));
- model.addAttribute("list", voList);
- model.addAttribute("menuid", menuid);
- /*
- * if (isPOST(request)) { SearchCondition.gqpage = page.getPage();
- * SearchCondition.gqmc = gqmc; SearchCondition.gqszd = szd;
- * SearchCondition.gqssgkglbm = ssgkglbm; SearchCondition.gqszgk =
- * szgkid; SearchCondition.gqszsylx = gqszsylx;
- *
- * }
- */
- // 翻页共通
- putPageInfo(model, page, list);
- return "gkjcxx/gq/gqmain";
- }
- /**
- * 保存
- *
- * @param model
- * @param code
- * @return
- */
- @RequestMapping(value = "/save")
- @RequiresPermissions("gqgl:add")
- @ResponseBody
- public WebJsonResult save(Model model, GqEntity code, String szdid, String szgkid, String ssgkglbmid, String gqszsylxid) {
- // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
- // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
- WebJsonResult wr = success();
- if (StringUtils.isEmpty(szdid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在地");
- return wr;
- }
- if (StringUtils.isEmpty(ssgkglbmid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择港口所属管理部门");
- return wr;
- }
- if (StringUtils.isEmpty(szgkid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在港口");
- return wr;
- }
- GqEntity entity = new GqEntity();
- try {
- if (!StringUtils.isEmpty(code.getId())) {
- entity = gqService.findOne(code.getId());
- }
- entity.setGqmc(code.getGqmc());
- if (!StringUtils.isEmpty(gqszsylxid)) {
- CodeEntity gqszsylx = new CodeEntity(gqszsylxid);
- entity.setGqszsylx(gqszsylx);
- }
- entity.setGqmj(code.getGqmj());
- entity.setLymj(code.getLymj());
- entity.setSyfw(code.getSyfw());
- entity.setSymj(code.getSymj());
- entity.setGqghmj(code.getGqghmj());
- entity.setGhlymj(code.getGhlymj());
- entity.setLymj(code.getLymj());
- entity.setFgyscydghmj(code.getFgyscydghmj());
- entity.setGhsymj(code.getGhsymj());
- entity.setGqzraxcd(code.getGqzraxcd());
- entity.setGymtaxcd(code.getGymtaxcd());
- entity.setGqgkaxcd(code.getGqgkaxcd());
- entity.setGkssysyaxcd(code.getGkssysyaxcd());
- entity.setGqdmbdzdz(code.getGqdmbdzdz());
- entity.setBz(code.getBz());
- GkEntity szgk = new GkEntity();
- szgk.setId(szgkid);
- entity.setSzgk(szgk);
- XzglbmxxEntity ssgkglbm = new XzglbmxxEntity();
- ssgkglbm.setId(ssgkglbmid);
- entity.setSsgkglbm(ssgkglbm);
- entity.setGqdm(code.getGqdm());
- entity.setGqnhhddm(code.getGqnhhddm());
- entity.setDlwzwd(code.getDlwzwd());
- entity.setDlwzjd(code.getDlwzjd());
- entity.setGqms(code.getGqms());
- CodeEntity szd = new CodeEntity(szdid);
- entity.setSzd(szd);
- entity.setZyid(code.getZyid());
- gqService.save(entity);
- // 如果是市级新增或者修改,保存后同步到省级
- /*try {
- if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
- GqWebService webService = gqService.getWebService(null);
- webService.save(code);
- code.setTbzt(Constants.YES);
- gqService.save(code);
- }
- } catch (Exception e) {
- code.setTbzt(Constants.NO);
- gqService.save(code);
- }*/
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- @RequestMapping(value = "/edit")
- @RequiresPermissions("gqgl:edit")
- public String edit(Model model, String id) {
- GqEntity gq = gqService.findOne(id);
- List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
- model.addAttribute("listSylx", listSylx);
- GqVo vo = new GqVo();
- BeanUtils.copyProperties(gq, vo);
- /*
- * vo.setSzgk(gq.getSzgk().getId());
- * vo.setSsgkglbm(gq.getSsgkglbm().getId());
- * vo.setGqszsylx(gq.getGqszsylx().getId());
- * vo.setSzd(gq.getSzd().getId());
- */
- vo.setSzgk(gq.getSzgk() != null ? gq.getSzgk().getId() : "");
- vo.setSsgkglbm(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getId() : "");
- vo.setGqszsylx(gq.getGqszsylx() != null ? gq.getGqszsylx().getId() : "");
- vo.setSzd(gq.getSzd() != null ? gq.getSzd().getId() : "");
- vo.setSzdzw(gq.getSzd() != null ? gq.getSzd().getText() : "");
- vo.setSzgkzw(gq.getSzgk() != null ? gq.getSzgk().getGkmc() : "");
- vo.setSsgkglbmzw(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getGkglbmqc() : "");
- vo.setGqszsylxzw(gq.getGqszsylx() != null ? gq.getGqszsylx().getText() : "");
- if (StringUtils.isEmpty(vo.getZyid())) {
- SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
- String zyid = dateTimeFormat.format(new Date());
- vo.setZyid(zyid);
- }
- model.addAttribute("record", vo);
- return "gkjcxx/gq/gqedit";
- }
- @RequestMapping(value = "/view")
- @RequiresPermissions("gqgl:main")
- public String view(Model model, String id) {
- GqEntity gq = gqService.findOne(id);
- List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode("GQSZSYLX");
- model.addAttribute("listSylx", listSylx);
- GqVo vo = new GqVo();
- BeanUtils.copyProperties(gq, vo);
- vo.setSzgk(gq.getSzgk() != null ? gq.getSzgk().getId() : "");
- vo.setSsgkglbm(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getId() : "");
- vo.setGqszsylx(gq.getGqszsylx() != null ? gq.getGqszsylx().getId() : "");
- vo.setSzd(gq.getSzd() != null ? gq.getSzd().getId() : "");
- vo.setSzdzw(gq.getSzd() != null ? gq.getSzd().getText() : "");
- vo.setSzgkzw(gq.getSzgk() != null ? gq.getSzgk().getGkmc() : "");
- vo.setSsgkglbmzw(gq.getSsgkglbm() != null ? gq.getSsgkglbm().getGkglbmqc() : "");
- vo.setGqszsylxzw(gq.getGqszsylx() != null ? gq.getGqszsylx().getText() : "");
- model.addAttribute("record", vo);
- return "gkjcxx/gq/gqview";
- }
- @RequestMapping(value = "/add")
- @RequiresPermissions("gqgl:add")
- public String add(Model model) {
- List<CodeEntity> listSylx = securityMgr.codeService().findValidCodesByGroupCode(Constants.GQ_CODE_GQSZSYLX);
- model.addAttribute("listSylx", listSylx);
- 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() : "");
- }
- }
- SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
- String zyid = dateTimeFormat.format(new Date());
- model.addAttribute("zyid", zyid);
- return "gkjcxx/gq/gqadd";
- }
- /**
- * 删除
- */
- @RequestMapping(value = "/delete")
- @ResponseBody
- @RequiresPermissions("gqgl:delete")
- public WebJsonResult delete(Model model, String id) {
- WebJsonResult wr = success();
- try {
- // 子类一并删除
- gqService.logicDelete(id);
- // 如果是市级刪除,省级也刪除
- GqEntity gq = gqService.findOne(id);
- try {
- if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
- GqWebService webService = gqService.getWebService(null);
- webService.delete(id);
- gq.setTbzt(Constants.YES);
- gqService.save(gq);
- }
- } catch (Exception e) {
- gq.setTbzt(Constants.NO);
- gqService.save(gq);
- }
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("删除失败!");
- e.printStackTrace();
- }
- return wr;
- }
- }
|