123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- package com.cxfws.jyrxxgl.service.impl;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.List;
- import javax.annotation.Resource;
- import javax.jws.WebMethod;
- import javax.jws.WebResult;
- import javax.jws.WebService;
- 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.xml.ws.WebServiceContext;
- import net.sf.json.JSONArray;
- 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.Service;
- import com.cxfws.config.utils.CxfwsUtils;
- import com.cxfws.jyrxxgl.service.ISssbxxService;
- import com.xt.jygl.common.BaseWebCtl;
- import com.xt.jygl.common.Constants;
- import com.xt.jygl.common.GlobalData;
- import com.xt.jygl.gkjcxx.gk.entity.GkEntity;
- import com.xt.jygl.gkjcxx.gq.entity.GqEntity;
- import com.xt.jygl.gkjcxx.gq.service.GqService;
- import com.xt.jygl.gkjcxx.zyq.entity.ZyqEntity;
- import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.entity.GkjyrEntity;
- import com.xt.jygl.gkjygl.gkjyr.sssb.client.SssbWebService;
- import com.xt.jygl.gkjygl.gkjyr.sssb.entity.SssbEntity;
- import com.xt.jygl.gkjygl.gkjyr.sssb.service.SssbService;
- import com.xt.jygl.gkjygl.gkjyr.sssb.vo.SssbVo;
- import com.xt.jygl.gkjygl.gkjyr.xkzxx.entity.XkzglbEntity;
- import com.xt.jygl.gkjygl.gkjyr.xkzxx.service.XkzglbService;
- import com.xtframe.core.base.ctl.WebJsonResult;
- 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.user.dao.UserDao;
- import com.xtframe.sec.user.entity.UserEntity;
- import com.xtframe.util.StringUtils;
- /**
- * 设施设备信息
- */
- @Service("sssbWebService")
- @WebService(targetNamespace = "http://service.web.jsjty.com/", portName = "sssbWebServicePort", serviceName = "sssbWebService")
- public class SssbxxService extends BaseWebCtl implements ISssbxxService{
- @Autowired
- private QueryService query;
- @Autowired
- private SssbService sssbService;
- @Resource
- private WebServiceContext wscontext;
- @Autowired
- private UserDao userdao;
- @Autowired
- private GqService gqService;
- @Autowired
- private XkzglbService xkzglbService;
- /**
- * 根据查询条件查询设施设备信息列表
- */
- @Override
- @WebMethod(operationName = "findSssb", action = "http://service.web.jsjty.com/findSssb")
- @WebResult(name = "result", targetNamespace = "http://service.web.jsjty.com/")
- public String findSssb(int pages, int rows,final String szdid, final String szgkid, final String szgqid, final String jyr, final String ssmc) {
- if (!this.checkUser()){
- return BaseWebCtl.NOLOGIN;
- }
- SimplePageRequest page = new SimplePageRequest(pages, rows);
- Specification<SssbEntity> spec = new Specification<SssbEntity>() {
- @Override
- public Predicate toPredicate(Root<SssbEntity> 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 + "%"));
- }
- 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(jyr)) {
- list.add(cb.like(root.get("ssjyr").get("gkjyr").as(String.class), "%" + jyr + "%"));
- }
- if (StringUtils.isNotEmpty(ssmc)) {
- list.add(cb.like(root.get("ssmc").as(String.class), "%" + ssmc + "%"));
- }
- // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据
- String userName=CxfwsUtils.userNameFromHeaderInfo(wscontext);
- UserEntity userEntity = userdao.findByUnameszd(userName,GlobalData.CITY_CODE);
- if (userEntity.getSsjyr()!=null) {
- 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));
- List<String> gqlist = gqService.findGqListByUserId(userEntity.getId());
- if (gqlist != null && gqlist.size() > 0) {
- for (int i = 0; i < gqlist.size(); i++) {
- in.value(gqlist.get(i));
- }
- list.add(in);
- }
- }
- // 状态为0,9,10,11不显示
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_COPY));
- 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_BGFLAG));
- list.add(cb.notEqual(root.get("recordStatus").as(Integer.class), BaseEntity.RECORE_STATE_ZXFLAG));
- return cb.and(list.toArray(new Predicate[] {}));
- }
- };
- if (page.getPage() < 1) {
- page.setPage(1);
- }
- page.setSort("id");
- page.setOrder("desc");
- Page<SssbEntity> sssblist = query.findAll(spec, toPageRequest(page), SssbEntity.class);
- List<SssbVo> voList = new ArrayList<SssbVo>();
- for (SssbEntity entity : sssblist) {
- SssbVo vo = new SssbVo();
- if (entity != null) {
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setYjfl(entity.getYjfl() != null ? entity.getYjfl().getText() : "");
- vo.setEjfl(entity.getEjfl() != null ? entity.getEjfl().getText() : "");
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setXkzid(entity.getXkzid() != null ? entity.getXkzid() : "");
- vo.setSzzyq(entity.getSzzyq() != null ? entity.getSzzyq().getId() : "");
- vo.setSzzyqzw(entity.getSzzyq() != null ? entity.getSzzyq().getZyqmc() : "");
- vo.setSldw(entity.getSldw() != null ? entity.getSldw().getText() : "");
- voList.add(vo);
- }
- }
- return Object2JsonStr(voList);
- }
- /**
- * 根据id查询设施设备信息详情
- */
- @Override
- public String findOne(String id) {
- if (!this.checkUser()){
- return BaseWebCtl.NOLOGIN;
- }
- SssbEntity entity = sssbService.findOne(id);
- SssbVo vo = new SssbVo();
- if(entity!=null){
- BeanUtils.copyProperties(entity, vo);
- vo.setSzdzw(entity.getSzd() != null ? entity.getSzd().getText() : "");
- vo.setSzgkzw(entity.getSzgk() != null ? entity.getSzgk().getGkmc() : "");
- vo.setSzgqzw(entity.getSzgq() != null ? entity.getSzgq().getGqmc() : "");
- vo.setSsjyrzw(entity.getSsjyr() != null ? entity.getSsjyr().getGkjyr() : "");
- vo.setYjflzw(entity.getYjfl() != null ? entity.getYjfl().getText() : "");
- vo.setEjflzw(entity.getEjfl() != null ? entity.getEjfl().getText() : "");
- vo.setSldwzw(entity.getSldw() != null ? entity.getSldw().getText() : "");
- vo.setSzd(entity.getSzd() != null ? entity.getSzd().getId() : "");
- vo.setSzgk(entity.getSzgk() != null ? entity.getSzgk().getId() : "");
- vo.setSzgq(entity.getSzgq() != null ? entity.getSzgq().getId() : "");
- vo.setSsjyr(entity.getSsjyr() != null ? entity.getSsjyr().getId() : "");
- vo.setYjfl(entity.getYjfl() != null ? entity.getYjfl().getId() : "");
- vo.setEjfl(entity.getEjfl() != null ? entity.getEjfl().getId() : "");
- vo.setSldw(entity.getSldw() != null ? entity.getSldw().getId() : "");
- vo.setSzzyq(entity.getSzzyq() != null ? entity.getSzzyq().getId() : "");
- vo.setSzzyqzw(entity.getSzzyq() != null ? entity.getSzzyq().getZyqmc() : "");
- if (null != entity.getYxq()) {
- vo.setYxqfmt(new SimpleDateFormat("yyyy-MM-dd").format(entity.getYxq()));
- }
- }
- JSONArray jsons=JSONArray.fromObject(vo);
- return jsons.toString();
- }
- @Override
- public String save(String path, SssbEntity code, String szdid, String szgkid, String szgqid, String ssjyrid, String sldwid, String yjflid, String ejflid, String sbszzyqid) {
- // how:如果是新增直接保存,如果更新,先取出数据库中记录,然后更新页面传过来的字段
- // why:这样的话一些在前台无需显示的字段保证不会丢失,同时一个个字段设置有助于bug排查
- WebJsonResult wr = success();
- if (!this.checkUser()){
- wr.setSuccess(false);
- wr.setMessage(BaseWebCtl.NOLOGIN);
- return Object2JsonStr(wr);
- }
- SssbEntity entity = new SssbEntity();
- try {
- if (!StringUtils.isEmpty(code.getId())) {
- entity = sssbService.findOne(code.getId());
- entity.setTbzt(Constants.NO);
- }
- entity.setSsmc(code.getSsmc());
- entity.setGgxh(code.getGgxh());
- entity.setSl(code.getSl());
- entity.setCfcs(code.getCfcs());
- entity.setYxq(code.getYxq());
- entity.setTbr(code.getTbr());
- entity.setLxdh(code.getLxdh());
- entity.setBz(code.getBz());
- entity.setBh(code.getBh());
- if (!StringUtils.isEmpty(sldwid)) {
- CodeEntity sldw = new CodeEntity(sldwid);
- entity.setSldw(sldw);
- }
- if (!StringUtils.isEmpty(yjflid)) {
- CodeEntity yjfl = new CodeEntity(yjflid);
- entity.setYjfl(yjfl);
- }
- if (!StringUtils.isEmpty(ejflid)) {
- CodeEntity ejfl = new CodeEntity(ejflid);
- entity.setEjfl(ejfl);
- }
- if (!StringUtils.isEmpty(sbszzyqid)) {
- ZyqEntity zyq = new ZyqEntity();
- zyq.setId(sbszzyqid);
- entity.setSzzyq(zyq);
- }
- CodeEntity szd = new CodeEntity(szdid);
- entity.setSzd(szd);
- GkEntity szgk = new GkEntity();
- szgk.setId(szgkid);
- entity.setSzgk(szgk);
- GqEntity szgq = new GqEntity();
- szgq.setId(szgqid);
- entity.setSzgq(szgq);
- GkjyrEntity ssjyr = new GkjyrEntity();
- ssjyr.setId(ssjyrid);
- entity.setSsjyr(ssjyr);
- GqEntity gq = gqService.findOne(szgqid);
- entity.setSsgkglbm(gq != null ? gq.getSsgkglbm() : null);
- if (!StringUtils.isEmpty(path) && path.indexOf("bg") > 0) {
- if (path.indexOf("add") > 0) {
- entity.setRecordStatus(BaseEntity.RECORE_STATE_COPY);
- } else {
- entity.setRecordStatus(BaseEntity.RECORE_STATE_BGFLAG);
- }
- }
- sssbService.save(entity);
- wr.setAttr("entity", entity);
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("操作失败!");
- e.printStackTrace();
- }
- return Object2JsonStr(wr);
-
- }
- @Override
- public String delete(String id, String czid) {
- WebJsonResult wr = success();
- if (!this.checkUser()){
- wr.setSuccess(false);
- wr.setMessage(BaseWebCtl.NOLOGIN);
- return Object2JsonStr(wr);
- }
- try {
- if (!StringUtils.isEmpty(czid)) {
- XkzglbEntity xkzglb = xkzglbService.findByCzidAndYwid(czid, id);
- if (xkzglb != null) {
- xkzglbService.delete(xkzglb.getId());
- }
- }
- // 子类一并删除
- sssbService.logicDelete(id);
- // 如果是市级删除,省级也删除
- SssbEntity sssb = sssbService.findOne(id);
- try {
- if (GlobalData.DEPLOY_MODE.equals(Constants.DEPLOY_MODE_CITY) && needWS()) {
- SssbWebService webService = sssbService.getWebService(null);
- webService.delete(id);
- sssb.setTbzt(Constants.YES);
- sssbService.save(sssb);
- }
- } catch (Exception e) {
- sssb.setTbzt(Constants.NO);
- sssbService.save(sssb);
- }
- } catch (Exception e) {
- wr.setSuccess(false);
- wr.setMessage("删除失败!");
- e.printStackTrace();
- }
- return Object2JsonStr(wr);
- }
- }
|