Commit c571829b authored by tangwei's avatar tangwei

平台升级调整

parent c06f6cad
......@@ -8,17 +8,17 @@
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeSafety3DRoot</artifactId>
<version>1.1.0</version>
<version>3.0.0</version>
</parent>
<dependencies>
<!-- 基础jar -->
<dependency>
<!-- 基础jar -->
<!-- <dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>AmosOPService</artifactId>
<version>${YeeOp.version}</version>
</dependency>
<!-- 安全模块jar -->
</dependency> -->
<!--安全模块jar
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>amos-authtoken</artifactId>
......@@ -33,7 +33,29 @@
<artifactId>spring-security-config</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency> -->
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-feign-privilege</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-feign-systemctl</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-feign</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -5,18 +5,22 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.yeejoin.amos.op.core.common.query.DaoCriteria;
import com.yeejoin.amos.op.core.common.query.QueryOperatorEnum;
import com.yeejoin.amos.op.core.common.request.CommonRequest;
import com.yeejoin.amos.op.core.util.StringUtil;
import com.yeejoin.amos.security.authorization.Authorization;
import com.yeejoin.amos.security.context.CurrentAuthentication;
import com.yeejoin.amos.security.entity.Company;
import com.yeejoin.amos.security.entity.Department;
import com.yeejoin.amos.security.entity.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.safety.business.vo.CommonRequest;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.business.vo.StringUtil;
import springfox.documentation.annotations.ApiIgnore;
......@@ -28,13 +32,101 @@ import springfox.documentation.annotations.ApiIgnore;
@ApiIgnore
@RestController
@RequestMapping("/base")
@Authorization
//@Authorization
public class BaseController {
@Autowired
protected HttpServletRequest request;
@Autowired
private RedisTemplate<String, String> redisTemplate;
protected String getToken() {
String authToken = request.getHeader("token");
if (authToken == null) {
authToken = request.getHeader("X-Access-Token");
}
return authToken;
}
protected String getProduct() {
String authToken = request.getHeader("product");
if (authToken == null) {
authToken = request.getParameter("product");
}
return authToken;
}
protected String getAppKey() {
String authToken = request.getHeader("appKey");
if (authToken == null) {
authToken = request.getParameter("appKey");
}
return authToken;
}
//redi缓存选择的用户信息
private String buildKey(String userId, String token) {
//return "region_" + userId + "_" + token.substring(0, token.indexOf('_', 1));
return "region_" + userId + "_" + token;
}
protected void saveSelectedOrgInfo(ReginParams reginParams) {
redisTemplate.opsForValue().set(buildKey(getUserId(), getToken()), JSONObject.toJSONString(reginParams));
}
protected ReginParams getSelectedOrgInfo() {
return JSON.parseObject(redisTemplate.opsForValue().get(buildKey(getUserId(), getToken())), ReginParams.class);
}
/**
* 当前登录用户信息
*/
protected AgencyUserModel getUserInfo() {
AgencyUserModel userModel=null;
if(getToken()!=null){
RequestContext.setToken(getToken());
RequestContext.setProduct(getProduct());
RequestContext.setAppKey(getAppKey());
FeignClientResult feignClientResult;
try {
feignClientResult = Privilege.agencyUserClient.getme();
userModel = (AgencyUserModel) feignClientResult.getResult();
} catch (InnerInvokException e) {
e.printStackTrace();
}
}
return userModel;
// return CurrentAuthentication.getAuthenticatedUserThreadLocal();
}
protected String getUserId()
{
String userId = null;
if (getUserInfo() != null)
{
userId = getUserInfo().getUserId();
}
return userId;
}
/**
* 获取最大数据位置(分页)
*
......@@ -60,51 +152,27 @@ public class BaseController {
}
return page.getPageNumber() * page.getPageSize();
}
/**
* 当前登录用户Id
*/
protected Long getUserId()
{
Long userId = null;
if (getUserInfo() != null)
{
userId = getUserInfo().getId();
}
return userId;
}
/**
* 当前登录用户信息
*/
protected User getUserInfo()
{
return CurrentAuthentication.getAuthenticatedUserThreadLocal();
}
protected String getToken() {
/* Get token from header */
String authToken = request.getHeader("X-Access-Token");
/* If token not found get it from request parameter */
if (authToken == null)
{
authToken = request.getParameter("token");
}
return authToken;
}
/**
* 获取当前用户所属公司名称
* @return
*/
protected String getCurrentCompanyNameOfUser(){
return getUserInfo().getCompany().getCompanyName();
}
protected String getCurrentCompanyNameOfUser() {
if (getUserInfo() == null) {
return "";
}
return getSelectedOrgInfo().getCompany().getCompanyName();
}
/**
* 获取当前用户所属部门名称
* @return
*/
protected String getCurrentDepartmentNameOfUser(){
return getUserInfo().getDepartment().getDepartmentName();
return getSelectedOrgInfo().getDepartment().getDepartmentName();
}
protected String getCurrentDepartmentNameOfUsercode(){
return getSelectedOrgInfo().getDepartment().getDeptOrgCode();
}
/**
*
......@@ -118,11 +186,15 @@ public class BaseController {
*/
protected String buildCurrentCompCodeOfUser()
{
/**
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
return company.getCompCode();
ReginParams reginParams =getSelectedOrgInfo();
if (reginParams == null) {
return null;
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getOrgCode();
}
return null;
}
/**
*
......@@ -181,8 +253,7 @@ public class BaseController {
/**
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
String companyCode = company.getCompCode();
String companyCode = buildCurrentCompCodeOfUser();
//添加所属公司的过滤条件
DaoCriteria daoCriteria = new DaoCriteria();
daoCriteria.setPropertyName("orgCode");
......@@ -211,8 +282,8 @@ public class BaseController {
/**
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
String companyCode = company.getCompCode();
//Company company = getUserInfo().getCompany();
String companyCode = buildCurrentCompCodeOfUser();
//添加所属公司的过滤条件
DaoCriteria daoCriteria = new DaoCriteria();
daoCriteria.setPropertyName("orgCode");
......@@ -238,18 +309,20 @@ public class BaseController {
/**
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
orgCode.append(company.getCompCode());
//Company company = getUserInfo().getCompany();
String companyCode = buildCurrentCompCodeOfUser();
orgCode.append(companyCode);
/**
* 当前用户所属部门
*/
Department department = getUserInfo().getDepartment();
//如果所属部门为null,则表示该用户为公司级用户
if (department != null)
{
// Department department = getUserInfo().getDepartment();
// //如果所属部门为null,则表示该用户为公司级用户
// if (department != null)
// {
String DepmCode=getCurrentDepartmentNameOfUsercode();
orgCode.append("-");
orgCode.append(department.getDepmCode());
}
orgCode.append(DepmCode);
// }
return orgCode.toString();
}
/**
......@@ -270,8 +343,9 @@ public class BaseController {
/**
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
String companyCode = company.getCompCode();
// Company company = getUserInfo().getCompany();
// String companyCode = company.getCompCode();
String companyCode = buildCurrentCompCodeOfUser();
//添加子公司下的过滤条件
DaoCriteria childCompDaoCriteria = new DaoCriteria();
childCompDaoCriteria.setPropertyName("orgCode");
......@@ -282,10 +356,11 @@ public class BaseController {
*
* 当前用户所属部门
*/
Department department = getUserInfo().getDepartment();
if (department != null)//部门用户,添加所属部门及子部门的过滤条件
//Department department = getUserInfo().getDepartment();
String depmCode=getCurrentDepartmentNameOfUsercode();
if (depmCode != null)//部门用户,添加所属部门及子部门的过滤条件
{
String depmCode = department.getDepmCode();
//String depmCode = department.getDepmCode();
//添加所属部门的过滤条件
DaoCriteria depmDaoCriteria = new DaoCriteria();
depmDaoCriteria.setPropertyName("orgCode");
......@@ -334,16 +409,19 @@ public class BaseController {
* 当前用户所属公司
*/
Company company = getUserInfo().getCompany();
String companyCode = company.getCompCode();
// Company company = getUserInfo().getCompany();
// String companyCode = company.getCompCode();
String companyCode = buildCurrentCompCodeOfUser();
/**
* 当前用户所属部门
*/
Department department = getUserInfo().getDepartment();
if (department != null)//部门用户,添加所属部门的过滤条件
//Department department = getUserInfo().getDepartment();
String depmCode=getCurrentDepartmentNameOfUsercode();
if (depmCode != null)//部门用户,添加所属部门的过滤条件
{
String depmCode = department.getDepmCode();
//String depmCode = department.getDepmCode();
//添加所属部门的过滤条件
DaoCriteria depmDaoCriteria = new DaoCriteria();
depmDaoCriteria.setPropertyName("orgCode");
......@@ -402,7 +480,7 @@ public class BaseController {
criteria.setValue(query.getValue());
// }
if (query.getType() == null || query.getType()==0)
if (query.getType() == null || query.getType().equals(""))
{
criteria.setOperator(QueryOperatorEnum.EQUAL.getName());
}else
......
......@@ -9,20 +9,18 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.op.core.common.query.CommonPageable;
import com.yeejoin.amos.op.core.common.query.DaoCriteria;
import com.yeejoin.amos.op.core.common.query.QueryOperatorEnum;
import com.yeejoin.amos.op.core.common.request.CommonRequest;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.CommonResponseUtil;
import com.yeejoin.amos.safety.business.service.INodeLogViewService;
import com.yeejoin.amos.safety.business.vo.CommonPageable;
import com.yeejoin.amos.safety.business.vo.CommonRequest;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import com.yeejoin.amos.safety.business.vo.CommonResponseUtil;
import com.yeejoin.amos.safety.business.vo.CompanyBo;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.DepartmentBo;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.common.cache.CurUserCompanyCache;
import com.yeejoin.amos.safety.common.entity.NodeToipLogView;
import com.yeejoin.amos.security.entity.Company;
import com.yeejoin.amos.security.entity.Department;
import com.yeejoin.amos.security.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -50,32 +48,33 @@ public class NodeLogViewController extends BaseController
@ApiParam(value = "分页参数", required = true) CommonPageable commonPageable)
{
List<DaoCriteria> daoCriterias = buildDaoCriterias(queryRequests);
User currUser = getUserInfo();
if (currUser != null)
{
Department department = currUser.getDepartment();
if (department != null)//部门用户
{
//通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}else
{
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}
}
}
daoCriterias = buildViewDaoCriteria(daoCriterias);
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Department department = currUser.getDepartment();
// if (department != null)//部门用户
// {
// //通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }else
// {
// String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }
// }
// }
Sort sort = new Sort(Sort.Direction.DESC,"time");
commonPageable.setSort(sort);
Page<NodeToipLogView> toipLogs = nodeLogViewService.findAll(daoCriterias, commonPageable);
......@@ -91,12 +90,12 @@ public class NodeLogViewController extends BaseController
*/
private List<DaoCriteria> buildViewDaoCriteria(List<DaoCriteria> daoCriterias)
{
User currUser = getUserInfo();
ReginParams currUser = getSelectedOrgInfo();
if (currUser != null)
{
Company company = currUser.getCompany();
Department department = currUser.getDepartment();
String compCode = company.getCompCode();
CompanyBo company = currUser.getCompany();
DepartmentBo department = currUser.getDepartment();
Long compCode = company.getCompanyOrgCode();
if (department == null)
{
//单位用户,查询本单位及子单位下所有部门
......@@ -108,7 +107,7 @@ public class NodeLogViewController extends BaseController
}else
{
//部门用户,查询当前部门
String orgCode = company.getCompCode()+"-"+department.getDepmCode();
String orgCode = company.getCompanyOrgCode()+"-"+department.getDeptOrgCode();
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), orgCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), orgCode+",%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+orgCode+",%"));
......
package com.yeejoin.amos.safety.business.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
......@@ -9,20 +8,18 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.op.core.common.query.CommonPageable;
import com.yeejoin.amos.op.core.common.query.DaoCriteria;
import com.yeejoin.amos.op.core.common.query.QueryOperatorEnum;
import com.yeejoin.amos.op.core.common.request.CommonRequest;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.CommonResponseUtil;
import com.yeejoin.amos.safety.business.service.INodeMsgViewService;
import com.yeejoin.amos.safety.business.vo.CommonPageable;
import com.yeejoin.amos.safety.business.vo.CommonRequest;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import com.yeejoin.amos.safety.business.vo.CommonResponseUtil;
import com.yeejoin.amos.safety.business.vo.CompanyBo;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.DepartmentBo;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.common.cache.CurUserCompanyCache;
import com.yeejoin.amos.safety.common.entity.NodeMessageView;
import com.yeejoin.amos.security.entity.Company;
import com.yeejoin.amos.security.entity.Department;
import com.yeejoin.amos.security.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -51,32 +48,33 @@ public class NodeMsgViewController extends BaseController
@ApiParam(value = "分页参数", required = true) CommonPageable commonPageable)
{
List<DaoCriteria> daoCriterias = buildDaoCriterias(queryRequests);
User currUser = getUserInfo();
if (currUser != null)
{
Department department = currUser.getDepartment();
if (department != null)//部门用户
{
//通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}else
{
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}
}
}
daoCriterias = buildViewDaoCriteria(daoCriterias);
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Department department = currUser.getDepartment();
// if (department != null)//部门用户
// {
// //通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }else
// {
// String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }
// }
// }
Sort sort = new Sort(Sort.Direction.DESC,"time");
commonPageable.setSort(sort);
Page<NodeMessageView> messages = nodeMsgViewService.findAll(daoCriterias, commonPageable);
......@@ -93,12 +91,19 @@ public class NodeMsgViewController extends BaseController
*/
private List<DaoCriteria> buildViewDaoCriteria(List<DaoCriteria> daoCriterias)
{
User currUser = getUserInfo();
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Company company = currUser.getCompany();
// Department department = currUser.getDepartment();
// String compCode = company.getCompCode();
// if (department == null)
ReginParams currUser = getSelectedOrgInfo();
if (currUser != null)
{
Company company = currUser.getCompany();
Department department = currUser.getDepartment();
String compCode = company.getCompCode();
CompanyBo company = currUser.getCompany();
DepartmentBo department = currUser.getDepartment();
Long compCode = company.getCompanyOrgCode();
if (department == null)
{
//单位用户,查询本单位及子单位下所有部门
......@@ -110,7 +115,7 @@ public class NodeMsgViewController extends BaseController
}else
{
//部门用户,查询当前部门
String orgCode = company.getCompCode()+"-"+department.getDepmCode();
String orgCode = company.getCompanyOrgCode()+"-"+department.getDeptOrgCode();
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), orgCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), orgCode+",%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+orgCode+",%"));
......
......@@ -11,10 +11,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.CommonResponseUtil;
import com.yeejoin.amos.op.core.util.JSONUtil;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.safety.business.service.INode3DVoService;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import com.yeejoin.amos.safety.business.vo.CommonResponseUtil;
import com.yeejoin.amos.safety.business.vo.JSONUtil;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.business.websocket.View3DWebSocket;
import com.yeejoin.amos.safety.common.cache.CurUserCompanyCache;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
......@@ -24,10 +26,7 @@ import com.yeejoin.amos.safety.common.entity.dto.PatrolTaskDTO;
import com.yeejoin.amos.safety.common.enums.CheckStateEnum;
import com.yeejoin.amos.safety.common.enums.View3DNodeType;
import com.yeejoin.amos.safety.common.view.View3DHandler;
import com.yeejoin.amos.security.authorization.Authorization;
import com.yeejoin.amos.security.common.remote.RemoteSecurityServer;
import com.yeejoin.amos.security.entity.User;
import com.yeejoin.amos.safety.core.remote.service.RemoteSecurityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -51,7 +50,7 @@ public class PatrolController extends BaseController
private INode3DVoService node3DVoService;
@Autowired
private RemoteSecurityServer remoteSecurityServer;
private RemoteSecurityService remoteSecurityServer;
private static final Logger logger = Logger.getLogger(PatrolController.class);
/**
......@@ -65,7 +64,7 @@ public class PatrolController extends BaseController
*/
@PostMapping(value = "/check",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "新增巡检记录信息", notes = "新增巡检记录信息")
@Authorization(ingore = true)
//@Authorization(ingore = true)
public CommonResponse addXJCheck(
@ApiParam(value = "巡检记录信息", required = true) @RequestBody List<PatrolCheckDTO> patrolCheckDTOs)
{
......@@ -109,11 +108,11 @@ public class PatrolController extends BaseController
if (perNode3dVos == null || perNode3dVos.size() == 0)
{
//用户无对应的3D节点,则进行新增
User user = remoteSecurityServer.getUserbyId(String.valueOf(riskPoint.getUserID()));
AgencyUserModel user= remoteSecurityServer.getUserById( getToken(), getProduct(), getAppKey(),String.valueOf(riskPoint.getUserID()));
perNode3dVo = new Node3DVo();
perNode3dVo.setDisplayName(user.getName());
perNode3dVo.setDisplayName(user.getUserName());
perNode3dVo.setType(View3DNodeType.PERSON.getName());
perNode3dVo.setOid(String.valueOf(user.getId()));
perNode3dVo.setOid(String.valueOf(user.getUserId()));
}else{
perNode3dVo = perNode3dVos.get(0);
}
......@@ -150,7 +149,7 @@ public class PatrolController extends BaseController
*/
@PostMapping(value = "/task",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "新增巡检任务信息", notes = "新增巡检任务信息")
@Authorization(ingore = true)
//@Authorization(ingore = true)
public CommonResponse addXJTask(
@ApiParam(value = "巡检记录信息", required = true) @RequestBody List<PatrolTaskDTO> patrolTaskDTOs)
{
......@@ -192,10 +191,11 @@ public class PatrolController extends BaseController
@PostMapping(value = "/save/curCompany/{orgCode}",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "保存当前登陆用户选择单位", notes = "保存当前登陆用户选择单位")
public CommonResponse saveCurrCompany(
@ApiParam(value = "当前登陆用户所选单位信息", required = true) @PathVariable String orgCode)
@ApiParam(value = "当前登陆用户所选单位信息", required = true) @RequestBody ReginParams reginParams)
{
CurUserCompanyCache.getInstance().putCurCompanyMap(getUserId(), getToken(), orgCode);
return CommonResponseUtil.success();
//CurUserCompanyCache.getInstance().putCurCompanyMap(getUserId(), getToken(), orgCode);
this.saveSelectedOrgInfo(reginParams);
return CommonResponseUtil.success();
}
/**
*
......
......@@ -19,20 +19,22 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.op.core.common.query.CommonPageable;
import com.yeejoin.amos.op.core.common.query.DaoCriteria;
import com.yeejoin.amos.op.core.common.query.QueryOperatorEnum;
import com.yeejoin.amos.op.core.common.request.CommonRequest;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.CommonResponseUtil;
import com.yeejoin.amos.op.core.util.JSONUtil;
import com.yeejoin.amos.op.core.util.StringUtil;
import com.yeejoin.amos.safety.business.response.PatrolUserRespone;
import com.yeejoin.amos.safety.business.response.PointInfoSyn3DRespone;
import com.yeejoin.amos.safety.business.response.RouteResponse;
import com.yeejoin.amos.safety.business.service.ILink3DVoService;
import com.yeejoin.amos.safety.business.service.INode3DVoService;
import com.yeejoin.amos.safety.business.vo.CommonPageable;
import com.yeejoin.amos.safety.business.vo.CommonRequest;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import com.yeejoin.amos.safety.business.vo.CommonResponseUtil;
import com.yeejoin.amos.safety.business.vo.CompanyBo;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.DepartmentBo;
import com.yeejoin.amos.safety.business.vo.JSONUtil;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.business.vo.StringUtil;
import com.yeejoin.amos.safety.common.cache.CurUserCompanyCache;
import com.yeejoin.amos.safety.common.entity.Link3DVo;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
......@@ -40,12 +42,7 @@ import com.yeejoin.amos.safety.common.entity.dto.CoordDTO;
import com.yeejoin.amos.safety.common.enums.CheckStateEnum;
import com.yeejoin.amos.safety.common.enums.View3DNodeType;
import com.yeejoin.amos.safety.common.view.View3DHandler;
import com.yeejoin.amos.safety.core.remote.service.RemotePatrolServer;
import com.yeejoin.amos.security.authorization.Authorization;
import com.yeejoin.amos.security.entity.Company;
import com.yeejoin.amos.security.entity.Department;
import com.yeejoin.amos.security.entity.User;
import com.yeejoin.amos.safety.core.remote.service.AmosBankPatrol;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -71,7 +68,7 @@ public class View3DController extends BaseController
private ILink3DVoService link3DVoService;
@Autowired
private RemotePatrolServer remotePatrolServer;
private AmosBankPatrol remotePatrolServer;
private static final Logger logger = Logger.getLogger(View3DController.class);
/**
......@@ -91,33 +88,35 @@ public class View3DController extends BaseController
List<Node3DVo> node3DVos = null;
boolean isAll = true;//是否查询所有与节点
List<DaoCriteria> daoCriterias = new ArrayList<>();
User currUser = getUserInfo();
if (currUser != null)
{
Department department = currUser.getDepartment();
if (department != null)//部门用户
{
//通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}else //单位用户
{
//获取当前用户所选单位
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}
}
}
daoCriterias = buildViewDaoCriteria(daoCriterias);
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Department department = currUser.getDepartment();
// if (department != null)//部门用户
// {
// //通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }else //单位用户
// {
// //获取当前用户所选单位
// String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }
// }
// }
if (StringUtil.isNotEmpty(type))
{
//查询节点类型对应的节点
......@@ -171,32 +170,34 @@ public class View3DController extends BaseController
public CommonResponse initViewLink()
{
List<DaoCriteria> daoCriterias = new ArrayList<>();
User currUser = getUserInfo();
if (currUser != null)
{
Department department = currUser.getDepartment();
if (department != null)//部门用户
{
//通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}else
{
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}
}
}
daoCriterias = buildViewDaoCriteria(daoCriterias);
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Department department = currUser.getDepartment();
// if (department != null)//部门用户
// {
// //通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }else
// {
// String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }
// }
// }
List<Link3DVo> linkVos = link3DVoService.findAll(daoCriterias);
List<Link3DVo> link3DVosfilter = View3DHandler.getInstance()
.linkDatafilter(linkVos); //进行数据过滤
......@@ -214,7 +215,9 @@ public class View3DController extends BaseController
Map<String, Object> patrolInfoMap = null;
if (type.equals(View3DNodeType.RISK.getName()))
{
Object object = remotePatrolServer.getPatrolInfo(id, getToken());
Map<String, String> map = new HashMap<String, String>();
map.put("pointID", id);
Object object = remotePatrolServer.getPatrolInfo(map);
LinkedHashMap<String, Object> patrolInfo = (LinkedHashMap<String, Object>)object;
patrolInfoMap = View3DHandler.getInstance().buildPatrolInfo(patrolInfo);
System.out.println(object);
......@@ -262,32 +265,33 @@ public class View3DController extends BaseController
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+orgCodeFilter));
}else
{
User currUser = getUserInfo();
if (currUser != null)
{
Department department = currUser.getDepartment();
if (department != null)//部门用户
{
//通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}else
{
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
daoCriterias = buildViewDaoCriteria(daoCriterias);
}
}
}
daoCriterias = buildViewDaoCriteria(daoCriterias);
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Department department = currUser.getDepartment();
// if (department != null)//部门用户
// {
// //通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }else
// {
// String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), compCode));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"*%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), compCode+"-%"));
// daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+compCode+"-%"));
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// daoCriterias = buildViewDaoCriteria(daoCriterias);
// }
// }
// }
}
queryDaoCriterias.addAll(daoCriterias);
Page<Link3DVo> searchLinkVos = link3DVoService.findAll(queryDaoCriterias, commonPageable);
......@@ -318,7 +322,10 @@ public class View3DController extends BaseController
}
if (routeIds.size() > 0)
{
Object object = remotePatrolServer.getPointsByRouteId(routeIds, getToken());
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("routeIDs", routeIds);
Object object = remotePatrolServer.getPointsByRouteId(map);
if (object != null)
{
LinkedHashMap<String, Object> rountPointIds = (LinkedHashMap<String, Object>) object;
......@@ -380,7 +387,9 @@ public class View3DController extends BaseController
*/
List<String> routeIds = new ArrayList<>();
routeIds.add(link3DVo.getOid());
Object object = remotePatrolServer.getPointsByRouteId(routeIds, getToken());
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("routeIDs", routeIds);
Object object = remotePatrolServer.getPointsByRouteId(map);
if (object != null)
{
LinkedHashMap<String, Object> rountPointIds = (LinkedHashMap<String, Object>) object;
......@@ -419,7 +428,7 @@ public class View3DController extends BaseController
@SuppressWarnings("unchecked")
@PostMapping(value = "/synchronous",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "同步巡检点和巡检线路对应的3D视图元素", notes = "同步巡检点和巡检线路对应的3D视图元素")
@Authorization(ingore = true)
//@Authorization(ingore = true)
public CommonResponse synchronousPatrolData()
{
Object object = remotePatrolServer.initViewNode();
......@@ -600,7 +609,7 @@ public class View3DController extends BaseController
*/
@PostMapping(value = "/synchronous/points",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "同步巡检点对应的3D视图元素", notes = "同步巡检点对应的3D视图元素")
@Authorization(ingore = true)
//@Authorization(ingore = true)
public CommonResponse synchronousPatrolpoints(
@ApiParam(value = "巡检点信息", required = true) @RequestBody List<PointInfoSyn3DRespone> pointInfoSyn3DRespones)
{
......@@ -696,7 +705,7 @@ public class View3DController extends BaseController
*/
@PostMapping(value = "/synchronous/routes",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "同步线路对应的3D视图元素", notes = "同步线路对应的3D视图元素")
@Authorization(ingore = true)
//@Authorization(ingore = true)
public CommonResponse synchronousPatrolroutes(
@ApiParam(value = "线路信息", required = true) @RequestBody List<RouteResponse> routeResponseList)
{
......@@ -883,12 +892,19 @@ public class View3DController extends BaseController
*/
private List<DaoCriteria> buildViewDaoCriteria(List<DaoCriteria> daoCriterias)
{
User currUser = getUserInfo();
// User currUser = getUserInfo();
// if (currUser != null)
// {
// Company company = currUser.getCompany();
// Department department = currUser.getDepartment();
// String compCode = company.getCompCode();
// if (department == null)
ReginParams currUser = getSelectedOrgInfo();
if (currUser != null)
{
Company company = currUser.getCompany();
Department department = currUser.getDepartment();
String compCode = company.getCompCode();
CompanyBo company = currUser.getCompany();
DepartmentBo department = currUser.getDepartment();
Long compCode = company.getCompanyOrgCode();
if (department == null)
{
//单位用户,查询本单位及子单位下所有部门
......@@ -900,7 +916,7 @@ public class View3DController extends BaseController
}else
{
//部门用户,查询当前部门
String orgCode = company.getCompCode()+"-"+department.getDepmCode();
String orgCode = company.getCompanyOrgCode()+"-"+department.getDeptOrgCode();
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.EQUAL.getName(), orgCode));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), orgCode+",%"));
daoCriterias.add(new DaoCriteria("orgCode", QueryOperatorEnum.LIKE.getName(), "%,"+orgCode+",%"));
......
package com.yeejoin.amos.safety.business.controller;
import com.yeejoin.amos.op.core.common.query.CommonPageable;
import com.yeejoin.amos.op.core.common.query.DaoCriteria;
import com.yeejoin.amos.op.core.common.query.QueryOperatorEnum;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.CommonResponseUtil;
import com.yeejoin.amos.safety.business.dao.mapper.View3DMapper;
import com.yeejoin.amos.safety.business.vo.CommonPageable;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import com.yeejoin.amos.safety.business.vo.CommonResponseUtil;
import com.yeejoin.amos.safety.business.vo.ReginParams;
import com.yeejoin.amos.safety.common.cache.CurUserCompanyCache;
import com.yeejoin.amos.safety.common.enums.CheckStateEnum;
import com.yeejoin.amos.safety.common.enums.View3DNodeType;
import com.yeejoin.amos.security.authorization.Authorization;
import com.yeejoin.amos.security.entity.Company;
import com.yeejoin.amos.security.entity.Department;
import com.yeejoin.amos.security.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
......@@ -64,7 +57,7 @@ public class View3DDataController extends BaseController
ObjectMapper objectMapper = new ObjectMapper();
@Authorization(ingore = true)
//@Authorization(ingore = true)
@GetMapping(value = "/3ddata/all",produces = "application/json;charset=UTF-8")
@ApiOperation(value = "实景右侧边栏搜索", notes = "实景右侧边栏搜索")
public CommonResponse saveCurrCompany(
......@@ -78,21 +71,21 @@ public class View3DDataController extends BaseController
@RequestParam(required = true) int pageSize) throws Exception
{
String orgCode = null;
User currUser = getUserInfo();
ReginParams currUser = getSelectedOrgInfo();
if (currUser != null)
{
//获取当前用户所选单位
String compCode = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
if (compCode != null)
{
//查询本单位及子单位下所有部门
Company company = currUser.getCompany();
orgCode = company.getCompCode();
}else
{
//无orgCode条件,通过当前登录用户orgCode过滤
orgCode = currUser.getOrgCode();
}
String compCode = currUser.getCompany().getOrgCode();
// if (compCode != null)
// {
// //查询本单位及子单位下所有部门
// Company company = currUser.getCompany();
// orgCode = company.getCompCode();
// }else
// {
// //无orgCode条件,通过当前登录用户orgCode过滤
// orgCode = currUser.getOrgCode();
// }
}
CommonPageable pageable = new CommonPageable( current, pageSize);
......
......@@ -24,7 +24,7 @@ public interface View3DMapper extends BaseMapper {
@Param("dataLevel")String dataLevel,
@Param("orgCode")String orgCode,
@Param("nodeState")String nodeState,
@Param("start")int start,
@Param("start")long l,
@Param("length")int length
);
......
......@@ -5,7 +5,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.op.core.jpa.IBaseRepository;
import com.yeejoin.amos.safety.business.service.IBaseRepository;
import com.yeejoin.amos.safety.common.entity.Link3DVo;
/**
......
......@@ -4,7 +4,7 @@ import java.util.List;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.op.core.jpa.IBaseRepository;
import com.yeejoin.amos.safety.business.service.IBaseRepository;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
......
......@@ -2,7 +2,7 @@ package com.yeejoin.amos.safety.business.dao.repository;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.op.core.jpa.IBaseRepository;
import com.yeejoin.amos.safety.business.service.IBaseRepository;
import com.yeejoin.amos.safety.common.entity.NodeToipLogView;
/**
......
......@@ -2,7 +2,7 @@ package com.yeejoin.amos.safety.business.dao.repository;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.op.core.jpa.IBaseRepository;
import com.yeejoin.amos.safety.business.service.IBaseRepository;
import com.yeejoin.amos.safety.common.entity.NodeMessageView;
/**
......
package com.yeejoin.amos.safety.business.service;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.io.Serializable;
/**
* <pre>
* JPA基础接口
* </pre>
*
* @author mincx
* @version IBaseRepository.java v0.1
* @time 2017-9-19 15:43:32
*/
@NoRepositoryBean
public interface IBaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID>,CrudRepository<T, ID>,PagingAndSortingRepository<T, ID>,JpaSpecificationExecutor<T>{
}
package com.yeejoin.amos.safety.business.service;
import java.io.Serializable;
import java.util.List;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
/**
* <pre>
* JPA基础接口
* </pre>
*
* @author mincx
* @version IGenericManager.java v0.1
* @time 2017-9-19 15:43:32
*/
public interface IGenericManager<T, ID extends Serializable> {
boolean exists(ID id);
T findOne(ID id);
T save(T object);
Iterable<T> save(Iterable<T> entities);
void delete(T object);
void delete(ID id);
List<T> findAll();
List<T> findAll(Sort sort);
List<T> findAll(Iterable<ID> ids);
List<T> findAll(Example<T> example);
List<T> findAll(Specification<T> spec);
List<T> findAll(Example<T> example, Sort sort);
List<T> findAll(Specification<T> spec, Sort sort);
Page<T> findAll(Pageable pageable);
Page<T> findAll(Example<T> example, Pageable pageable);
Page<T> findAll(Specification<T> spec, Pageable pageable);
/**
* <pre>
* 根据查询条件查询数据,条件之间用且连接
* </pre>
* @param daoCriteria
* @return List<Equipment>
*/
List<T> findAll(List<DaoCriteria> daoCriteria);
/**
* <pre>
* 根据查询条件查询数据,条件之间用连or接
* </pre>
* @param daoCriteria
* @return List<Equipment>
*/
List<T> findAllJoinOR(List<DaoCriteria> daoCriteria);
/**
* <pre>
* 根据查询条件和分页查询数据,条件之间用且连接
* </pre>
* @param daoCriteria
* @param pageable
* @return Page<Equipment>
*/
Page<T> findAll(List<DaoCriteria> daoCriteria,Pageable pageable);
/**
* <pre>
* 根据查询条件和分页查询数据,条件之间用连or接
* </pre>
* @param daoCriteria
* @param pageable
* @return Page<Equipment>
*/
Page<T> findAllJoinOR(List<DaoCriteria> daoCriteria,Pageable pageable);
}
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.safety.business.service;
import java.util.List;
import com.yeejoin.amos.op.core.jpa.IGenericManager;
import com.yeejoin.amos.safety.common.entity.Link3DVo;
/**
......
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.safety.business.service;
import java.util.List;
import com.yeejoin.amos.op.core.jpa.IGenericManager;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
/**
......
package com.yeejoin.amos.safety.business.service;
import com.yeejoin.amos.op.core.jpa.IGenericManager;
import com.yeejoin.amos.safety.common.entity.NodeToipLogView;
/**
......
package com.yeejoin.amos.safety.business.service;
import com.yeejoin.amos.op.core.jpa.IGenericManager;
import com.yeejoin.amos.safety.common.entity.NodeMessageView;
/**
......
package com.yeejoin.amos.safety.business.service;
/**
*
* <pre>
* 资源抽象类
* </pre>
*
* @author as-guowubin
* @version $Id: Resource.java, v 0.1 2018年5月18日 下午2:27:35 as-guowubin Exp $
*/
public abstract class Resource
{
}
package com.yeejoin.amos.safety.business.service.impl;
import com.yeejoin.amos.safety.business.service.Resource;
//import com.yeejoin.amos.op.core.entity.Resource;
/**
*
* <pre>
* service抽象接口
* </pre>
*
* @author as-guowubin
* @version $Id: AbstractSupportedModel.java, v 0.1 2018年5月25日 下午3:06:52 as-guowubin Exp $
*/
public abstract class AbstractSupportedModel
{
/**
*
* <pre>
* 删除资源
* </pre>
*
* @param model
*/
public void fireResourceReomoved(Resource resource)
{
}
}
package com.yeejoin.amos.safety.business.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.predicate.InPredicate;
import org.springframework.data.jpa.domain.Specification;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
/**
* 基础Specification
*
* @author as-youjun
*
* @param <T>
*/
public class BaseQuerySpecification<T> implements Specification<T> {
private List<DaoCriteria> daoCriterias;
private Map<String, List<DaoCriteria>> criterias;
private Map<String, List<String>> orderbys;
public BaseQuerySpecification(List<DaoCriteria> daoCriterias) {
this.daoCriterias = daoCriterias;
}
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
if (daoCriterias == null) {
return builder.and(new Predicate[] {});
}
criterias = classify(daoCriterias);
List<Predicate> conditions = new ArrayList<Predicate>();
for (String key : criterias.keySet()) {
List<DaoCriteria> daoCriterias = criterias.get(key);
if (daoCriterias.size() > 1) {
List<Predicate> sameConditions = new ArrayList<Predicate>();
for (DaoCriteria daoCriteria : daoCriterias) {
Predicate predicate = createPredicate(root, query, builder, daoCriteria);
if (null == predicate) {
throw new IllegalArgumentException("查询条件生成错误!");
} else {
sameConditions.add(predicate);
}
}
Predicate[] predicates = new Predicate[sameConditions.size()];
conditions.add(builder.or(sameConditions.toArray(predicates)));
} else {
for (DaoCriteria daoCriteria : daoCriterias) {
Predicate predicate = createPredicate(root, query, builder, daoCriteria);
if (null != predicate) {
conditions.add(predicate);
}
}
}
}
Predicate[] predicates = new Predicate[conditions.size()];
query.where(builder.and(conditions.toArray(predicates)));
List<Order> orders = new ArrayList<>();
orderbys.keySet().forEach(key -> {
if (key.toLowerCase().equals("asc") && !orderbys.get(key).isEmpty()) {
orderbys.get(key).forEach(propertyName -> {
orders.add(builder.asc(root.get(propertyName)));
});
} else if (key.toLowerCase().equals("desc") && !orderbys.get(key).isEmpty()) {
orderbys.get(key).forEach(propertyName -> {
orders.add(builder.desc(root.get(propertyName)));
});
}
});
query.orderBy(orders);
return query.getRestriction();
}
/**
* 根据同类条件进行分组
*
* @param criteraList
* @return
*/
private Map<String, List<DaoCriteria>> classify(List<DaoCriteria> criteraList) {
Map<String, List<DaoCriteria>> criteraType = new HashMap<String, List<DaoCriteria>>();
orderbys = new HashMap<>();
orderbys.put("asc", new ArrayList<String>());
orderbys.put("desc", new ArrayList<String>());
if (criteraList != null && criteraList.size() > 0) {
for (DaoCriteria daoCriteria : criteraList) {
if (daoCriteria.getOperator().equals(QueryOperatorEnum.ORDER_BY.getName())) {
orderbys.get(daoCriteria.getValue().toString().toLowerCase()).add(daoCriteria.getPropertyName());
} else {
List<DaoCriteria> temp = criteraType.get(daoCriteria.getPropertyName());
if (temp == null) {
temp = new ArrayList<DaoCriteria>();
criteraType.put(daoCriteria.getPropertyName(), temp);
}
temp.add(daoCriteria);
}
}
}
return criteraType;
}
/**
* 根据条件类型,创建查询条件
*
* @param root
* @param query
* @param builder
* @param daoCriteria
* @return
*/
private Predicate createPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder,
DaoCriteria daoCriteria) {
String name = daoCriteria.getPropertyName();
Object value = daoCriteria.getValue();
String operator = daoCriteria.getOperator();
if (operator.equals(QueryOperatorEnum.EQUAL.getName())) {
if (value instanceof Boolean) {
return builder.equal(root.get(name), value);
}
return builder.equal(root.get(name), value);
} else if (operator.equals(QueryOperatorEnum.LIKE.getName())) {
return builder.like(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.NOT_IN.getName())) {
return builder.not(
new InPredicate<Object>((CriteriaBuilderImpl) builder, root.get(name).as(String.class), value));
} else if (operator.equals(QueryOperatorEnum.BIGGER.getName())) {
return builder.greaterThan(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.BIGGER_EQUAL.getName())) {
return builder.greaterThanOrEqualTo(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.LESS.getName())) {
return builder.lessThan(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.LESS_EQUAL.getName())) {
return builder.lessThanOrEqualTo(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.NOT_EQUAL.getName())) {
return builder.notEqual(root.get(name).as(String.class), value);
} else if (operator.equals(QueryOperatorEnum.IN.getName())) {
if (value instanceof ArrayList<?>) {
return builder.and(
new InPredicate<Object>((CriteriaBuilderImpl) builder, root.get(name), ((ArrayList) value).toArray()));
}
return builder.and(
new InPredicate<Object>((CriteriaBuilderImpl) builder, root.get(name), value));
} else {
return null;
}
}
@SuppressWarnings("all")
private Class clasz(Object o) {
if (o instanceof Date) {
return Date.class;
} else if (o instanceof Integer) {
return Integer.class;
} else if (o instanceof Long) {
return Long.class;
} else if (o instanceof Double) {
return Double.class;
} else if (o instanceof Float) {
return Float.class;
} else if (o instanceof Short) {
return Short.class;
} else if (o instanceof Character) {
return Character.class;
} else if (o instanceof BigDecimal) {
return Double.class;
} else if (o instanceof Byte) {
return Byte.class;
} else if (o instanceof Byte) {
return Byte.class;
} else {
return String.class;
}
}
}
package com.yeejoin.amos.safety.business.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.predicate.InPredicate;
import org.springframework.data.jpa.domain.Specification;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
import com.yeejoin.amos.safety.business.vo.QueryOperatorEnum;
/**
* <pre>
* 查询条件转Specification
* </pre>
*
* @author as-zhaoqi_1
* @version $Id: BaseQuerySpecification.java, v 0.1 2017年11月2日 上午9:33:57 as-zhaoqi_1 Exp $
*/
public class BaseQuerySpecificationJoinOR<T> implements Specification<T> {
private List<DaoCriteria> daoCriterias;
private Map<String, List<DaoCriteria>> criterias;
private Map<String, List<String>> orderbys;
public BaseQuerySpecificationJoinOR(List<DaoCriteria> daoCriterias) {
this.daoCriterias = daoCriterias;
}
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
if(daoCriterias==null){
return builder.and(new Predicate[]{});
}
//将属性分为查询和排序
criterias = classify(daoCriterias);
List<Predicate> conditions = new ArrayList<Predicate>();
for(String key: criterias.keySet()) {
List<DaoCriteria> daoCriterias = criterias.get(key);
if (daoCriterias.size() > 1) {
List<Predicate> sameConditions = new ArrayList<Predicate>();
for(DaoCriteria daoCriteria: daoCriterias) {
Predicate predicate = createPredicate(root, query, builder, daoCriteria);
if (null == predicate) {
throw new IllegalArgumentException("查询条件生成错误!");
} else {
sameConditions.add(predicate);
}
}
Predicate[] predicates = new Predicate[sameConditions.size()];
conditions.add(builder.or(sameConditions.toArray(predicates)));
} else {
for(DaoCriteria daoCriteria: daoCriterias) {
Predicate predicate = createPredicate(root, query, builder, daoCriteria);
if (null != predicate) {
conditions.add(predicate);
}
}
}
}
Predicate[] predicates = new Predicate[conditions.size()];
query.where(builder.and(conditions.toArray(predicates)));
List<Order> orders = new ArrayList<>();
orderbys.keySet().forEach(key -> {
if (key.toLowerCase().equals("asc") && !orderbys.get(key).isEmpty()) {
orderbys.get(key).forEach(propertyName -> {
orders.add(builder.asc(root.get(propertyName)));
});
} else if (key.toLowerCase().equals("desc") && !orderbys.get(key).isEmpty()) {
orderbys.get(key).forEach(propertyName -> {
orders.add(builder.desc(root.get(propertyName)));
});
}
});
query.orderBy(orders);
return query.getRestriction();
}
/**
* 根据同类条件进行分组
*
* @param criteraList
* @return
*/
private Map<String, List<DaoCriteria>> classify(List<DaoCriteria> criteraList) {
Map<String, List<DaoCriteria>> criteraType = new HashMap<String, List<DaoCriteria>>();
orderbys = new HashMap<>();
orderbys.put("asc", new ArrayList<String>());
orderbys.put("desc", new ArrayList<String>());
if (criteraList != null && criteraList.size() > 0) {
for (DaoCriteria daoCriteria : criteraList) {
//排序属性
if (daoCriteria.getOperator().equals(QueryOperatorEnum.ORDER_BY.getName())) {
orderbys.get(daoCriteria.getValue().toString().toLowerCase()).add(daoCriteria.getPropertyName());
} else {//查询属性
List<DaoCriteria> temp = criteraType.get(daoCriteria.getPropertyName());
if (temp == null) {
temp = new ArrayList<DaoCriteria>();
criteraType.put(daoCriteria.getPropertyName(), temp);
}
temp.add(daoCriteria);
}
}
}
return criteraType;
}
/**
* 根据条件类型,创建查询条件
*
* @param root
* @param query
* @param builder
* @param daoCriteria
* @return
*/
private Predicate createPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder, DaoCriteria daoCriteria) {
String name = daoCriteria.getPropertyName();
Object value = daoCriteria.getValue();
String operator = daoCriteria.getOperator();
if (operator.equals(QueryOperatorEnum.EQUAL.getName())) {
return builder.equal(root.get(name).as(String.class), value);
} else if (operator.equals(QueryOperatorEnum.LIKE.getName())) {
return builder.like(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.NOT_IN.getName())) {
return builder.not(new InPredicate<Object>((CriteriaBuilderImpl) builder, root.get(name).as(String.class), value));
} else if (operator.equals(QueryOperatorEnum.BIGGER.getName())) {
return builder.greaterThan(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.BIGGER_EQUAL.getName())) {
return builder.greaterThanOrEqualTo(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.LESS.getName())) {
return builder.lessThan(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.LESS_EQUAL.getName())) {
return builder.lessThanOrEqualTo(root.get(name).as(String.class), value.toString());
} else if (operator.equals(QueryOperatorEnum.NOT_EQUAL.getName())) {
return builder.notEqual(root.get(name).as(String.class), value);
} else if (operator.equals(QueryOperatorEnum.IN.getName())) {
return builder.and(new InPredicate<Object>((CriteriaBuilderImpl) builder, root.get(name).as(String.class), value));
} else {
return null;
}
}
}
package com.yeejoin.amos.safety.business.service.impl;
import java.io.Serializable;
import java.util.List;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.transaction.annotation.Transactional;
import com.yeejoin.amos.safety.business.service.IBaseRepository;
import com.yeejoin.amos.safety.business.service.IGenericManager;
import com.yeejoin.amos.safety.business.vo.DaoCriteria;
/**
* <pre>
* JPA基础封装类
* </pre>
*
* @author mincx
* @version IBaseRepository.java v0.1
* @time 2017-9-19 15:43:32
*/
public class GenericManagerImpl<T, ID extends Serializable> extends
AbstractSupportedModel implements IGenericManager<T, ID>
{
protected IBaseRepository<T, ID> repository;
public GenericManagerImpl(IBaseRepository<T, ID> repository) {
this.repository = repository;
}
@Override
@Transactional(readOnly = true)
public boolean exists(ID id) {
return repository.existsById(id);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll() {
return repository.findAll();
}
@Override
@Transactional(readOnly = true)
public T findOne(ID id) {
return repository.findById(id).get();
}
@Override
public T save(T object) {
return repository.save(object);
}
@Override
public Iterable<T> save(Iterable<T> entities) {
return repository.saveAll(entities);
}
@Override
public void delete(T object) {
repository.delete(object);
}
@Override
public void delete(ID id) {
repository.deleteById(id);
}
@Override
@Transactional(readOnly = true)
public Page<T> findAll(Pageable pageable) {
return repository.findAll(pageable);
}
@Override
@Transactional(readOnly = true)
public Page<T> findAll(Example<T> example, Pageable pageable) {
return repository.findAll(example, pageable);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Example<T> example) {
return repository.findAll(example);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Example<T> example, Sort sort) {
return repository.findAll(example, sort);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Sort sort) {
return repository.findAll(sort);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Iterable<ID> ids) {
return repository.findAllById(ids);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Specification<T> spec) {
return repository.findAll(spec);
}
@Override
@Transactional(readOnly = true)
public List<T> findAll(Specification<T> spec, Sort sort) {
return repository.findAll(spec,sort);
}
@Override
@Transactional(readOnly = true)
public Page<T> findAll(Specification<T> spec, Pageable pageable) {
return repository.findAll(spec,pageable);
}
@Override
public List<T> findAll(List<DaoCriteria> daoCriteria)
{
//将daoCriteria条件转换为jpa识别的Specification
BaseQuerySpecification<T> spec = new BaseQuerySpecification<T>(daoCriteria);
return findAll(spec);
}
@Override
public Page<T> findAll(List<DaoCriteria> daoCriteria, Pageable pageable)
{
//将daoCriteria条件转换为jpa识别的Specification
BaseQuerySpecification<T> spec = new BaseQuerySpecification<T>(daoCriteria);
return findAll(spec,pageable);
}
@Override
public List<T> findAllJoinOR(List<DaoCriteria> daoCriteria)
{
//将daoCriteria条件转换为jpa识别的Specification
BaseQuerySpecificationJoinOR<T> spec = new BaseQuerySpecificationJoinOR<T>(daoCriteria);
return findAll(spec);
}
@Override
public Page<T> findAllJoinOR(List<DaoCriteria> daoCriteria, Pageable pageable)
{
//将daoCriteria条件转换为jpa识别的Specification
BaseQuerySpecificationJoinOR<T> spec = new BaseQuerySpecificationJoinOR<T>(daoCriteria);
return findAll(spec,pageable);
}
}
......@@ -4,7 +4,6 @@ import java.util.List;
import org.springframework.stereotype.Service;
import com.yeejoin.amos.op.core.jpa.GenericManagerImpl;
import com.yeejoin.amos.safety.business.dao.repository.ILink3DVoRepository;
import com.yeejoin.amos.safety.business.service.ILink3DVoService;
import com.yeejoin.amos.safety.common.entity.Link3DVo;
......
......@@ -3,8 +3,6 @@ package com.yeejoin.amos.safety.business.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.yeejoin.amos.op.core.jpa.GenericManagerImpl;
import com.yeejoin.amos.safety.business.dao.repository.INode3DVoRepository;
import com.yeejoin.amos.safety.business.service.INode3DVoService;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
......
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.safety.business.service.impl;
import org.springframework.stereotype.Service;
import com.yeejoin.amos.op.core.jpa.GenericManagerImpl;
import com.yeejoin.amos.safety.business.dao.repository.INodeLogViewRepository;
import com.yeejoin.amos.safety.business.service.INodeLogViewService;
import com.yeejoin.amos.safety.common.entity.NodeToipLogView;
......
......@@ -2,7 +2,6 @@ package com.yeejoin.amos.safety.business.service.impl;
import org.springframework.stereotype.Service;
import com.yeejoin.amos.op.core.jpa.GenericManagerImpl;
import com.yeejoin.amos.safety.business.dao.repository.INodeMsgViewRepository;
import com.yeejoin.amos.safety.business.service.INodeMsgViewService;
import com.yeejoin.amos.safety.common.entity.NodeMessageView;
......
package com.yeejoin.amos.safety.business.vo;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
*
* <pre>
* 分页实体
* </pre>
*
* @author as-chenjiajun
* @version $Id: CommonPageable.java, v 0.1 2016-12-14 上午10:42:44 as-chenjiajun
* Exp $
*/
public class CommonPageable implements Pageable {
/**
* 页号(大于等于0)
*/
protected int pageNumber = 0;
/**
* 每页大小(大于等于0)
*/
protected int pageSize = 10;
/**
* 起始索引
*/
protected int offset = 0;
/**
* 排序
*/
protected Sort sort = null;
public CommonPageable() {
this.pageNumber = 0;
this.pageSize = 10;
this.offset = pageSize * pageNumber;
}
public CommonPageable(int pageNumber, int pageSize) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.offset = pageSize * pageNumber;
}
public CommonPageable(int pageNumber, int pageSize, Sort sort) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.sort = sort;
this.offset = pageSize * pageNumber;
}
public int getPageNumber() {
return this.pageNumber;
}
public int getPageSize() {
return pageSize;
}
public long getOffset() {
offset = pageSize * pageNumber;
return offset;
}
public Sort getSort() {
return sort;
}
public Pageable next() {
return null;
}
public Pageable previousOrFirst() {
return null;
}
public Pageable first() {
return null;
}
public boolean hasPrevious() {
return false;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public void setSort(Sort sort) {
this.sort = sort;
}
public void setOffset(int offset) {
this.offset = offset;
}
}
package com.yeejoin.amos.safety.business.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* <pre>
* 公共请求对象
* </pre>
*
* @author as-shibaobao
* @version $Id: CommonRequest.java, v 0.1 2018年1月26日 上午10:59:19 as-shibaobao Exp $
*/
@ApiModel
public class CommonRequest {
/**
* 字段名称
*/
@ApiModelProperty(value="字段名称",required=true)
private String name;
/**
* 字段值
*/
@ApiModelProperty(value="字段值",required=true)
private Object value;
/**
* 查询类型
*/
@ApiModelProperty(value="查询类型",notes="空值时,默认为等于;其它类型按QueryOperatorEnum",required=false)
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.yeejoin.amos.safety.business.vo;
import java.io.Serializable;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.swagger.annotations.ApiModelProperty;
/**
* <pre>
* 返回封装对象
* </pre>
*
* @author mincx
* @version CommonReponse.java v0.1
* @time 2017-9-19 15:43:32
*/
public class CommonResponse implements Serializable {
private static final long serialVersionUID = -8737351878134480646L;
/**
* 操作状态
*/
@ApiModelProperty(required=true,value="操作状态")
private String result;
/**
* 数据
*/
@ApiModelProperty(required=false,value="数据")
private Object dataList;
/**
* 操作详细信息
*/
@ApiModelProperty(required=false,value="操作详细信息")
private String message;
public CommonResponse(){
}
public CommonResponse(String result) {
this.result = result;
}
public CommonResponse(Object dataList) {
this.dataList = dataList;
this.result = "";
}
public CommonResponse(String result, Object dataList) {
this.dataList = dataList;
this.result = result;
}
public CommonResponse(String result, String message) {
this.result = result;
this.message = message;
}
public CommonResponse(String result, Object dataList, String message) {
this.dataList = dataList;
this.result = result;
this.message = message;
}
public Boolean isSuccess(){
return "SUCCESS".equals(getResult());
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getDataList() {
return dataList;
}
public void setDataList(Object dataList) {
this.dataList = dataList;
}
public String toJsonStr() throws Exception {
return JSON.toJSONString(this,SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.SkipTransientField);
}
}
package com.yeejoin.amos.safety.business.vo;
public class CommonResponseUtil
{
public static CommonResponse success()
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_SUCCESS);
return response;
}
public static CommonResponse success(Object obj)
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_SUCCESS);
response.setDataList(obj);
return response;
}
public static CommonResponse success(Object obj, String message)
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_SUCCESS);
response.setDataList(obj);
response.setMessage(message);
return response;
}
public static CommonResponse failure()
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_FAILURE);
return response;
}
public static CommonResponse failure(String message)
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_FAILURE);
response.setMessage(message);
return response;
}
public static CommonResponse failure(Object obj, String message)
{
CommonResponse response = new CommonResponse();
response.setResult(Constants.RESULT_FAILURE);
response.setDataList(obj);
response.setMessage(message);
return response;
}
}
package com.yeejoin.amos.safety.business.vo;
import java.util.List;
public class CompanyBo {
private String address;
private String companyName;
private Long companyOrgCode;
private String email;
private String landlinePhone;
private String latitude;
private String level;
private String longitude;
private String orgCode;
private String parentId;
private String sequenceNbr;
private List<CompanyBo> children;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public Long getCompanyOrgCode() {
return companyOrgCode;
}
public void setCompanyOrgCode(Long companyOrgCode) {
this.companyOrgCode = companyOrgCode;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLandlinePhone() {
return landlinePhone;
}
public void setLandlinePhone(String landlinePhone) {
this.landlinePhone = landlinePhone;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(String sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public List<CompanyBo> getChildren() {
return children;
}
public void setChildren(List<CompanyBo> children) {
this.children = children;
}
}
package com.yeejoin.amos.safety.business.vo;
/**
* <pre>
* 系统常量
* </pre>
*
* @author mincx
* @version Constants.java v0.1
* @time 2017-9-19 15:43:32
*/
public class Constants {
public static final String ERROR_MESSAGE = "系统异常";
public static final String RESULT_SUCCESS = "SUCCESS";
public static final String RESULT_FAILURE = "FAILURE";
public static final String RULE_FACT_PREFIX = "rule_";
public static final String RULE_COMPILATION_ERROR = "规则编译异常";
public static final String NEW_LINE= "\r\n";
public static final String POSITION_LATITUDE = "latitude";
public static final String POSITION_LONGITUDE = "longitude";
public static final double PI = 3.1415;
public static final double EARTH_RADIUS = 6370.996;
public static final String RULE_CONDITION_AND = "&&";
public static final String RULE_CONDITION_OR = "||";
/**
* DES加密解密默认key
*/
public static final String XSS_KEY = "qaz";
/**
* 灾情状态
*/
public static final String FireHappenStateID = "90db70b7-49a4-4a72-b54b-0fabbed9bec7";//发生
public static final String FireDevelopStateID = "1f7fe7d7-b30c-4518-8c95-6e3bc506ca86";//猛烈
/**
* 车辆状态
*/
public static final String CarArrivedStateID = "ad55748a-1206-4507-8831-95b7f2ad804f";//到达
public static final String CarDispatchingStateID = "43a23576-3d0f-4c3d-a46b-555391a4d870";//待出动
public static final String CarOnDutyStateID = "21cc717f-60b4-46ae-942e-9efd63d13415";//执勤
public static final String CarOnSiteStateID = "d7eddc16-4c55-4de0-b726-3547c7b0b980";//在位
public static final String CarOnTheWayStateID = "5e1b6e98-d1dc-4c49-a7ad-b959d2278dba";//在途
public static final String CarRepairStateID = "e86d455b-e9fd-4938-9826-38ca46623287";//维修
/**
* 战斗力量编队状态
*/
public static final String RescuePowerArrivedStateID = "0951f770-7f75-43d8-bcec-47d7559be727";//到达
public static final String RescuePowerDispatchedStateID = "ec4afc56-6cec-41a3-95f5-20c735f052d4";//已调派
public static final String RescuePowerEnhanceStateID = "3d6cf113-b69d-47c3-a3a8-ded448cc4636";//增援
public static final String RescuePowerFightingStateID = "4bacd4b4-b07d-454e-b737-431e7c997cde";//战斗
public static final String RescuePowerStandByStateID = "4fc6e4d6-c6a8-453c-b554-ce7de0b828b2";//待命
/**
* sql注入关键字
*/
public static String badStr = "'|and|exec|execute|insert|select|delete|update|count|drop|%|chr|mid|master|truncate|" +
"char|declare|sitename|net user|xp_cmdshell|;|or|-|+|,|like'|and|exec|execute|insert|create|drop|" +
"table|from|grant|use|group_concat|column_name|" +
"information_schema.columns|table_schema|union|where|select|delete|update|order|by|count|" +
"chr|mid|master|truncate|char|declare|or|;|-|--|,|like|//|/|%|#";
}
package com.yeejoin.amos.safety.business.vo;
import java.io.Serializable;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
*
* <pre>
* 查询条件封装类
* </pre>
*
* @author as-hanshipeng
* @version $Id: DaoCriteria.java, v 0.1 2016-12-9 下午12:22:03 as-hanshipeng Exp $
*/
public class DaoCriteria implements Serializable
{
private static final long serialVersionUID = 812759366580443779L;
//属性名称
private String propertyName;
//操作符
private String operator;
//属性值
private Object value;
public String getOperator()
{
return operator;
}
public void setOperator(String operator)
{
this.operator = operator;
}
public String getPropertyName()
{
return propertyName;
}
public void setPropertyName(String propertyName)
{
this.propertyName = propertyName;
}
public Object getValue()
{
return value;
}
public void setValue(Object value)
{
this.value = value;
}
public DaoCriteria()
{
}
public DaoCriteria(String property, String operator, Object value)
{
propertyName = property;
this.operator = operator;
this.value = value;
}
public String toString()
{
return (new ToStringBuilder(this)).append("Property", propertyName).append(operator).append("Value", value).toString();
}
}
package com.yeejoin.amos.safety.business.vo;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import org.apache.commons.lang.StringUtils;
/**
* 鏃ユ湡宸ュ叿绫�
*
*/
public class DateUtil {
// 榛樿鏃ユ湡鏍煎紡
public static final String DATE_DEFAULT_FORMAT = "yyyy-MM-dd";
// 榛樿鏃ユ湡鏍煎紡
public static final String DATE_YEARANDMONTH_FORMAT = "yyyy-MM";
// 榛樿鏃堕棿鏍煎紡
public static final String DATETIME_DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String TIME_DEFAULT_FORMAT = "HH:mm:ss";
// 鏃ユ湡鏍煎紡鍖�
private static DateFormat dateFormat = null;
// 鏃堕棿鏍煎紡鍖�
private static DateFormat dateTimeFormat = null;
// 骞存湀鏍煎紡鍖�
private static DateFormat dateYearAndMonthFormat = null;
private static DateFormat timeFormat = null;
private static Calendar gregorianCalendar = null;
static {
dateFormat = new SimpleDateFormat(DATE_DEFAULT_FORMAT);
dateYearAndMonthFormat = new SimpleDateFormat(DATE_YEARANDMONTH_FORMAT);
dateTimeFormat = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT);
timeFormat = new SimpleDateFormat(TIME_DEFAULT_FORMAT);
gregorianCalendar = new GregorianCalendar();
}
/**
* 鏃ユ湡鏍煎紡鍖杫yyy-MM-dd
*
* @param date
* @return
*/
public static Date formatDate(String date, String format) {
try {
return new SimpleDateFormat(format).parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 鏃ユ湡鏍煎紡鍖杫yyy-MM-dd
*
* @param date
* @return
*/
public static String getDateFormat(Date date) {
return dateFormat.format(date);
}
/**
* 鏃ユ湡鏍煎紡鍖杫yyy-MM
*
* @param date
* @return
*/
public static String getDateYearAndMonthFormat(Date date) {
return dateYearAndMonthFormat.format(date);
}
/**
* 鏃ユ湡鏍煎紡鍖杫yyy-MM-dd HH:mm:ss
*
* @param date
* @return
*/
public static String getDateTimeFormat(Date date) {
return dateTimeFormat.format(date);
}
/**
* 鏃堕棿鏍煎紡鍖�
*
* @param date
* @return HH:mm:ss
*/
public static String getTimeFormat(Date date) {
return timeFormat.format(date);
}
/**
* 鏃ユ湡鏍煎紡鍖�
*
* @param date
* @param 鏍煎紡绫诲瀷
* @return
*/
public static String getDateFormat(Date date, String formatStr) {
if (StringUtils.isNotBlank(formatStr)) {
return new SimpleDateFormat(formatStr).format(date);
}
return null;
}
/**
* 鏃ユ湡鏍煎紡鍖�
*
* @param date
* @return
*/
public static Date getDateFormat(String date) {
try {
return dateFormat.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 鏃堕棿鏍煎紡鍖�
*
* @param date
* @return
*/
public static Date getDateTimeFormat(String date) {
try {
return dateTimeFormat.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 鑾峰彇褰撳墠鏃ユ湡(yyyy-MM-dd)
*
* @param date
* @return
*/
public static Date getNowDate() {
return DateUtil.getDateFormat(dateFormat.format(new Date()));
}
/**
* 鑾峰彇褰撳墠鏃ユ湡鏄熸湡涓�鏃ユ湡
*
* @return date
*/
public static Date getFirstDayOfWeek() {
gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
gregorianCalendar.setTime(new Date());
gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek()); // Monday
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇褰撳墠鏃ユ湡鏄熸湡鏃ユ棩鏈�
*
* @return date
*/
public static Date getLastDayOfWeek() {
gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
gregorianCalendar.setTime(new Date());
gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek() + 6); // Monday
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鏃ユ湡鏄熸湡涓�鏃ユ湡
*
* @param 鎸囧畾鏃ユ湡
* @return date
*/
public static Date getFirstDayOfWeek(Date date) {
if (date == null) {
return null;
}
gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
gregorianCalendar.setTime(date);
gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek()); // Monday
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鏃ユ湡鏄熸湡涓�鏃ユ湡
*
* @param 鎸囧畾鏃ユ湡
* @return date
*/
public static Date getLastDayOfWeek(Date date) {
if (date == null) {
return null;
}
gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
gregorianCalendar.setTime(date);
gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek() + 6); // Monday
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇褰撳墠鏈堢殑绗竴澶�
*
* @return date
*/
public static Date getFirstDayOfMonth() {
gregorianCalendar.setTime(new Date());
gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇褰撳墠鏈堢殑鏈�鍚庝竴澶�
*
* @return
*/
public static Date getLastDayOfMonth() {
gregorianCalendar.setTime(new Date());
gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);
gregorianCalendar.add(Calendar.MONTH, 1);
gregorianCalendar.add(Calendar.DAY_OF_MONTH, -1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鎸囧畾鏈堢殑绗竴澶�
*
* @param date
* @return
*/
public static Date getFirstDayOfMonth(Date date) {
gregorianCalendar.setTime(date);
gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鎸囧畾鏈堢殑鏈�鍚庝竴澶�
*
* @param date
* @return
*/
public static Date getLastDayOfMonth(Date date) {
gregorianCalendar.setTime(date);
gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);
gregorianCalendar.add(Calendar.MONTH, 1);
gregorianCalendar.add(Calendar.DAY_OF_MONTH, -1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鏃ユ湡鍓嶄竴澶�
*
* @param date
* @return
*/
public static Date getDayBefore(Date date) {
gregorianCalendar.setTime(date);
int day = gregorianCalendar.get(Calendar.DATE);
gregorianCalendar.set(Calendar.DATE, day - 1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇鏃ユ湡鍚庝竴澶�
*
* @param date
* @return
*/
public static Date getDayAfter(Date date) {
gregorianCalendar.setTime(date);
int day = gregorianCalendar.get(Calendar.DATE);
gregorianCalendar.set(Calendar.DATE, day + 1);
return gregorianCalendar.getTime();
}
/**
* 鑾峰彇褰撳墠骞�
*
* @return
*/
public static int getNowYear() {
Calendar d = Calendar.getInstance();
return d.get(Calendar.YEAR);
}
/**
* 鑾峰彇褰撳墠鏈堜唤
*
* @return
*/
public static int getNowMonth() {
Calendar d = Calendar.getInstance();
return d.get(Calendar.MONTH) + 1;
}
/**
* 鑾峰彇date鐨勫勾
*
* @return
*/
public static int getDateYear(Date date) {
Calendar d = Calendar.getInstance();
d.setTime(date);
return d.get(Calendar.YEAR);
}
/**
* 鑾峰彇date鐨勬湀浠�
*
* @return
*/
public static int getDateMonth(Date date) {
Calendar d = Calendar.getInstance();
d.setTime(date);
return d.get(Calendar.MONTH) + 1;
}
/**
* 鑾峰彇褰撴湀澶╂暟
*
* @return
*/
public static int getNowMonthDay() {
Calendar d = Calendar.getInstance();
return d.getActualMaximum(Calendar.DATE);
}
/**
* 鑾峰彇鏃堕棿娈电殑姣忎竴澶�
*
* @param 寮�濮嬫棩鏈�
* @param 缁撶畻鏃ユ湡
* @return 鏃ユ湡鍒楄〃
*/
public static List<Date> getEveryDay(Date startDate, Date endDate) {
if (startDate == null || endDate == null) {
return null;
}
// 鏍煎紡鍖栨棩鏈�(yy-MM-dd)
startDate = DateUtil.getDateFormat(DateUtil.getDateFormat(startDate));
endDate = DateUtil.getDateFormat(DateUtil.getDateFormat(endDate));
List<Date> dates = new ArrayList<Date>();
gregorianCalendar.setTime(startDate);
dates.add(gregorianCalendar.getTime());
while (gregorianCalendar.getTime().compareTo(endDate) < 0) {
// 鍔�1澶�
gregorianCalendar.add(Calendar.DAY_OF_MONTH, 1);
dates.add(gregorianCalendar.getTime());
}
return dates;
}
/**
* 鑾峰彇鎻愬墠澶氬皯涓湀
*
* @param monty
* @return
*/
public static Date getFirstMonth(int monty) {
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -monty);
return c.getTime();
}
/**
* 寰楀埌鐜板湪鏃堕棿
*
* @return
*/
public static Date getNow()
{
Date currentTime = new Date();
return currentTime;
}
/**
* 鑾峰彇鐜板湪鏃堕棿
*
* @return 杩斿洖鏃堕棿绫诲瀷 yyyy-MM-dd HH:mm:ss
*/
public static String getNowDateLongForHandset()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd-HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
public static String getDateLongForHandset(java.util.Date dateDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
public static String getDateStr(String formatterstr) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(formatterstr);
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 鑾峰彇鐜板湪鏃堕棿
*
* @return 杩斿洖鏃堕棿绫诲瀷 yyyy-MM-dd HH:mm:ss
*/
public static Date getNowDateLong()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(0);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
/**
* 鑾峰彇鐜板湪鏃堕棿
*
* @return杩斿洖鐭椂闂存牸寮� yyyy-MM-dd
*/
public static Date getNowDateShort()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
/**
* 鑾峰彇鐜板湪鏃堕棿瀛楃涓�
*
* @return杩斿洖瀛楃涓叉牸寮� yyyy-MM-dd HH:mm:ss
*/
public static String getNowStrLong()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 鑾峰彇鐜板湪鏃堕棿瀛楃涓�
*
* @return 杩斿洖鐭椂闂村瓧绗︿覆鏍煎紡yyyy-MM-dd
*/
public static String getNowStrShort()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 鑾峰彇鏃堕棿 灏忔椂:鍒�;绉� HH:mm:ss
*
* @return
*/
public static String getNowHHMMSS()
{
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date currentTime = new Date();
String dateString = formatter.format(currentTime);
return dateString;
}
/**
*
* <pre>
*
* </pre>
*
* @param strDate
* @param dateFormat
* @return
*/
public static Date str2Date(String strDate, String dateFormat)
{
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/**
*
* <pre>
* e.g localDateStr ="2017-03-30T06:28:12.803Z";
* </pre>
*
* @param strDate
* @param dateFormat
* @return
*/
public static Date localDateStr2Date(String localDateStr)
{
LocalDateTime localDate = LocalDateTime.parse(localDateStr,DateTimeFormatter.ISO_ZONED_DATE_TIME);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formatLocalDate2Str = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(formatLocalDate2Str, pos);
return strtodate;
}
/**
* 灏嗛暱鏃堕棿鏍煎紡瀛楃涓茶浆鎹负鏃堕棿 yyyy-MM-dd HH:mm:ss
*
* @param strDate
* @return
*/
public static Date longStr2Date(String strDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/**
* 灏嗛暱鏃堕棿鏍煎紡瀛楃涓茶浆鎹负鏃堕棿 yyyy-MM-dd HH:mm
*
* @param strDate
* @return
*/
public static Date longStr3Date(String strDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/**
* 灏嗛暱鏃堕棿鏍煎紡瀛楃涓茶浆鎹负long鍨嬫暟鎹�
*
* @param strDate
* @return
*/
public static Long longStr2Long(String strDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate.getTime();
}
/**
* 灏嗛暱鏃堕棿鏍煎紡鏃堕棿杞崲涓哄瓧绗︿覆 yyyy-MM-dd HH:mm:ss
*
* @param dateDate
* @return
*/
public static String date2LongStr(Date dateDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
/**
* 灏嗙煭鏃堕棿鏍煎紡鏃堕棿杞崲涓哄瓧绗︿覆 yyyy-MM-dd
*
* @param dateDate
* @param k
* @return
*/
public static String date2ShortStr(java.util.Date dateDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(dateDate);
return dateString;
}
/**
*
* <pre>
*
* </pre>
*
* @param l
* @param dateFormat
* @return
*/
public static String long2Str(long l, String dateFormat)
{
if (l == 0)
{
return "";
}
try
{
Date dateDate = new Date(l);
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
String dateString = formatter.format(dateDate);
return dateString;
}
catch (Exception e)
{
return "";
}
}
/**
* 鎶奓ONG鏁版嵁绫诲瀷杞崲涓哄瓧绗︿覆
*
* @param l
* @return
*/
public static String long2LongStr(long l)
{
if (l == 0)
{
return "";
}
try
{
Date dateDate = new Date(l);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
catch (Exception e)
{
return "";
}
}
/**
* 鎶奓ONG鏁版嵁绫诲瀷杞崲涓哄瓧绗︿覆
*
* <pre>
*
* </pre>
*
* @param l
* @return
*/
public static String long2ShortStr(long l)
{
if (l == 0)
{
return "";
}
try
{
Date dateDate = new Date(l);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(dateDate);
return dateString;
}
catch (Exception e)
{
return "";
}
}
/**
* 灏嗙煭鏃堕棿鏍煎紡瀛楃涓茶浆鎹负鏃堕棿 yyyy-MM-dd
*
* @param strDate
* @return
*/
public static Date shortStr2ShortDate(String strDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/**
* 鎻愬彇涓�涓湀涓殑鏈�鍚庝竴澶�
*
* @param day
* @return
*/
public static Date getLastDateOfThisMonth(long day)
{
Date date = new Date();
long date_3_hm = date.getTime() - 3600000 * 34 * day;
Date date_3_hm_date = new Date(date_3_hm);
return date_3_hm_date;
}
/**
* 鑾峰彇鏃ユ湡涓殑骞�
*
* @param date
* @return
*/
public static String getYear(Date date) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(date);
String year;
year = dateString.substring(0, 4);
return year;
}
/**
* 寰楀埌鐜板湪灏忔椂
*/
public static String getHour()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
String hour;
hour = dateString.substring(11, 13);
return hour;
}
/**
* 寰楀埌鐜板湪鍒嗛挓
*
* @return
*/
public static String getMinute()
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
String min;
min = dateString.substring(14, 16);
return min;
}
/**
* 鏍规嵁鐢ㄦ埛浼犲叆鐨勬椂闂磋〃绀烘牸寮忥紝杩斿洖褰撳墠鏃堕棿鐨勬牸寮� 濡傛灉鏄痽yyyMMdd锛屾敞鎰忓瓧姣峺涓嶈兘澶у啓銆�
*
* @param sformat
* yyyyMMddhhmmss
* @return
*/
public static String parseDate(String sformat)
{
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(sformat);
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 浜屼釜灏忔椂鏃堕棿闂寸殑宸��,蹇呴』淇濊瘉浜屼釜鏃堕棿閮芥槸"HH:MM"鐨勬牸寮忥紝杩斿洖瀛楃鍨嬬殑鍒嗛挓
*/
public static String getTwoHour(String st1, String st2)
{
String[] kk = null;
String[] jj = null;
kk = st1.split(":");
jj = st2.split(":");
if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0])) return "0";
else
{
double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60;
double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60;
if ((y - u) > 0) return y - u + "";
else
return "0";
}
}
/**
* 寰楀埌浜屼釜鏃ユ湡闂寸殑闂撮殧澶╂暟
*/
public static String getTwoDay(String sj1, String sj2)
{
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
long day = 0;
try
{
java.util.Date date = myFormatter.parse(sj1);
java.util.Date mydate = myFormatter.parse(sj2);
day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
}
catch (Exception e)
{
return "";
}
return day + "";
}
/**
* 鏃堕棿鍓嶆帹鎴栧悗鎺ㄥ垎閽�,鍏朵腑JJ琛ㄧず鍒嗛挓.
*/
public static String getPreTime(String sj1, String jj)
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate1 = "";
try
{
Date date1 = format.parse(sj1);
long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
date1.setTime(Time * 1000);
mydate1 = format.format(date1);
}
catch (Exception e)
{
mydate1 = "";
}
return mydate1;
}
/**
* 寰楀埌涓�涓椂闂村欢鍚庢垨鍓嶇Щ鍑犲ぉ鐨勬椂闂�,nowdate涓烘椂闂�,delay涓哄墠绉绘垨鍚庡欢鐨勫ぉ鏁�
*/
public static String getNextDay(String nowdate, String delay)
{
try
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String mdate = "";
Date d = shortStr2ShortDate(nowdate);
long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;
d.setTime(myTime * 1000);
mdate = format.format(d);
return mdate;
}
catch (Exception e)
{
return "";
}
}
/**
* 鍒ゆ柇鏄惁娑﹀勾
*
* @param ddate
* @return
*/
public static boolean isLeapYear(String ddate)
{
/**
* 璇︾粏璁捐锛� 1.琚�400鏁撮櫎鏄棸骞达紝鍚﹀垯锛� 2.涓嶈兘琚�4鏁撮櫎鍒欎笉鏄棸骞� 3.鑳借4鏁撮櫎鍚屾椂涓嶈兘琚�100鏁撮櫎鍒欐槸闂板勾
* 3.鑳借4鏁撮櫎鍚屾椂鑳借100鏁撮櫎鍒欎笉鏄棸骞�
*/
Date d = shortStr2ShortDate(ddate);
GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
gc.setTime(d);
int year = gc.get(Calendar.YEAR);
if ((year % 400) == 0) return true;
else if ((year % 4) == 0)
{
if ((year % 100) == 0) return false;
else
return true;
}
else
return false;
}
/**
* 杩斿洖缇庡浗鏃堕棿鏍煎紡 26 Apr 2006
*
* @param str
* @return
*/
public static String getEDate(String str)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(str, pos);
String j = strtodate.toString();
String[] k = j.split(" ");
return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
}
/**
* 鑾峰彇涓�涓湀鐨勬渶鍚庝竴澶�
*
* @param dat
* @return
*/
public static String getEndDateOfMonth(String dat)
{// yyyy-MM-dd
String str = dat.substring(0, 8);
String month = dat.substring(5, 7);
int mon = Integer.parseInt(month);
if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12)
{
str += "31";
}
else if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
{
str += "30";
}
else
{
if (isLeapYear(dat))
{
str += "29";
}
else
{
str += "28";
}
}
return str;
}
/**
* 鍒ゆ柇浜屼釜鏃堕棿鏄惁鍦ㄥ悓涓�涓懆
*
* @param date1
* @param date2
* @return
*/
public static boolean isSameWeekDates(Date date1, Date date2)
{
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
if (0 == subYear)
{
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) return true;
}
else if (1 == subYear && 11 == cal2.get(Calendar.MONTH))
{
// 濡傛灉12鏈堢殑鏈�鍚庝竴鍛ㄦí璺ㄦ潵骞寸涓�鍛ㄧ殑璇濆垯鏈�鍚庝竴鍛ㄥ嵆绠楀仛鏉ュ勾鐨勭涓�鍛�
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) return true;
}
else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH))
{
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) return true;
}
return false;
}
/**
* 浜х敓鍛ㄥ簭鍒�,鍗冲緱鍒板綋鍓嶆椂闂存墍鍦ㄧ殑骞村害鏄鍑犲懆
*
* @return
*/
public static String getSeqWeek()
{
Calendar c = Calendar.getInstance(Locale.CHINA);
String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));
if (week.length() == 1) week = "0" + week;
String year = Integer.toString(c.get(Calendar.YEAR));
return year + week;
}
/**
* 鑾峰緱涓�涓棩鏈熸墍鍦ㄧ殑鍛ㄧ殑鏄熸湡鍑犵殑鏃ユ湡锛屽瑕佹壘鍑�2002骞�2鏈�3鏃ユ墍鍦ㄥ懆鐨勬槦鏈熶竴鏄嚑鍙�
*
* @param sdate
* @param num
* @return
*/
public static String getWeek(String sdate, String num)
{
// 鍐嶈浆鎹负鏃堕棿
Date dd = shortStr2ShortDate(sdate);
Calendar c = Calendar.getInstance();
c.setTime(dd);
if (num.equals("1")) // 杩斿洖鏄熸湡涓�鎵�鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
else if (num.equals("2")) // 杩斿洖鏄熸湡浜屾墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
else if (num.equals("3")) // 杩斿洖鏄熸湡涓夋墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
else if (num.equals("4")) // 杩斿洖鏄熸湡鍥涙墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
else if (num.equals("5")) // 杩斿洖鏄熸湡浜旀墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
else if (num.equals("6")) // 杩斿洖鏄熸湡鍏墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
else if (num.equals("0")) // 杩斿洖鏄熸湡鏃ユ墍鍦ㄧ殑鏃ユ湡
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
}
/**
* 鏍规嵁涓�涓棩鏈燂紝杩斿洖鏄槦鏈熷嚑鐨勫瓧绗︿覆
*
* @param sdate
* @return
*/
public static String getWeek(String sdate)
{
// 鍐嶈浆鎹负鏃堕棿
Date date = shortStr2ShortDate(sdate);
Calendar c = Calendar.getInstance();
c.setTime(date);
// int hour=c.get(Calendar.DAY_OF_WEEK);
// hour涓瓨鐨勫氨鏄槦鏈熷嚑浜嗭紝鍏惰寖鍥� 1~7
// 1=鏄熸湡鏃� 7=鏄熸湡鍏紝鍏朵粬绫绘帹
return new SimpleDateFormat("EEEE").format(c.getTime());
}
public static String getWeekStr(String sdate)
{
String str = "";
str = getWeek(sdate);
if ("1".equals(str))
{
str = "鏄熸湡鏃�";
}
else if ("2".equals(str))
{
str = "鏄熸湡涓�";
}
else if ("3".equals(str))
{
str = "鏄熸湡浜�";
}
else if ("4".equals(str))
{
str = "鏄熸湡涓�";
}
else if ("5".equals(str))
{
str = "鏄熸湡鍥�";
}
else if ("6".equals(str))
{
str = "鏄熸湡浜�";
}
else if ("7".equals(str))
{
str = "鏄熸湡鍏�";
}
return str;
}
/**
* 涓や釜鏃堕棿涔嬮棿鐨勫ぉ鏁�
*
* @param date1
* @param date2
* @return
*/
public static long getDays(String date1, String date2)
{
if (date1 == null || date1.equals("")) return 0;
if (date2 == null || date2.equals("")) return 0;
// 杞崲涓烘爣鍑嗘椂闂�
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = null;
java.util.Date mydate = null;
try
{
date = myFormatter.parse(date1);
mydate = myFormatter.parse(date2);
}
catch (Exception e)
{
;
}
long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
return day;
}
/**
* 褰㈡垚濡備笅鐨勬棩鍘� 锛� 鏍规嵁浼犲叆鐨勪竴涓椂闂磋繑鍥炰竴涓粨鏋� 鏄熸湡鏃� 鏄熸湡涓� 鏄熸湡浜� 鏄熸湡涓� 鏄熸湡鍥� 鏄熸湡浜� 鏄熸湡鍏� 涓嬮潰鏄綋鏈堢殑鍚勪釜鏃堕棿
* 姝ゅ嚱鏁拌繑鍥炶鏃ュ巻绗竴琛屾槦鏈熸棩鎵�鍦ㄧ殑鏃ユ湡
*
* @param sdate
* @return
*/
public static String getNowMonth(String sdate)
{
// 鍙栬鏃堕棿鎵�鍦ㄦ湀鐨勪竴鍙�
sdate = sdate.substring(0, 8) + "01";
// 寰楀埌杩欎釜鏈堢殑1鍙锋槸鏄熸湡鍑�
Date date = shortStr2ShortDate(sdate);
Calendar c = Calendar.getInstance();
c.setTime(date);
int u = c.get(Calendar.DAY_OF_WEEK);
String newday = DateUtil.getNextDay(sdate, (1 - u) + "");
return newday;
}
/**
* 鍙栧緱鏁版嵁搴撲富閿� 鐢熸垚鏍煎紡涓簓yyymmddhhmmss+k浣嶉殢鏈烘暟
*
* @param k
* 琛ㄧず鏄彇鍑犱綅闅忔満鏁帮紝鍙互鑷繁瀹�
*/
public static String getNo(int k)
{
return parseDate("yyyyMMddhhmmss") + getRandom(k);
}
/**
* 杩斿洖涓�涓殢鏈烘暟
*
* @param i
* @return
*/
private static String getRandom(int i)
{
Random jjj = new Random();
// int suiJiShu = jjj.nextInt(9);
if (i == 0) return "";
String jj = "";
for (int k = 0; k < i; k++)
{
jj = jj + jjj.nextInt(9);
}
return jj;
}
/**
*
* @param args
*/
public static boolean rightDate(String date)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
if (date == null) return false;
if (date.length() > 10)
{
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
}
else
{
sdf = new SimpleDateFormat("yyyy-MM-dd");
}
try
{
sdf.parse(date);
}
catch (ParseException e)
{
return false;
}
return true;
}
public static void main(String[] args)
{
//
}
/**
* 灏哾ate 鎸夌収鎸囧畾 鐨� 鏍煎紡 formatStr 杞崲鎴� 瀛楃涓�
*
* @param date
* @param formatStr
* @return
*/
public static String date2Str(Date date, String formatStr)
{
SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
String dateString = formatter.format(date);
return dateString;
}
/**
* 澧炲姞hours灏忔檪
*
* @param date
* @param hours
* @return
*/
public static Date addHours(Date date, int hours)
{
if (date == null) return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR_OF_DAY, hours);// 24灏忔椂鍒�
// cal.add(Calendar.HOUR, x);12灏忔椂鍒�
date = cal.getTime();
return date;
}
/**
* 澧炲姞minutes鍒嗛悩
*
* @param date
* @param minutes
* @return
*/
public static Date addMinutes(Date date, int minutes)
{
if (date == null) return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MINUTE, minutes);//
date = cal.getTime();
return date;
}
/**
* 鍔熻兘鎻忚堪锛氭牸寮忓寲鏃ユ湡
*
* @param dateStr
* String 瀛楃鍨嬫棩鏈�
* @param format
* String 鏍煎紡
* @return Date 鏃ユ湡
*/
public static Date parseDate(String dateStr, String format) {
Date date=null;
try {
DateFormat dateFormat = new SimpleDateFormat(format);
date = (Date) dateFormat.parse(dateStr);
} catch (Exception e) {
}
return date;
}
// 鎸囧畾妯″紡鐨勬椂闂存牸寮�
private static SimpleDateFormat getSDFormat(String pattern) {
return new SimpleDateFormat(pattern);
}
/**
* 褰撳墠鏃ュ巻锛岃繖閲岀敤涓浗鏃堕棿琛ㄧず
*
* @return 浠ュ綋鍦版椂鍖鸿〃绀虹殑绯荤粺褰撳墠鏃ュ巻
*/
public static Calendar getCalendar() {
return Calendar.getInstance();
}
/**
* 榛樿鏃ユ湡鎸夋寚瀹氭牸寮忔樉绀�
*
* @param pattern
* 鎸囧畾鐨勬牸寮�
* @return 榛樿鏃ユ湡鎸夋寚瀹氭牸寮忔樉绀�
*/
public static String formatDate(String pattern) {
return getSDFormat(pattern).format(getCalendar().getTime());
}
/**
* 鑾峰彇褰撳墠鏃堕棿浠绘剰
* @return
*/
public static String get(int field) {
return String.valueOf(getCalendar().get(field));
}
/**
* 鑾峰彇浠婃棩鐨勫紑濮嬫椂闂�
* @return
*/
public static Date getTodayBeginTime(){
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date today = calendar.getTime();
return today;
}
/**
* 鑾峰彇浠婃棩鐨勭粨鏉熸椂闂�
* @return
*/
public static Date getTodayEndTime(){
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Date today = calendar.getTime();
return today;
}
/**
* 鑾峰彇涓や釜鏃堕棿鐩稿樊鐨� *灏忔椂*鍒嗛挓
* @param endDate
* @param nowDate
* @return
*/
public static String getDatePoorToMin(Date endDate, Date nowDate) {
// long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
long diff = endDate.getTime() - nowDate.getTime();
// 璁$畻宸灏戝ぉ
// long day = diff / nd;
// 璁$畻宸灏戝皬鏃�
long hour = diff / nh;
// 璁$畻宸灏戝垎閽�
long min = diff % nh / nm;
// 璁$畻宸灏戠//杈撳嚭缁撴灉
// long sec = diff % nd % nh % nm / ns;
return hour + "灏忔椂" + min + "鍒嗛挓";
}
public static String getDatePoorToSec(Date endDate, Date nowDate) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ss = 1000;
// long ns = 1000;
// 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
long diff = endDate.getTime() - nowDate.getTime();
// 璁$畻宸灏戝ぉ
long day = diff / nd;
// 璁$畻宸灏戝皬鏃�
long hour = diff % nd / nh;
// 璁$畻宸灏戝垎閽�
long min = diff % nd % nh / nm;
long sen = diff % nd % nh % nm / ss;
// 璁$畻宸灏戠//杈撳嚭缁撴灉
// long sec = diff % nd % nh % nm / ns;
return day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓"+ sen + "绉�";
}
}
package com.yeejoin.amos.safety.business.vo;
import java.util.List;
public class DepartmentBo {
private String departmentName;
private String level;
private String deptOrgCode;
private String orgCode;
private String departmentDesc;
private String companySeq;
private String sequenceNbr;
private String parentId;
private List<DepartmentBo> children;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getDeptOrgCode() {
return deptOrgCode;
}
public void setDeptOrgCode(String deptOrgCode) {
this.deptOrgCode = deptOrgCode;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getDepartmentDesc() {
return departmentDesc;
}
public void setDepartmentDesc(String departmentDesc) {
this.departmentDesc = departmentDesc;
}
public String getCompanySeq() {
return companySeq;
}
public void setCompanySeq(String companySeq) {
this.companySeq = companySeq;
}
public String getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(String sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public List<DepartmentBo> getChildren() {
return children;
}
public void setChildren(List<DepartmentBo> children) {
this.children = children;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
}
package com.yeejoin.amos.safety.business.vo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
/**
*
* <pre>
* JSON宸ュ叿绫�
* </pre>
*
* @author dell
* @version $Id: JSONUtil.java, v 0.1 2017骞�3鏈�28鏃� 涓嬪崍9:04:47 dell Exp $
*/
public class JSONUtil
{
private static Gson gson = null;
static
{
gson = new Gson();
}
public static synchronized Gson newInstance()
{
if (gson == null)
{
gson = new Gson();
}
return gson;
}
public static String toJson(Object obj)
{
return gson.toJson(obj);
}
public static <T> T toBean(String json, Class<T> clz)
{
return gson.fromJson(json, clz);
}
public static <T> Map<String, T> toMap(String json, Class<T> clz)
{
Map<String, JsonObject> map = gson.fromJson(json,
new TypeToken<Map<String, JsonObject>>() {
}.getType());
Map<String, T> result = new HashMap<>();
for (String key : map.keySet())
{
result.put(key, gson.fromJson(map.get(key), clz));
}
return result;
}
public static Map<String, Object> toMap(String json)
{
Map<String, Object> map = gson.fromJson(json,
new TypeToken<Map<String, Object>>() {
}.getType());
return map;
}
public static <T> List<T> toList(String json, Class<T> clz)
{
JsonArray array = new JsonParser().parse(json).getAsJsonArray();
List<T> list = new ArrayList<>();
for (final JsonElement elem : array)
{
list.add(gson.fromJson(elem, clz));
}
return list;
}
}
package com.yeejoin.amos.safety.business.vo;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.enums.ValuedEnum;
/**
* 操作枚举
*
* @author as-youjun
*
*/
@SuppressWarnings("all")
public final class QueryOperatorEnum extends ValuedEnum {
private static final long serialVersionUID = -375127751242109017L;
public static final int LESS_VALUE = 1; // 小于
public static final int BIGGER_VALUE = 2; // 大于
public static final int EQUAL_VALUE = 3; // 等于
public static final int LESS_EQUAL_VALUE = 4; // 小于等于
public static final int BIGGER_EQUAL_VALUE = 5; // 大于等于
public static final int NOT_EQUAL_VALUE = 6; // 不等于
public static final int IN_VALUE = 7; // 包含
public static final int LIKE_VALUE = 8; // like
public static final int OR_VALUE = 9; // 或者
public static final int ORDER_VALUE = 10; // 排序
public static final int NOT_IN_VALUE = 11; // 不包含
public static final int IS_VALUE= 12; //是
public static final QueryOperatorEnum LESS = new QueryOperatorEnum("LESS", 1, "<");
public static final QueryOperatorEnum BIGGER = new QueryOperatorEnum("BIGGER", 2, ">");
public static final QueryOperatorEnum EQUAL = new QueryOperatorEnum("EQUAL", 3, "=");
public static final QueryOperatorEnum LESS_EQUAL = new QueryOperatorEnum("LESS_EQUAL", 4, "<=");
public static final QueryOperatorEnum BIGGER_EQUAL = new QueryOperatorEnum("BIGGER_EQUAL", 5, ">=");
public static final QueryOperatorEnum NOT_EQUAL = new QueryOperatorEnum("NOT_EQUAL", 6, "<>");
public static final QueryOperatorEnum IN = new QueryOperatorEnum("IN", 7, "IN");
public static final QueryOperatorEnum LIKE = new QueryOperatorEnum("LIKE", 8, "LIKE");
public static final QueryOperatorEnum OR = new QueryOperatorEnum("OR", 9, "OR");
public static final QueryOperatorEnum ORDER_BY = new QueryOperatorEnum("ORDER BY", 10, "ORDER BY");
public static final QueryOperatorEnum NOT_IN = new QueryOperatorEnum("NOT IN", 11, "NOT IN");
public static final QueryOperatorEnum IS = new QueryOperatorEnum("IS", 12, "IS");
public String condition;
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
protected QueryOperatorEnum(String arg0, int arg1, String condition) {
super(arg0, arg1);
this.condition = condition;
}
public static QueryOperatorEnum getEnum(String name) {
try {
return ((QueryOperatorEnum) getEnum(QueryOperatorEnum.class, name));
} catch (Exception ex) {
return null;
}
}
public static QueryOperatorEnum getEnum(int name) {
try {
return ((QueryOperatorEnum) getEnum(QueryOperatorEnum.class, name));
} catch (Exception ex) {
return null;
}
}
public static Map getMap() {
try {
return getEnumMap(QueryOperatorEnum.class);
} catch (Exception ex) {
return null;
}
}
public static List getList() {
try {
return getEnumList(QueryOperatorEnum.class);
} catch (Exception ex) {
return null;
}
}
public static Iterator iterator() {
try {
return iterator(QueryOperatorEnum.class);
} catch (Exception ex) {
return null;
}
}
}
package com.yeejoin.amos.safety.business.vo;
import java.io.Serializable;
public class ReginParams implements Serializable {
private static final long serialVersionUID = 1L;
private CompanyBo company;
private RoleBo role;
private DepartmentBo department;
public CompanyBo getCompany() {
return company;
}
public void setCompany(CompanyBo company) {
this.company = company;
}
public RoleBo getRole() {
return role;
}
public void setRole(RoleBo role) {
this.role = role;
}
public DepartmentBo getDepartment() {
return department;
}
public void setDepartment(DepartmentBo department) {
this.department = department;
}
}
package com.yeejoin.amos.safety.business.vo;
public class RoleBo {
private String roleName;
private String roleType;
private String sequenceNbr;
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getRoleType() {
return roleType;
}
public void setRoleType(String roleType) {
this.roleType = roleType;
}
public String getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(String sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
}
package com.yeejoin.amos.safety.business.vo;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.Assert;
/**
* 字符串工具类
*
* @author as-youjun
*
*/
public class StringUtil {
private static Pattern NOT_ZERO_AT_THE_END = Pattern.compile("[1-9](\\d*[1-9])?");
private static Pattern numericPattern = Pattern.compile("-?[0-9]+\\.?[0-9]*");
/**
* 判断对象是否为空
*
* @param str
* @return
*/
public static boolean isNotEmpty(Object str) {
boolean flag = true;
if (str != null && !str.equals("")) {
if (str.toString().length() > 0) {
flag = true;
}
} else {
flag = false;
}
return flag;
}
/***************************************************************************
* repeat - 通过源字符串重复生成N次组成新的字符串。
*
* @param src
* - 源字符串 例如: 空格(" "), 星号("*"), "浙江" 等等...
* @param num
* - 重复生成次数
* @return 返回已生成的重复字符串
* @version 1.0 (2006.10.10) Wilson Lin
**************************************************************************/
public static String repeat(String src, int num) {
StringBuffer s = new StringBuffer();
for (int i = 0; i < num; i++)
s.append(src);
return s.toString();
}
/**
* 判断是否数字表示
*
* @param src
* 源字符串
* @return 是否数字的标志
*/
public static boolean isNumeric(String str) {
// 该正则表达式可以匹配所有的数字 包括负数
String bigStr;
try {
bigStr = new BigDecimal(str).toString();
} catch (Exception e) {
return false;// 异常 说明包含非数字。
}
Matcher isNum = numericPattern.matcher(bigStr); // matcher是全匹配
if (!isNum.matches()) {
return false;
}
return true;
}
public static int toInt(String s) {
if (s != null && !"".equals(s.trim())) {
try {
return Integer.parseInt(s);
} catch (Exception e) {
return 0;
}
}
return 0;
}
/**
* 截取前后都不是0的数字字符串
*
* 12010102 => 12010102 12010100 => 120101 ab1201100b => 12011
*
* @param str
* @return
*/
public static String delEndZero(String str) {
Matcher mat = NOT_ZERO_AT_THE_END.matcher(str);
boolean rs = mat.find();
if (rs) {
return mat.group(0);
}
return null;
}
/**
*
* <pre>
* 移除字符串后面的0
* </pre>
*
* @param s
* @return
*/
public static String removeSufixZero(String s) {
if (s == null) {
return "";
}
while (s.endsWith("0")) {
if (s.equals("0")) {
s = "";
break;
}
s = s.substring(0, s.length() - 1);
}
return s;
}
public static String transforCode(String code) {
if (code.endsWith("0000000")) {
code = code.substring(0, 1);
} else if (code.endsWith("000000")) {
code = code.substring(0, 2);
} else if (code.endsWith("0000")) {
code = code.substring(0, 4);
} else if (code.endsWith("00")) {
code = code.substring(0, 6);
}
return code;
}
}
package com.yeejoin.amos.safety.business.vo;
/**
*
* <pre>
* 自定义异常
* </pre>
*
* @author as-youjun
* @version $Id: YeeException.java, v 0.1 2017年7月18日 上午9:34:21 as-youjun Exp $
*/
public class YeeException extends RuntimeException {
/**
* <pre>
*
* </pre>
*/
private static final long serialVersionUID = -1963401137898098411L;
private int errorCode = 0;
public YeeException(int errorCode) {
this.errorCode = errorCode;
}
public YeeException(String message, int errorCode) {
super(message);
this.errorCode = errorCode;
}
public YeeException(String message) {
super(message);
}
public YeeException(String message, Throwable cause, int errorCode) {
super(message, cause);
this.errorCode = errorCode;
}
public YeeException(Throwable cause, int errorCode) {
super(cause);
this.errorCode = errorCode;
}
public YeeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace,
int errorCode) {
super(message, cause, enableSuppression, writableStackTrace);
this.errorCode = errorCode;
}
/**
* Getter method for property <tt>errorCode</tt>.
*
* @return property value of errorCode
*/
public int getErrorCode() {
return errorCode;
}
/**
* Setter method for property <tt>errorCode</tt>.
*
* @param errorCode
* value to be assigned to property errorCode
*/
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
}
package com.yeejoin.amos.safety.common.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
*
* <pre>
* 涓氬姟瀹炰綋鎶借薄绫�
* </pre>
*
* @author as-guowubin
* @version $Id: BusinessEntity.java, v 0.1 2018骞�5鏈�18鏃� 涓嬪崍2:27:17 as-guowubin Exp $
*/
@MappedSuperclass
@EntityListeners(value=AuditingEntityListener.class)
public abstract class BusinessEntity implements Serializable
{
/**
* <pre>
*
* </pre>
*/
private static final long serialVersionUID = 1L;
/**
* 鍒涘缓鏃堕棿
*/
@Column(name = "create_date",updatable = false)
private Date createDate;
/**
* 鍒涘缓鐢ㄦ埛
*/
@Column(name = "create_user",updatable = false)
private String createUser;
/**
* 鏇存柊鏃堕棿
*/
@Column(name = "update_date")
private Date updateDate;
/**
* 鏇存柊鐢ㄦ埛
*/
@Column(name = "update_user")
private String updateUser;
/**
* 鏄惁鍒犻櫎
*/
@Column(name = "is_delete")
private Boolean isDelete = false;
public Date getCreateDate()
{
return createDate;
}
public void setCreateDate(Date createDate)
{
this.createDate = createDate;
}
public String getCreateUser()
{
return createUser;
}
public void setCreateUser(String createUser)
{
this.createUser = createUser;
}
public Date getUpdateDate()
{
return updateDate;
}
public void setUpdateDate(Date updateDate)
{
this.updateDate = updateDate;
}
public String getUpdateUser()
{
return updateUser;
}
public void setUpdateUser(String updateUser)
{
this.updateUser = updateUser;
}
public Boolean getIsDelete()
{
return isDelete;
}
public void setIsDelete(Boolean isDelete)
{
this.isDelete = isDelete;
}
}
......@@ -11,7 +11,6 @@ import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Where;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.op.core.entity.BusinessEntity;
import com.yeejoin.amos.safety.business.response.RouteResponse;
import com.yeejoin.amos.safety.common.entity.dto.LinkPathDTO;
......
......@@ -6,12 +6,9 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Where;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.op.core.entity.BusinessEntity;
import com.yeejoin.amos.safety.business.response.PointInfoResponse;
import com.yeejoin.amos.safety.common.entity.dto.CoordDTO;
import com.yeejoin.amos.safety.common.entity.dto.NodeConfigDTO;
......
package com.yeejoin.amos.safety.common.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.yeejoin.amos.op.core.util.DateUtil;
import com.yeejoin.amos.safety.business.vo.DateUtil;
/**
*
* <pre>
......
......@@ -8,7 +8,8 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.yeejoin.amos.op.core.util.DateUtil;
import com.yeejoin.amos.safety.business.vo.DateUtil;
/**
*
......
......@@ -3,8 +3,7 @@ package com.yeejoin.amos.safety.common.entity;
import java.util.Date;
import java.util.List;
import com.yeejoin.amos.op.core.entity.Resource;
import com.yeejoin.amos.op.core.util.DateUtil;
import com.yeejoin.amos.safety.business.vo.DateUtil;
import com.yeejoin.amos.safety.common.entity.dto.PatrolCheckInputDTO;
/**
*
......@@ -15,7 +14,7 @@ import com.yeejoin.amos.safety.common.entity.dto.PatrolCheckInputDTO;
* @author amos
* @version $Id: RiskPoint.java, v 0.1 2019年1月4日 上午9:27:20 amos Exp $
*/
public class RiskPoint extends Resource
public class RiskPoint
{
/**
......
......@@ -7,13 +7,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.yeejoin.amos.op.core.util.DateUtil;
import com.yeejoin.amos.op.core.util.JSONUtil;
import com.yeejoin.amos.op.core.util.StringUtil;
import com.yeejoin.amos.safety.business.response.PatrolUserRespone;
import com.yeejoin.amos.safety.business.response.PointInfoResponse;
import com.yeejoin.amos.safety.business.response.RouteResponse;
import com.yeejoin.amos.safety.business.vo.DateUtil;
import com.yeejoin.amos.safety.business.vo.JSONUtil;
import com.yeejoin.amos.safety.business.vo.StringUtil;
import com.yeejoin.amos.safety.common.cache.UserPostionCache;
import com.yeejoin.amos.safety.common.entity.Link3DVo;
import com.yeejoin.amos.safety.common.entity.Node3DVo;
......
package com.yeejoin.amos.safety.core.remote.service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.yeejoin.amos.safety.business.vo.CommonResponse;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.util.MultiValueMap;
//巡检
@FeignClient(name = "${elecfire_converter_statton_patrol}",configuration=FeignConfiguration.class)
public interface AmosBankPatrol {
@RequestMapping(value = "/api/check/viewModule/initData", method = RequestMethod.GET)
CommonResponse initViewNode();
@RequestMapping(value = "/api/spc/check-detail", method = RequestMethod.POST)
CommonResponse getPatrolInfo( @RequestBody Map permissionType);
@RequestMapping(value = "/api/route/points", method = RequestMethod.POST )
CommonResponse getPointsByRouteId(@RequestBody Map permissionType);
}
package com.yeejoin.amos.safety.core.remote.service;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import feign.RequestInterceptor;
import feign.RequestTemplate;
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor{
public FeignBasicAuthRequestInterceptor() {
}
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String authToken = request.getHeader("X-Access-Token");
String appKey = request.getHeader("appKey");
String product = request.getHeader("product");
if (authToken == null)
{
authToken = request.getParameter("token");
}
template.header("toke", authToken);
template.header("X-Access-Token", authToken);
template.header("product", product);
template.header("appKey", appKey);
}
}
package com.yeejoin.amos.safety.core.remote.service;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
public class FeignConfiguration {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
@Bean
public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new FeignBasicAuthRequestInterceptor();
}
}
package com.yeejoin.amos.safety.core.remote.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import com.yeejoin.amos.op.core.common.response.CommonResponse;
import com.yeejoin.amos.op.core.util.ApplicationConfig;
import com.yeejoin.amos.op.core.util.Constants;
/**
*
* <pre>
* 巡检系统远程调用
* </pre>
*
* @author amos
* @version $Id: RemotePatrolServer.java, v 0.1 2018年12月5日 下午4:38:27 amos Exp $
*/
@Service("remotePatrolServer")
public class RemotePatrolServer
{
@Autowired
private ApplicationConfig applicationConfig;
private final RestTemplate restTemplate;
public RemotePatrolServer()
{
this.restTemplate = new RestTemplate();
}
/**
*
* <pre>
* 初始化巡检系统巡检点状态、巡检人员数据
* </pre>
*
* @return
*/
public Object initViewNode()
{
String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType
.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("X-From-Service", "true");
HttpEntity<String> formEntity = new HttpEntity<String>(headers);
CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/check/viewModule/initData",
HttpMethod.GET, formEntity, CommonResponse.class).getBody();
if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
{
return commonResponse.getDataList();
}
return null;
}
/**
*
* <pre>
* 初始化巡检系统巡检点状态、巡检人员数据
* </pre>
*
* @return
*/
public Object getPatrolInfo(String patrolId, String token)
{
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("pointID", Integer.valueOf(patrolId));
String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType
.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("X-Access-Token", token);
headers.add("X-From-Service", "true");
HttpEntity<Map<String, Integer>> formEntity = new HttpEntity<Map<String, Integer>>(map, headers);
CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/spc/check-detail",
HttpMethod.POST, formEntity, CommonResponse.class).getBody();
if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
{
return commonResponse.getDataList();
}
return null;
}
/**
*
* <pre>
* 根据线路Id查询巡检点信息
* </pre>
*
* @param routeId
* @return
*/
public Object getPointsByRouteId(List<String> routeIds, String token)
{
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("routeIDs", routeIds);
String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType
.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
headers.add("X-Access-Token", token);
headers.add("X-From-Service", "true");
HttpEntity<Map<String, List<String>>> formEntity = new HttpEntity<Map<String, List<String>>>(map, headers);
CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/route/points",
HttpMethod.POST, formEntity, CommonResponse.class).getBody();
if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
{
return commonResponse.getDataList();
}
return null;
}
}
\ No newline at end of file
//package com.yeejoin.amos.safety.core.remote.service;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.stereotype.Service;
//import org.springframework.web.client.RestTemplate;
//
//import com.yeejoin.amos.op.core.common.response.CommonResponse;
//import com.yeejoin.amos.op.core.util.ApplicationConfig;
//import com.yeejoin.amos.op.core.util.Constants;
///**
// *
// * <pre>
// * 巡检系统远程调用
// * </pre>
// *
// * @author amos
// * @version $Id: RemotePatrolServer.java, v 0.1 2018年12月5日 下午4:38:27 amos Exp $
// */
//@Service("remotePatrolServer")
//public class RemotePatrolServer
//{
// @Autowired
// private ApplicationConfig applicationConfig;
// private final RestTemplate restTemplate;
//
// public RemotePatrolServer()
// {
// this.restTemplate = new RestTemplate();
// }
//
// /**
// *
// * <pre>
// * 初始化巡检系统巡检点状态、巡检人员数据
// * </pre>
// *
// * @return
// */
// public Object initViewNode()
// {
// String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
// HttpHeaders headers = new HttpHeaders();
// MediaType type = MediaType
// .parseMediaType("application/json; charset=UTF-8");
// headers.setContentType(type);
// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
// headers.add("X-From-Service", "true");
// HttpEntity<String> formEntity = new HttpEntity<String>(headers);
// CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/check/viewModule/initData",
// HttpMethod.GET, formEntity, CommonResponse.class).getBody();
// if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
// {
// return commonResponse.getDataList();
// }
// return null;
// }
// /**
// *
// * <pre>
// * 初始化巡检系统巡检点状态、巡检人员数据
// * </pre>
// *
// * @return
// */
// public Object getPatrolInfo(String patrolId, String token)
// {
// Map<String, Integer> map = new HashMap<String, Integer>();
// map.put("pointID", Integer.valueOf(patrolId));
// String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
// HttpHeaders headers = new HttpHeaders();
// MediaType type = MediaType
// .parseMediaType("application/json; charset=UTF-8");
// headers.setContentType(type);
// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
// headers.add("X-Access-Token", token);
// headers.add("X-From-Service", "true");
// HttpEntity<Map<String, Integer>> formEntity = new HttpEntity<Map<String, Integer>>(map, headers);
// CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/spc/check-detail",
// HttpMethod.POST, formEntity, CommonResponse.class).getBody();
// if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
// {
// return commonResponse.getDataList();
// }
// return null;
// }
// /**
// *
// * <pre>
// * 根据线路Id查询巡检点信息
// * </pre>
// *
// * @param routeId
// * @return
// */
// public Object getPointsByRouteId(List<String> routeIds, String token)
// {
// Map<String, List<String>> map = new HashMap<String, List<String>>();
// map.put("routeIDs", routeIds);
// String url = applicationConfig.getParamValueStr("params.remotePatrolUrl");
// HttpHeaders headers = new HttpHeaders();
// MediaType type = MediaType
// .parseMediaType("application/json; charset=UTF-8");
// headers.setContentType(type);
// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
// headers.add("X-Access-Token", token);
// headers.add("X-From-Service", "true");
// HttpEntity<Map<String, List<String>>> formEntity = new HttpEntity<Map<String, List<String>>>(map, headers);
// CommonResponse commonResponse = (CommonResponse)restTemplate.exchange(url + "api/route/points",
// HttpMethod.POST, formEntity, CommonResponse.class).getBody();
// if (commonResponse != null && commonResponse.getResult().equals(Constants.RESULT_SUCCESS) )
// {
// return commonResponse.getDataList();
// }
// return null;
// }
//}
\ No newline at end of file
package com.yeejoin.amos.safety.core.remote.service;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.stereotype.Service;
@Service("remoteSecurityService")
public class RemoteSecurityService {
//用户id获取用户信息
public AgencyUserModel getUserById(String toke,String product,String appKey,String userId) {
if (userId == null || userId.equals("")) {
return null;
}
RequestContext.setToken(toke);
RequestContext.setProduct(product);
RequestContext.setAppKey(appKey);
AgencyUserModel agencyUserModel=null;
FeignClientResult feignClientResult;
try {
feignClientResult = Privilege.agencyUserClient.queryByUserId(userId);
agencyUserModel = (AgencyUserModel)feignClientResult.getResult();
} catch (InnerInvokException e) {
e.printStackTrace();
}
return agencyUserModel;
}
}
......@@ -8,7 +8,7 @@
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeSafety3DRoot</artifactId>
<version>1.1.0</version>
<version>3.0.0</version>
</parent>
<dependencies>
......@@ -16,7 +16,7 @@
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeSafety3DServer</artifactId>
<version>1.1.0</version>
<version>3.0.0</version>
</dependency>
</dependencies>
......
......@@ -10,9 +10,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
......@@ -26,16 +31,19 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
* @author amos
* @version $Id: AmosSafetyStart.java, v 0.1 2018年11月26日 下午4:56:29 amos Exp $
*/
@EnableHystrix
@EnableScheduling
@SpringBootApplication
@EnableTransactionManagement
@EnableConfigurationProperties
@EnableSwagger2
@ServletComponentScan
@EnableJpaAuditing
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
// @Configuration
// @EnableApolloConfig
@EnableAsync
@EnableEurekaClient
@ComponentScan({"org.typroject","com.yeejoin.amos"})
@MapperScan(basePackages = { "com.yeejoin.amos.safety.business.dao.mapper" })
public class AmosSafetyStart
{
......
spring.application.name = AmosSafety3D
eureka.client.serviceUrl.defaultZone = http://172.16.3.3:10500/eureka/
eureka.client.serviceUrl.defaultZone = http://172.16.10.72:10001/eureka/
eureka.client.register-with-eureka = true
eureka.client.fetch-registry = true
eureka.client.healthcheck.enabled = true
eureka.instance.hostname = ${spring.cloud.client.ipAddress}
eureka.instance.statusPageUrlPath = ${management.context-path}/info
eureka.instance.healthCheckUrlPath = ${management.context-path}/health
eureka.instance.preferIpAddress = true
eureka.instance.instance-id = ${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.lease-expiration-duration-in-seconds = 10
eureka.instance.lease-renewal-interval-in-seconds = 5
#eureka.instance.hostname = ${spring.cloud.client.ipAddress}
#eureka.instance.statusPageUrlPath = ${management.context-path}/info
#eureka.instance.healthCheckUrlPath = ${management.context-path}/health
#eureka.instance.preferIpAddress = true
#eureka.instance.instance-id = ${spring.cloud.client.ipAddress}:${server.port}
#eureka.instance.lease-expiration-duration-in-seconds = 10
#eureka.instance.lease-renewal-interval-in-seconds = 5
server.port = 9000
#redis
spring.redis.database=5
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=
spring.redis.jedis.pool.max-active=200
spring.redis.jedis.pool.max-wait=-1
spring.redis.jedis.pool.max-idle=10
spring.redis.jedis.pool.min-idle=0
spring.redis.timeout=1000
elecfire_converter_statton_patrol=YEEAMOSPATROL-MY99
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#DB properties:
spring.datasource.url = jdbc:mysql://172.16.11.33:3306/fire_auto_system?useSSL=false&&allowMultiQueries=true
spring.datasource.username = root
......@@ -48,7 +64,7 @@ mybatis.mapper-locations = classpath:db/mapper/*.xml
mybatis.type-aliases-package = com.yeejoin.amos.op.business.entity.mybatis
#liquibase
liquibase.change-log = classpath:/db/changelog/changelog-master.xml
spring.liquibase.change-log = classpath:/db/changelog/changelog-master.xml
params.remoteurl=http://127.0.0.1:8800/
params.time = 5
params.period = 1800
......
......@@ -4,14 +4,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeSafety3DRoot</artifactId>
<version>1.1.0</version>
<version>3.0.0</version>
<packaging>pom</packaging>
<name>YeeSafety3DRoot</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<version>2.1.6.RELEASE</version>
</parent>
<modules>
......@@ -19,21 +19,22 @@
<module>YeeSafety3DServer</module>
</modules>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<liquibase.version>3.5.3</liquibase.version>
<liquibase.version>3.6.3</liquibase.version>
<swagger.version>2.7.0</swagger.version>
<spring-cloud.version>Dalston.SR5</spring-cloud.version>
<YeeSecurity.version>2.0.3</YeeSecurity.version>
<YeeOp.version>2.0.2</YeeOp.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<YeeSecurity.version>2.1.0</YeeSecurity.version>
<YeeOp.version>2.0.1</YeeOp.version>
<maven-jar-plugin.version>3.0.0</maven-jar-plugin.version>
</properties>
<dependencies>
<dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -41,12 +42,13 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- Swagger2模块 -->
<dependency>
<groupId>io.springfox</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment