Commit 59a23605 authored by taabe's avatar taabe

添加common包

parent c192fdeb
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-biz-common</artifactId>
<name>AMOS-BOOT-BIZ-COMMON</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<artifactId>amos-biz-boot</artifactId>
<groupId>com.amosframework.boot</groupId>
<version>1.0.0</version>
</parent>
<artifactId>amos-boot-biz-common</artifactId>
<dependencies>
</dependencies>
......
package org.amos.boot.biz.common;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package org.amos.boot.biz.common.bo;
import java.util.List;
/**
* 公司实体vo
*
* @author DELL
***/
public class CompanyBo {
private String address;
private String companyName;
private Integer companyOrgCode;
private String email;
private String landlinePhone;
private String latitude;
private String level;
private String longitude;
private String orgCode;
private Long parentId;
private Long 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 Integer getCompanyOrgCode() {
return companyOrgCode;
}
public void setCompanyOrgCode(Integer 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 Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public List<CompanyBo> getChildren() {
return children;
}
public void setChildren(List<CompanyBo> children) {
this.children = children;
}
}
package org.amos.boot.biz.common.bo;
import java.util.List;
/**
* 部门vo
*
* @author DELL
**/
public class DepartmentBo {
private String departmentName;
private String level;
private Integer deptOrgCode;
private String orgCode;
private String departmentDesc;
private Long companySeq;
private Long sequenceNbr;
private Long parentId;
private List<DepartmentBo> children;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Integer getDeptOrgCode() {
return deptOrgCode;
}
public void setDeptOrgCode(Integer 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 Long getCompanySeq() {
return companySeq;
}
public void setCompanySeq(Long companySeq) {
this.companySeq = companySeq;
}
public Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long 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 org.amos.boot.biz.common.bo;
import java.io.Serializable;
/***
*
* 用户选择保存实体类
* @author Dell
* **/
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 org.amos.boot.biz.common.bo;
/***
*
* 角色实体vo
*
* @author DELL*/
public class RoleBo {
private String roleName;
private String roleType;
private Long 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 Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
}
package org.amos.boot.biz.common.constants;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
/**
* @Description: 通用常量类
* @Author: DELL
* @Date: 2021/5/26
*/
public interface CommonConstant {
String RESULT_SUCCESS = "SUCCESS";
String RESULT_FAILURE = "FAILURE";
}
package org.amos.boot.biz.common.controller;
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 org.amos.boot.biz.common.bo.ReginParams;
import org.amos.boot.biz.common.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.TransactionSystemException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException;
import java.util.HashMap;
/**
* 基础控制器
*
* @author
*/
@ApiIgnore
@RestController
@RequestMapping("/base")
public class BaseController {
/**
* 成功返回状态
*/
protected static final String SUCCESS = "SUCCESS";
/**
* 失败返回状态
*/
protected static final String FAILED = "FAILED";
/**
* 默认页大小
*/
protected static final int DEFAULT_PAGE_SIZE = 10;
@Autowired
protected HttpServletRequest request;
@Autowired
private RedisUtils redisUtils;
/**
* 获取token
**/
protected String getToken() {
String authToken = request.getHeader("token");
if (authToken == null) {
authToken = request.getHeader("X-Access-Token");
}
return authToken;
}
/**
* 获取Product
**/
protected String getProduct() {
String product = request.getHeader("product");
if (product == null) {
product = request.getParameter("product");
}
return product;
}
/**
* 获取AppKey
**/
protected String getAppKey() {
String appKey = request.getHeader("appKey");
if (appKey == null) {
appKey = request.getParameter("appKey");
}
return appKey;
}
/**
* redi缓存选择的用户信息key
*
* @param userId
* @param token
* @return
*/
private String buildKey(String userId, String token) {
return "region_" + userId + "_" + token;
}
/**
* 用户选择信息保存redis
*/
protected void saveSelectedOrgInfo(ReginParams reginParams) {
redisUtils.set(buildKey(getUserId(), getToken()), JSONObject.toJSONString(reginParams));
}
/**
* 获取结构code
*
* @return
*/
protected String getOrgCode() {
ReginParams reginParams = getSelectedOrgInfo();
if (reginParams == null) {
return null;
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getOrgCode();
}
return null;
}
/**
* 用户选择信心redis获取
**/
protected ReginParams getSelectedOrgInfo() {
return JSONObject.parseObject(redisUtils.get(buildKey(getUserId(), getToken())).toString(), 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) {
throw new RuntimeException(e.getMessage());
}
}
return userModel;
}
/**
* 获取当前登录用户id
**/
protected String getUserId() {
String userId = null;
if (getUserInfo() != null) {
userId = getUserInfo().getUserId();
}
return userId;
}
/**
* 获取请求的cookies
*
* @return
*/
protected HashMap<String, String> getCookInfoMap() {
HashMap<String, String> map = new HashMap<String, String>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie ck : cookies) {
map.put(ck.getName(), ck.getValue());
}
}
return map;
}
/**
* 获取登录用户getLoginOrgCode
**/
protected String getLoginOrgCode(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getDepartment() != null) {
return reginParams.getDepartment().getOrgCode();
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getOrgCode();
}
return null;
}
/**
* 获取部门id
**/
protected Long getDepartmentId(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getDepartment() != null) {
return reginParams.getDepartment().getSequenceNbr();
}
return null;
}
/**
* 获取公司id
**/
protected Long getCompanyId(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getSequenceNbr();
}
return null;
}
/**
* <pre>
* 提取错误异常中的错误消息
* </pre>
*
* <p>
* 当实体类中对属相注解了以下类似的注解,需要用try.catch语句捕获异常,使用 #getErrorMessage(Exception)
* 提取出异常信息NotNull(message = "属性不能为空!")
* </p>
*
* @param e
* @return
* @see {@code NotBlank} ... NotNull、NotEmpty...
* @see {@code Valid}
*/
public String getErrorMessage(Exception e) {
StringBuilder message = new StringBuilder();
if (e instanceof TransactionSystemException) {
TransactionSystemException exception = (TransactionSystemException) e;
if (exception.getRootCause() instanceof ConstraintViolationException) {
ConstraintViolationException root = (ConstraintViolationException) exception.getRootCause();
root.getConstraintViolations().forEach(constraintViolation -> {
message.append(constraintViolation.getMessageTemplate());
});
} else {
message.append(e.getMessage());
}
} else if (e instanceof ConstraintViolationException) {
((ConstraintViolationException) e).getConstraintViolations()
.forEach(constraintViolation -> message.append(constraintViolation.getMessageTemplate()));
} else {
message.append("操作异常!");
}
return message.toString();
}
}
package org.amos.boot.biz.common.utils;
import org.amos.boot.biz.common.constants.CommonConstant;
import org.springframework.http.HttpStatus;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
*/
public class CommonResponseUtil {
public static ResponseModel success() {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_SUCCESS);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel success(Object obj) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(CommonConstant.RESULT_SUCCESS);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel success(Object obj, String message) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(message);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel failure() {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
public static ResponseModel failure(String message) {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setMessage(message);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
public static ResponseModel failure(Object obj, String message) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
}
......@@ -15,6 +15,11 @@
<artifactId>amos-boot-module-tzs-api</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-biz-common</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
</dependencies>
</project>
package org.amos.boot.module.tzs.biz;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package org.amos.boot.module.tzs.biz.controller;
import org.amos.boot.biz.common.controller.BaseController;
import org.amos.boot.biz.common.utils.CommonResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RestController
@RequestMapping("/test")
public class TestController extends BaseController {
public ResponseModel test() {
return CommonResponseUtil.success();
}
}
......@@ -16,8 +16,6 @@
</dependencies>
<modules>
<module>amos-boot-module-jcs-api</module>
<module>amos-boot-module-tzs-biz</module>
<module>amos-boot-module-api</module>
<module>amos-boot-module-biz</module>
<module>amos-boot-cloud-gateway</module>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>amos-biz-boot</artifactId>
<groupId>com.amosframework.boot</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-tzs-system</artifactId>
<name>SpecialEquipmentServiceStart</name>
<packaging>jar</packaging>
<artifactId>amos-boot-tzs-system</artifactId>
<parent>
<artifactId>amos-biz-boot</artifactId>
<groupId>com.amosframework.boot</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-tzs-biz</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-tzs-biz</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
</dependencies>
</project>
package com.yeejoin.amos;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
......@@ -23,6 +22,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
* 特种设备服务启动类
* </pre>
*
* @author DELL
*/
@SpringBootApplication
@EnableTransactionManagement
......@@ -34,13 +34,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableAsync
@EnableEurekaClient
@ComponentScan({"org.typroject","com.yeejoin.amos"})
//@MapperScan(basePackages = {"com.yeejoin.amos.patrol.service.business.dao.mapper"})
public class AmosTzsApplication
{
public class AmosTzsApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class);
public static void main( String[] args )
{
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(AmosTzsApplication.class, args);
Environment environment = context.getEnvironment();
......
#DB properties:
spring.datasource.url=jdbc:mysql://172.16.10.66:3306/safety-business-3.0.0?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root_123
\ No newline at end of file
#DB properties:
spring.datasource.url=jdbc:mysql://172.16.10.66:3306/safety-business-3.0.0?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root_123
\ No newline at end of file
spring.application.name=SPECIAL-EQUIPMENT
server.servlet.context-path=/specialEquip
server.port=10000
spring.profiles.active=dev
\ No newline at end of file
......@@ -39,7 +39,7 @@
<url>http://172.16.1.6:8081/nexus/content/repositories/maven-public/</url>
</repository>
<repository>
<id>maven-public</id>
<id>maven-public1</id>
<name>maven-public</name>
<url>http://repo.typroject.org:8081/repository/maven-public/</url>
</repository>
......
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