package com.cxfws.jyrxxgl.service.impl; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; 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.jpa.domain.Specification; import org.springframework.stereotype.Service; import com.cxfws.config.utils.CxfwsUtils; import com.cxfws.jyrxxgl.service.ICgxxService; import com.xt.jygl.common.BaseWebCtl; import com.xt.jygl.gkjcxx.gq.service.GqService; import com.xt.jygl.gkjygl.gkjyr.jyrcg.entity.CgEntity; import com.xt.jygl.gkjygl.gkjyr.jyrcg.service.CgService; import com.xt.jygl.gkjygl.gkjyr.jyrcg.vo.CgVo; import com.xtframe.sec.common.BaseEntity; import com.xtframe.sec.common.QueryService; import com.xtframe.sec.user.dao.UserDao; import com.xtframe.sec.user.entity.UserEntity; import com.xtframe.util.StringUtils; /** * 储罐信息 */ @Service("cgWebService") @WebService(targetNamespace = "http://service.web.jsjty.com/", portName = "cgWebServicePort", serviceName = "cgWebService") public class CgxxService extends BaseWebCtl implements ICgxxService{ @Autowired private QueryService query; @Autowired private CgService cgService; @Resource private WebServiceContext wscontext; @Autowired private UserDao userdao; @Autowired private GqService gqService; /** * 储罐信息列表 */ @Override @WebMethod(operationName = "findCg", action = "http://service.web.jsjty.com/findCg") @WebResult(name = "result", targetNamespace = "http://service.web.jsjty.com/") public String findCg(final String szdid,final String szgkid,final String szgqid,final String cgmc,final String ssjyr) { if (!this.checkUser()){ return BaseWebCtl.NOLOGIN; } Specification spec = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { List list = new ArrayList(); 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(cgmc)) { list.add(cb.like(root.get("cgmc").as(String.class), "%" + cgmc + "%")); } // 经营人只能查看自己企业下的数据,非经营人只能查看自己所在地的数据 String userName=CxfwsUtils.userNameFromHeaderInfo(wscontext); UserEntity userEntity = userdao.findByUname(userName); if (userEntity.getSsjyr()!=null) { list.add(cb.like(root.get("ssjyr").get("id").as(String.class), "%" + getSsjyr().getId() + "%")); } else { In in = cb.in(root.get("szgq").get("id").as(String.class)); List 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[] {})); } }; List cglist = query.findAll(spec, CgEntity.class); JSONArray jsons=JSONArray.fromObject(cglist); return jsons.toString(); } /** * 储罐信息详情 */ @Override public String findOne(String id) { if (!this.checkUser()){ return BaseWebCtl.NOLOGIN; } CgEntity entity = cgService.findOne(id); CgVo vo = new CgVo(); 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.setCgxszw(entity.getCgxs() != null ? entity.getCgxs().getText() : ""); vo.setCgwxzw(entity.getCgwx() != null ? entity.getCgwx().getText() : ""); vo.setCgczzw(entity.getCgcz() != null ? entity.getCgcz().getText() : ""); vo.setWxydjzw(entity.getWxydj() != null ? entity.getWxydj().getText() : ""); vo.setYwfhdzw(entity.getYwfhd() != null ? entity.getYwfhd().getText() : ""); vo.setCgazxszw(entity.getCgazxs() != null ? entity.getCgazxs().getText() : ""); vo.setWzztzw(entity.getWzzt() != null ? entity.getWzzt().getText() : ""); vo.setJlfszw(entity.getJlfs() != null ? entity.getJlfs().getText() : ""); vo.setClfszw(entity.getClfs() != null ? entity.getClfs().getText() : ""); vo.setSfwxpcgzw(entity.getSfwxpcg() != null ? entity.getSfwxpcg().getText() : ""); vo.setTbsjstr(transFormatDate(entity.getTbsj())); vo.setTcsjstr(transFormatDate(entity.getTcsj())); } JSONArray jsons=JSONArray.fromObject(vo); return jsons.toString(); } // 时间格式化 private String transFormatDate(Date d) { if (d == null) { return ""; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(d); } }