123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761 |
- package com.xt.jygl.gkjcxx.ax.ctl;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- 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.CriteriaBuilder.In;
- import javax.persistence.criteria.CriteriaQuery;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- 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.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
- 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.ax.client.AxWebService;
- import com.xt.jygl.gkjcxx.ax.entity.AxEntity;
- import com.xt.jygl.gkjcxx.ax.service.AxService;
- import com.xt.jygl.gkjcxx.ax.vo.AxVo;
- import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
- import com.xt.jygl.gkjcxx.gk.service.GkService;
- import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
- import com.xt.jygl.gkjcxx.gq.service.GqService;
- import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.entity.GkjyrEntity;
- 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("/ax")
- public class AxCtl extends BaseWebCtl {
- @Autowired
- private SecurityMgr securityMgr;
- @Autowired
- private QueryService query;
- @Autowired
- private AxService axService;
- @Autowired
- private GkService gkService;
- @Autowired
- private GqService gqService;
- @Autowired
- private GkjyrService gkjyrService;
- /**
- * 一览页面
- * @param page 分页
- * @param model
- * @param request
- * @param axmc 岸线名称
- * @param szdid 所在地ID
- * @param szgkid 所在港口ID
- * @param szgqid 所在港区ID
- * @param ssjyr 经营人
- * @param menuid
- * @param lyztid
- * @return
- * @throws JsonProcessingException
- */
- @RequestMapping(value = "/main")
- @RequiresPermissions("ax:main")
- 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 {
- final Map<String, Object> cacheSCmap = CacheSearchCondition.cacheSCmap(request,"ax");
- Specification<AxEntity> spec = new Specification<AxEntity>() {
- // 查询条件
- @Override
- public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> list = new ArrayList<Predicate>();
- if (StringUtils.isNotEmpty(axmc)) {
- list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
- } else if (isGET(request)) {
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, null,"axmc");
- }
- if (StringUtils.isNotEmpty(szdid)) {
- list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
- } else if (isGET(request)) {
- 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)) {
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szgk","szgkid");
- }
- if (StringUtils.isNotEmpty(szgqid)) {
- list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
- } else if (isGET(request)) {
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","szgq","szgqid");
- }
- if (StringUtils.isNotEmpty(ssjyr)) {
- list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
- } else if (isGET(request)) {
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "gkjyr","ssjyr");
- }
- if (StringUtils.isNotEmpty(lyztid)) {
- list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
- } else if (isGET(request)) {
- CacheSearchCondition.predicateList(list, cacheSCmap, root, cb, "id","lyzt","lyztid");
- }
- // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
- 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").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(Integer.class), BaseEntity.RECORD_STATE_DELETE));
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
-
- if(page.getPage() <1){
- page.setPage(SearchCondition.axpage);
- }
- page.setSort("id");
- page.setOrder("desc");
- Page<AxEntity> list = query.findAll(spec, toPageRequest(page), AxEntity.class);
- List<AxVo> voList = new ArrayList<AxVo>();
- for (AxEntity entity : list) {
- AxVo vo = new AxVo();
- if (null != entity) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
- vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
- vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
- vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
- vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
- vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
- vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
- voList.add(vo);
- }
- }
-
- if (isPOST(request)) {
- SearchCondition.axpage=page.getPage();
- //cacheSCmap.put("axpage", page.getPage());
- CacheSearchCondition.putCacheSCmap(request.getParameterMap(), cacheSCmap);
- }
-
- model.addAttribute("list", voList);
- model.addAttribute("axmc", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "axmc"));
- model.addAttribute("szd", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szdid"));
- model.addAttribute("szgk", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgkid"));
- model.addAttribute("szgq", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "szgqid"));
- model.addAttribute("ssjyr", CacheSearchCondition.cacheSCmapVal(cacheSCmap, "ssjyr"));
- model.addAttribute("lyzt",CacheSearchCondition.cacheSCmapVal(cacheSCmap, "lyztid"));
- List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
- model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
- model.addAttribute("menuid", menuid);
- // 翻页共通
- putPageInfo(model, page, list);
- return "gkjcxx/ax/axmain";
- }
- //删除
- @RequestMapping(value = "/delete")
- @RequiresPermissions("ax:delete")
- @ResponseBody
- public WebJsonResult logicdelete(Model model, String id) {
- WebJsonResult wr = success();
- try {
- // 逻辑删除
- axService.logicDelete(id);
- // 如果是市级删除,省级也删除
- AxEntity ax = axService.findOne(id);
- try {
- if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
- AxWebService webService = axService.getWebService(null);
- webService.delete(id);
- ax.setTbzt(Constants.NO);
- axService.save(ax);
- }
- } catch (Exception e) {
- ax.setTbzt(Constants.NO);
- axService.save(ax);
- }
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- //保存
- @RequestMapping(value = "/save")
- @ResponseBody
- @RequiresPermissions("ax:add")
- public WebJsonResult save(Model model, AxEntity code, String szdid, String szgkid, String szgqid, String ssjyrid, String axlxid, String axgnid, String lyztid,String nbaid) {
- // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
- // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
- WebJsonResult wr = success();
- // 必填字段的后台验证
- if (StringUtils.isEmpty(szdid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在地");
- return wr;
- }
- if (StringUtils.isEmpty(szgkid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在港口");
- return wr;
- }
- if (StringUtils.isEmpty(szgqid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所在港区");
- return wr;
- }
- if (StringUtils.isEmpty(ssjyrid)) {
- wr.setSuccess(false);
- wr.setMessage("请选择所属经营人");
- return wr;
- }
- AxEntity axEntity = new AxEntity();
- try {
- if (!StringUtils.isEmpty(code.getId())) {
- // 修改
- axEntity = axService.findOne(code.getId());
- }
- axEntity.setAxcd(code.getAxcd());
- axEntity.setAxmc(code.getAxmc());
- GkEntity szgk = new GkEntity();
- szgk.setId(szgkid);
- axEntity.setSzgk(szgk);
- GqEntity szgq = new GqEntity();
- szgq.setId(szgqid);
- axEntity.setSzgq(szgq);
- GkjyrEntity ssjyr = new GkjyrEntity();
- ssjyr.setId(ssjyrid);
- axEntity.setSsjyr(ssjyr);
- // 非必填字段的验证,如为空则不验证,不为空则验证
- if (!StringUtils.isEmpty(axlxid)) {
- CodeEntity axlx = new CodeEntity(axlxid);
- axEntity.setAxlx(axlx);
- }
- if (!StringUtils.isEmpty(axgnid)) {
- CodeEntity axgn = new CodeEntity(axgnid);
- axEntity.setAxgn(axgn);
- }
- if (!StringUtils.isEmpty(lyztid)) {
- CodeEntity lyzt = new CodeEntity(lyztid);
- axEntity.setLyzt(lyzt);
- }
- if (!StringUtils.isEmpty(nbaid)) {
- CodeEntity nba = new CodeEntity(nbaid);
- axEntity.setNba(nba);
- }
- axEntity.setZyid(code.getZyid());
- axEntity.setJzrq(code.getJzrq());
- axEntity.setAxcd(code.getAxcd());
- axEntity.setQdzb(code.getQdzb());
- axEntity.setZdzb(code.getZdzb());
- axEntity.setAxpb(code.getAxpb());
- axEntity.setBz(code.getBz());
- axEntity.setWaterarea(code.getWaterarea());
- axEntity.setLandarea(code.getLandarea());
- axEntity.setLinelength(code.getLinelength());
- axEntity.setQdzby(code.getQdzby());
- axEntity.setZdzby(code.getZdzby());
- axEntity.setAxwzms(code.getAxwzms());
- GqEntity gq = gqService.findOne(szgqid);
- axEntity.setSsgkglbm(gq != null ? gq.getSsgkglbm() : null);
- CodeEntity szd = new CodeEntity(szdid);
- axEntity.setSzd(szd);
- axService.save(axEntity);
-
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- //编辑
- @RequestMapping(value = "/edit")
- @RequiresPermissions("ax:edit")
- public String edit(Model model, String id) {
- List<CodeEntity> axlxlist = securityMgr.codeService().findValidCodesByGroupCode("AXLX");
- model.addAttribute("axlxlist", JSONArray.fromObject(axlxlist, config).toString());
- List<CodeEntity> axgnlist = securityMgr.codeService().findValidCodesByGroupCode("AXGN");
- model.addAttribute("axgnlist", JSONArray.fromObject(axgnlist, config).toString());
- List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
- model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
- List<CodeEntity> nbalist = securityMgr.codeService().findValidCodesByGroupCode("NBA");
- model.addAttribute("nbalist",JSONArray.fromObject(nbalist,config).toString());
- AxEntity entity = axService.findOne(id);
- AxVo vo = new AxVo();
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
- vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
- vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
- vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
- vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
- vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
- vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
-
- if(StringUtils.isEmpty(vo.getZyid())){
- SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
- String zyid = dateTimeFormat.format(new Date());
- vo.setZyid(zyid);
- }
- model.addAttribute("record", vo);
- model.addAttribute("jyr", getSsjyr() != null ? JSONObject.fromObject(getSsjyr()).toString() : null);
- return "gkjcxx/ax/axedit";
- }
- //查看
- @RequestMapping(value = "/view")
- @RequiresPermissions("ax:main")
- public String view(Model model, String id) {
- AxVo vo = new AxVo();
- AxEntity entity = axService.findOne(id);
- if (entity != null) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
- vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
- vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
- vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
-
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
- vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
- vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
- vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
- if (null != entity.getJzrq()) {
- vo.setJzrqfmt(new SimpleDateFormat("yyyy-MM-dd").format(entity.getJzrq()));
- }
- }
- model.addAttribute("record", vo);
- return "gkjcxx/ax/axview";
- }
- //新增
- @RequestMapping(value = "/add")
- @RequiresPermissions("ax:add")
- public String add(Model model) {
- List<CodeEntity> axlxlist = securityMgr.codeService().findValidCodesByGroupCode("AXLX");
- model.addAttribute("axlxlist", JSONArray.fromObject(axlxlist, config).toString());
- List<CodeEntity> axgnlist = securityMgr.codeService().findValidCodesByGroupCode("AXGN");
- model.addAttribute("axgnlist", JSONArray.fromObject(axgnlist, config).toString());
- List<CodeEntity> lyztlist = securityMgr.codeService().findValidCodesByGroupCode("AXLYZT");
- model.addAttribute("lyztlist", JSONArray.fromObject(lyztlist, config).toString());
- List<CodeEntity> nbalist = securityMgr.codeService().findValidCodesByGroupCode("NBA");
- model.addAttribute("nbalist",JSONArray.fromObject(nbalist, config).toString());
- model.addAttribute("jyr", getSsjyr() != null ? JSONObject.fromObject(getSsjyr()).toString() : null);
- 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/ax/axadd";
- }
- /**
- * 导出全部数据到excel
- *
- * @param response
- * @return
- */
- @RequestMapping(value = "/exportExcelAll")
- public String exportExcelAll(HttpServletResponse response, final String axmc, final String szdid, final String szgkid, final String szgqid, final String ssjyr, final String lyztid) {
- Specification<AxEntity> spec = new Specification<AxEntity>() {
- // 查询条件
- @Override
- public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> list = new ArrayList<Predicate>();
- if (StringUtils.isNotEmpty(axmc)) {
- list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
- }
- if (StringUtils.isNotEmpty(szdid)) {
- list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
- }
- if (StringUtils.isNotEmpty(szgkid)) {
- list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
- }
- if (StringUtils.isNotEmpty(szgqid)) {
- list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
- }
- if (StringUtils.isNotEmpty(ssjyr)) {
- list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
- }
- if (StringUtils.isNotEmpty(lyztid)) {
- list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
- }
- // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
- 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").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(Integer.class), BaseEntity.RECORD_STATE_DELETE));
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
- List<AxEntity> list = query.findAll(spec, AxEntity.class);
- List<AxVo> voList = new ArrayList<AxVo>();
- for (AxEntity entity : list) {
- AxVo vo = new AxVo();
- if (null != entity) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
- vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
- vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
- vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
-
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
- vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
- vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
- vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
- voList.add(vo);
- }
- }
- response.setContentType("application/binary;charset=iso-8859-1");
- try {
- ServletOutputStream outputStream = response.getOutputStream();
- String fileName = new String(("岸线信息全部").getBytes(), "iso-8859-1");
- response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
- String[] titles = { "序号", "岸线名称", "所在港口", "所在港区", "所属经营人", "利用状态" };
- axService.exportExcelAll(voList, titles, outputStream);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 导出当前页数据到excel
- *
- * @param response
- * @param axmc
- * @param szdid
- * @param szgkid
- * @param szgqid
- * @param ssjyr
- * @return
- */
- @RequestMapping(value = "/exportExcelthisPage")
- 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) {
- Specification<AxEntity> spec = new Specification<AxEntity>() {
- @Override
- public Predicate toPredicate(Root<AxEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> list = new ArrayList<Predicate>();
-
- if (StringUtils.isNotEmpty(axmc)) {
- list.add(cb.like(root.get("axmc").as(String.class), "%" + axmc + "%"));
- }
- if (StringUtils.isNotEmpty(szdid)) {
- list.add(cb.like(root.get("szd").get("id").as(String.class), "%" + szdid + "%"));
- }
- if (StringUtils.isNotEmpty(szgkid)) {
- list.add(cb.like(root.get("szgk").get("id").as(String.class), "%" + szgkid + "%"));
- }
- if (StringUtils.isNotEmpty(szgqid)) {
- list.add(cb.like(root.get("szgq").get("id").as(String.class), "%" + szgqid + "%"));
- }
- if (StringUtils.isNotEmpty(ssjyr)) {
- list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + ssjyr + "%"));
- }
- if (StringUtils.isNotEmpty(lyztid)) {
- list.add(cb.like(root.get("lyzt").get("id").as(String.class), "%" + lyztid + "%"));
- }
- // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
- 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").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(Integer.class), BaseEntity.RECORD_STATE_DELETE));
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
- page.setPage(pageNum);
- page.setRows(pageSize);
- page.setSort("id");
- page.setOrder("desc");
- Page<AxEntity> list = query.findAll(spec, toPageRequest(page), AxEntity.class);
- List<AxVo> voList = new ArrayList<AxVo>();
- for (AxEntity entity : list) {
- AxVo vo = new AxVo();
- if (null != entity) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setAxlxzw(entity.getAxlx() != null ? entity.getAxlx().getText() : "");
- vo.setAxgnzw(entity.getAxgn() != null ? entity.getAxgn().getText() : "");
- vo.setLyztzw(entity.getLyzt() != null ? entity.getLyzt().getText() : "");
- vo.setNbazw(entity.getNba() != null?entity.getNba().getText() : "");
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setAxlx(entity.getAxlx() != null ? entity.getAxlx().getId() : "");
- vo.setAxgn(entity.getAxgn() != null ? entity.getAxgn().getId() : "");
- vo.setLyzt(entity.getLyzt() != null ? entity.getLyzt().getId() : "");
- vo.setNba(entity.getNba() != null?entity.getNba().getId() : "");
- voList.add(vo);
- }
- }
- response.setContentType("application/binary;charset=iso-8859-1");
- try {
- ServletOutputStream outputStream = response.getOutputStream();
- String fileName = new String(("岸线信息单页").getBytes(), "iso-8859-1");
- response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");// 组装附件名称和格式
- String[] titles = { "序号", "岸线名称", "所在港口", "所在港区", "所属经营人", "利用状态" };
- axService.exportExcelthisPage(voList, titles, outputStream);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 打开批量导入页面
- *
- * @param model
- * @return
- */
- @RequestMapping(value = "/inputAll")
- public String inputAll(Model model) {
- return "gkjcxx/ax/inputAll";
- }
- /**
- * 批量导入excel数据
- *
- * @param model
- * @return
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/report")
- @ResponseBody
- public WebJsonResult report(@RequestParam MultipartFile file) throws IOException {
- WebJsonResult wr = success();
- try {
- Map<String, Object> map = axService.readReport(file.getInputStream());
- if (((List<String>) map.get("error")).size() > 0) {
- List<String> errorList = (List<String>) map.get("error");
- for (int j = 0; j < errorList.size(); j++) {
- File file1 = new File("D:/bug.txt");
- if (!file1.exists()) {
- file1.createNewFile();
- }
- FileOutputStream fos = new FileOutputStream("D:/bug.txt", true);
- fos.write(errorList.get(j).getBytes());
- fos.flush();
- fos.close();
- }
- wr.setMessage("导入文件有错误,请根据操作日志修改正确后重新导入!");
- } else {
- List<AxEntity> axList = (List<AxEntity>) map.get("axList");
- for (int i = 0; i < axList.size(); i++) {
- axService.save(axList.get(i));
- }
- wr.setMessage("数据导入成功!");
- }
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return wr;
- }
- /**
- * 下载错误日志
- *
- * @param request
- * @param response
- * @throws UnsupportedEncodingException
- */
- @RequestMapping(value = "/downLoadTxt")
- public void DownLoadTxt(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
- response.setCharacterEncoding("utf-8");
- response.setContentType("multipart/form-data");
- String fileName = "错误日志.txt";
- if ("FF".equals(getBrowser(request))) {
- // 针对火狐浏览器处理方式不一样了
- fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
- } else {
- fileName = URLEncoder.encode(fileName, "UTF-8");
- }
- response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
- File file = new File("D:/bug.txt");
- try {
- FileReader reader = new FileReader(file);
- BufferedReader br = new BufferedReader(reader);
- String line = br.readLine();
- while (line != null) {
- response.getOutputStream().write(line.getBytes());
- line = br.readLine();
- }
- br.close();
- file.delete();
- return;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 服务器端判断客户端浏览器类型(IE/FF/SF)
- *
- * @param request
- * @return
- */
- public static String getBrowser(HttpServletRequest request) {
- String UserAgent = request.getHeader("USER-AGENT").toLowerCase();
- if (UserAgent != null) {
- if (UserAgent.indexOf("msie") >= 0)
- return "IE";
- if (UserAgent.indexOf("firefox") >= 0)
- return "FF";
- if (UserAgent.indexOf("safari") >= 0)
- return "SF";
- }
- return null;
- }
- /***
- * 解决js传入参数乱码
- *
- * @param str
- * @return
- */
- static String enCodeStr(String str) {
- if (str == null) {
- str = "";
- }
- try {
- return new String(str.getBytes("iso-8859-1"), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
|