Commit 3d666afb by 张晓

Merge branch 'develop' of https://gitlab.dituhui.com/bsh/project/project into develop

2 parents a259e141 93b096b4
Showing with 61 additions and 758 deletions
...@@ -105,7 +105,6 @@ ...@@ -105,7 +105,6 @@
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -116,7 +115,7 @@ ...@@ -116,7 +115,7 @@
<dependency> <dependency>
<groupId>org.optaplanner</groupId> <groupId>org.optaplanner</groupId>
<artifactId>optaplanner-persistence-jackson</artifactId> <artifactId>optaplanner-persistence-jackson</artifactId>
<version>9.38.0.Final</version> <version>${version.org.optaplanner}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
...@@ -130,7 +129,6 @@ ...@@ -130,7 +129,6 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.0</version>
</dependency> </dependency>
......
...@@ -18,11 +18,6 @@ public class UserAuthInfo implements Serializable { ...@@ -18,11 +18,6 @@ public class UserAuthInfo implements Serializable {
private String userId; private String userId;
/** /**
* 团队id
*/
private String teamId;
/**
* 用户名称 * 用户名称
*/ */
private String userName; private String userName;
...@@ -37,9 +32,8 @@ public class UserAuthInfo implements Serializable { ...@@ -37,9 +32,8 @@ public class UserAuthInfo implements Serializable {
*/ */
private String role; private String role;
public UserAuthInfo(String userId, String teamId, String userName, String password, String role) { public UserAuthInfo(String userId, String userName, String password, String role) {
this.userId = userId; this.userId = userId;
this.teamId = teamId;
this.userName = userName; this.userName = userName;
this.password = password; this.password = password;
this.role = role; this.role = role;
......
...@@ -97,14 +97,5 @@ public class UserInfo { ...@@ -97,14 +97,5 @@ public class UserInfo {
* 更新时间 * 更新时间
*/ */
private Date updatedTime; private Date updatedTime;
/**
* 团队ID
*/
private String teamId;
/**
* 团队信息
*/
private TeamInfo teamInfo;
} }
...@@ -78,9 +78,9 @@ ...@@ -78,9 +78,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>org.gavaghan</groupId>
<artifactId>project-dispatch</artifactId> <artifactId>geodesy</artifactId>
<version>${revision}</version> <version>1.1.3</version>
</dependency> </dependency>
<dependency> <dependency>
......
package com.dituhui.pea.order.common;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
public class Distance {
public long calculateDistance(double lat1, double lnt1, double lat2, double lnt2) {
GlobalCoordinates source = new GlobalCoordinates(lat1, lnt1);
GlobalCoordinates target = new GlobalCoordinates(lat2, lnt2);
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, source, target);
return Math.round(geoCurve.getEllipsoidalDistance());
}
}
package com.dituhui.pea.order.common; package com.dituhui.pea.order.common;
import com.dituhui.pea.dispatch.pojo.Location;
import com.dituhui.pea.order.dao.EngineerBusinessMPDao; import com.dituhui.pea.order.dao.EngineerBusinessMPDao;
import com.dituhui.pea.order.dao.OrderAppointmentMPDao; import com.dituhui.pea.order.dao.OrderAppointmentMPDao;
import com.dituhui.pea.order.dao.OrderRequestMPDao; import com.dituhui.pea.order.dao.OrderRequestMPDao;
...@@ -9,7 +8,6 @@ import com.dituhui.pea.order.entity.EngineerBusiness; ...@@ -9,7 +8,6 @@ import com.dituhui.pea.order.entity.EngineerBusiness;
import com.dituhui.pea.order.entity.OrderAppointment; import com.dituhui.pea.order.entity.OrderAppointment;
import com.dituhui.pea.order.entity.OrderRequest; import com.dituhui.pea.order.entity.OrderRequest;
import com.dituhui.pea.order.entity.SkillInfo; import com.dituhui.pea.order.entity.SkillInfo;
import com.dituhui.pea.dispatch.common.GeoDistanceCalculator;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -185,16 +183,13 @@ public class OrderAssignCheck { ...@@ -185,16 +183,13 @@ public class OrderAssignCheck {
} }
private Pair getDistanceAndDuration(double x1, double y1, double x2, double y2){ private Pair getDistanceAndDuration(double x1, double y1, double x2, double y2){
Location from = new Location(1, "1", "1", x1, y1); Distance cal= new Distance();
Location to = new Location(2, "2", "2", x2, y2); long distance = Math.round(cal.calculateDistance(x1, y1, x2, y2) * 1.4); // 单位为米
GeoDistanceCalculator cal= new GeoDistanceCalculator(); long duration = distance / (19 * 1000 / 60); // 时间为分钟,假设电动车速度为19km/h
int distance = (int) cal.calculateDistance(from, to); // 单位为米 return new Pair((int)distance, (int)duration);
int duration = distance / (19 * 1000 / 60); // 时间为分钟,假设电动车速度为19km/h
return new Pair(distance, duration);
} }
} }
@Data @Data
class OrderSegment{ class OrderSegment{
private String orderId; private String orderId;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<properties> <properties>
<druid.version>1.1.10</druid.version> <druid.version>1.1.10</druid.version>
<mysql.version>8.0.28</mysql.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -93,10 +94,10 @@ ...@@ -93,10 +94,10 @@
<version>2.2.5.RELEASE</version> <version>2.2.5.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>mysql</groupId>
<artifactId>postgresql</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency> </dependency>
<!-- temp --> <!-- temp -->
......
package com.dituhui.pea.user.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.UserInfo;
import com.dituhui.pea.user.ITeam;
import com.dituhui.pea.user.entity.TeamEntity;
import com.dituhui.pea.user.service.TeamService;
import com.dituhui.pea.pojo.WebResult;
import com.dituhui.pea.pojo.TeamInfo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
*
* 团队控制层
* @author zl
* @since 2020-12-09 15:42:00
*
*/
@RestController
@RefreshScope
public class TeamController implements ITeam {
private static final Logger logger = LoggerFactory.getLogger(TestController.class);
@Autowired
TeamService teamService;
@Override
public WebResult<TeamInfo> queryById(String teamId) {
if (StringUtils.isBlank(teamId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
TeamInfo teamInfo = teamService.queryTeamById(teamId);
return WebResult.ok(teamInfo);
}
@Override
public WebResult<TeamInfo> queryByAppKey(String ak) {
if (StringUtils.isBlank(ak)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
TeamInfo teamInfo = teamService.queryTeamByAppKey(ak);
return WebResult.ok(teamInfo);
}
@Override
public WebResult<TeamInfo> addTeam(@Validated TeamInfo teamInfo) {
TeamEntity teamEntity = BeanUtil.copyProperties(teamInfo, TeamEntity.class);
teamInfo = teamService.saveTeam(teamEntity);
return WebResult.ok(teamInfo);
}
@Override
public WebResult<TeamInfo> updateTeam(TeamInfo teamInfo) {
if (ObjectUtil.isNull(teamInfo)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
if (StringUtils.isBlank(teamInfo.getId())){
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
teamInfo = teamService.updateTeam(teamInfo);
return WebResult.ok(teamInfo);
}
@Override
public WebResult<Boolean> deleteTeam(String teamId) {
if (StringUtils.isBlank(teamId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
teamService.deleteTeam(teamId);
return WebResult.ok();
}
@Override
public WebResult<Boolean> addTeamUser(String teamId, String userId) {
if (StringUtils.isBlank(teamId) && StringUtils.isBlank(userId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
teamService.saveTeamUser(teamId, userId);
return WebResult.ok();
}
@Override
public WebResult<Boolean> deleteTeamUser(String teamId, String userId) {
if (StringUtils.isBlank(teamId) && StringUtils.isBlank(userId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
teamService.deleteTeamUser(teamId,userId);
return WebResult.ok();
}
@Override
public WebResult<List<UserInfo>> getTeamUser(String teamId) {
if (StringUtils.isBlank(teamId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
List<UserInfo> teamUserList = teamService.getTeamUserList(teamId);
return WebResult.ok(teamUserList);
}
@Override
public WebResult<List<RoleInfo>> getTeamRole(String teamId) {
if (StringUtils.isBlank(teamId)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
List<RoleInfo> teamRoleList = teamService.getTeamRoleList(teamId);
return WebResult.ok(teamRoleList);
}
}
...@@ -8,9 +8,7 @@ import com.dituhui.pea.enums.ThirdPartyEnum; ...@@ -8,9 +8,7 @@ import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.pojo.*; import com.dituhui.pea.pojo.*;
import com.dituhui.pea.user.IUser; import com.dituhui.pea.user.IUser;
import com.dituhui.pea.user.commom.RedisService; import com.dituhui.pea.user.commom.RedisService;
import com.dituhui.pea.user.service.TeamService;
import com.dituhui.pea.user.service.UserService; import com.dituhui.pea.user.service.UserService;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -30,25 +28,13 @@ public class UserController implements IUser { ...@@ -30,25 +28,13 @@ public class UserController implements IUser {
private UserService userService; private UserService userService;
@Autowired @Autowired
TeamService teamService;
@Autowired
private CurrentUser currentUser;
@Autowired
private RedisService redisService; private RedisService redisService;
@Override @Override
public WebResult<UserInfo> getCurrentUserInfo(String userToken, Boolean needTeamInfo) { public WebResult<UserInfo> getCurrentUserInfo(String userToken, Boolean needTeamInfo) {
UserAuthInfo userInfoCache = getUserAuthInfoFromToken(userToken); UserAuthInfo userInfoCache = getUserAuthInfoFromToken(userToken);
String userId = userInfoCache.getUserId(); String userId = userInfoCache.getUserId();
String teamId = userInfoCache.getTeamId();
UserInfo userInfo = userService.queryUserById(userId); UserInfo userInfo = userService.queryUserById(userId);
if (BooleanUtils.isTrue(needTeamInfo)) {
TeamInfo teamInfo = teamService.queryTeamById(teamId);
userInfo.setTeamInfo(teamInfo);
userInfo.setTeamId(teamId);
}
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
...@@ -78,8 +64,6 @@ public class UserController implements IUser { ...@@ -78,8 +64,6 @@ public class UserController implements IUser {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY); return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
} }
UserInfo userInfo = userService.queryTeamByAccount(account); UserInfo userInfo = userService.queryTeamByAccount(account);
// 补充团队信息
fillTemInfo(userInfo);
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
...@@ -91,32 +75,15 @@ public class UserController implements IUser { ...@@ -91,32 +75,15 @@ public class UserController implements IUser {
} }
UserInfo userInfo = userService.queryUserByPhone(phone); UserInfo userInfo = userService.queryUserByPhone(phone);
System.out.println("queryUserByPhone UserInfo ["+userInfo+"]"); System.out.println("queryUserByPhone UserInfo ["+userInfo+"]");
// 补充团队信息
fillTemInfo(userInfo);
System.out.println("queryUserByPhone fillTemInfo UserInfo ["+userInfo+"]");
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
/**
* 补充团队信息
*
* @param userInfo
*/
private void fillTemInfo(UserInfo userInfo) {
if (StringUtils.isNotEmpty(userInfo.getTeamId())) {
TeamInfo teamInfo = teamService.queryTeamById(userInfo.getTeamId());
userInfo.setTeamInfo(teamInfo);
}
}
@Override @Override
public WebResult<UserInfo> queryUserByThirdParty(String id, ThirdPartyEnum type) { public WebResult<UserInfo> queryUserByThirdParty(String id, ThirdPartyEnum type) {
if (StringUtils.isBlank(id)) { if (StringUtils.isBlank(id)) {
return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY); return WebResult.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
} }
UserInfo userInfo = userService.queryUserByThirdParty(id, type); UserInfo userInfo = userService.queryUserByThirdParty(id, type);
// 补充团队信息
fillTemInfo(userInfo);
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
...@@ -159,16 +126,12 @@ public class UserController implements IUser { ...@@ -159,16 +126,12 @@ public class UserController implements IUser {
@Override @Override
public WebResult<UserInfo> register(@Validated UserInfo userInfo) { public WebResult<UserInfo> register(@Validated UserInfo userInfo) {
userInfo = userService.register(userInfo); userInfo = userService.register(userInfo);
// 补充团队信息
fillTemInfo(userInfo);
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
@Override @Override
public WebResult<UserInfo> thirdRegister(ThirdUserInfo thirdUserInfo) { public WebResult<UserInfo> thirdRegister(ThirdUserInfo thirdUserInfo) {
UserInfo userInfo = userService.thirdRegister(thirdUserInfo); UserInfo userInfo = userService.thirdRegister(thirdUserInfo);
// 补充团队信息
fillTemInfo(userInfo);
return WebResult.ok(userInfo); return WebResult.ok(userInfo);
} }
......
package com.dituhui.pea.user.dao;
import com.dituhui.pea.user.entity.TeamEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
/**
* 团队表(Team)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:34:36
*/
public interface TeamDao extends JpaRepository<TeamEntity, String>,
JpaSpecificationExecutor<TeamEntity>, CrudRepository<TeamEntity, String> {
/**
* 查询团队信息
*
* @param ak 团队ak
* @return
*/
TeamEntity findByAppKey(String ak);
}
package com.dituhui.pea.user.dao;
import com.dituhui.pea.user.entity.UserTeamEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* 用户所属团队表(UserTeam)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:34:53
*/
public interface UserTeamDao extends JpaRepository<UserTeamEntity, String>,
JpaSpecificationExecutor<UserTeamEntity>, CrudRepository<UserTeamEntity, String> {
/**
* 根据用户ID查询
* @param userId 用户ID
* @return
*/
UserTeamEntity findByUserId(String userId);
/**
* 根据用户ID查询
*
* @param userId 用户ID
* @param status 状态
* @return
*/
List<UserTeamEntity> findAllByUserIdAndStatusOrderByCreatedByDesc(String userId, int status);
/**
* 根据团队Id和用户ID查询
* @param userId 用户ID
* @param teamId 团队ID
* @return
*/
UserTeamEntity findByUserIdAndTeamId(String userId, String teamId);
/**
* 根据用户ID删除
* @param userId 用户ID
*/
void deleteByUserId(String userId);
/**
* 根据团队ID查询
* @param teamId 团队ID
* @return
*/
List<UserTeamEntity> findByTeamId(String teamId);
/**
* 根据teamId删除
* @param teamId 团队Id
*/
void deleteByTeamId(String teamId);
/**
* 根据团队和用户删除
* @param teamId 团队ID
* @param userId 用户ID
*/
void deleteByTeamIdAndUserId(String teamId, String userId);
}
...@@ -14,12 +14,10 @@ import java.util.Date; ...@@ -14,12 +14,10 @@ import java.util.Date;
/** /**
* 资源表 用户对某种具体权限或者功能的描述(ResourceEntity)实体类 * 资源表 用户对某种具体权限或者功能的描述(ResourceEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:13:43
*/ */
@Data @Data
@Entity @Entity
@Table(name ="resource") @Table(name = "sys_resource")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class ResourceEntity implements Serializable { public class ResourceEntity implements Serializable {
private static final long serialVersionUID = 157258775707540233L; private static final long serialVersionUID = 157258775707540233L;
...@@ -43,11 +41,10 @@ public class ResourceEntity implements Serializable { ...@@ -43,11 +41,10 @@ public class ResourceEntity implements Serializable {
@Column(name = "extra") @Column(name = "extra")
private String extra; private String extra;
/** /**
* 团队id * 资源类型1菜单2功能点3所属组织
*/ */
@Column(name = "team_id") @Column(name = "type")
@NotBlank(message = "团队名称不能为空!") private Integer type;
private String teamId;
/** /**
* 描述 * 描述
*/ */
......
...@@ -14,12 +14,10 @@ import java.util.Date; ...@@ -14,12 +14,10 @@ import java.util.Date;
/** /**
* 角色表(RoleEntity)实体类 * 角色表(RoleEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:13:27
*/ */
@Data @Data
@Entity @Entity
@Table(name ="role") @Table(name ="sys_role")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class RoleEntity implements Serializable { public class RoleEntity implements Serializable {
private static final long serialVersionUID = -71423293715769828L; private static final long serialVersionUID = -71423293715769828L;
...@@ -38,12 +36,6 @@ public class RoleEntity implements Serializable { ...@@ -38,12 +36,6 @@ public class RoleEntity implements Serializable {
@NotBlank(message = "角色名称不能为空!") @NotBlank(message = "角色名称不能为空!")
private String name; private String name;
/** /**
* 团队id
*/
@Column(name = "team_id")
@NotBlank(message = "团队Id不能为空!")
private String teamId;
/**
* 角色组id * 角色组id
*/ */
@Column(name = "group_id") @Column(name = "group_id")
......
...@@ -10,12 +10,10 @@ import java.util.Date; ...@@ -10,12 +10,10 @@ import java.util.Date;
/** /**
* 角色组表(RoleGroupEntity)实体类 * 角色组表(RoleGroupEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:13:18
*/ */
@Data @Data
@Entity @Entity
@Table(name ="role_group") @Table(name ="sys_role_group")
public class RoleGroupEntity implements Serializable { public class RoleGroupEntity implements Serializable {
private static final long serialVersionUID = -66824982136301845L; private static final long serialVersionUID = -66824982136301845L;
/** /**
...@@ -37,11 +35,6 @@ public class RoleGroupEntity implements Serializable { ...@@ -37,11 +35,6 @@ public class RoleGroupEntity implements Serializable {
@Column(name = "description") @Column(name = "description")
private String description; private String description;
/** /**
* 团队id
*/
@Column(name = "team_id")
private String teamId;
/**
* 创建人 * 创建人
*/ */
@Column(name = "CREATED_BY") @Column(name = "CREATED_BY")
......
...@@ -10,12 +10,10 @@ import java.util.Date; ...@@ -10,12 +10,10 @@ import java.util.Date;
/** /**
* 角色资源表(RoleResourceEntity)实体类 * 角色资源表(RoleResourceEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:13:05
*/ */
@Data @Data
@Entity @Entity
@Table(name ="role_resource") @Table(name ="sys_role_resource")
public class RoleResourceEntity implements Serializable { public class RoleResourceEntity implements Serializable {
private static final long serialVersionUID = -10273487455832697L; private static final long serialVersionUID = -10273487455832697L;
/** /**
......
package com.dituhui.pea.user.entity;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* 团队表(TeamEntity)实体类
*
* @author zl
* @since 2020-12-09 15:16:29
*/
@Data
@Entity
@Table(name ="team")
@EntityListeners(AuditingEntityListener.class)
public class TeamEntity implements Serializable {
private static final long serialVersionUID = 959077359004482022L;
/**
* 主键
*/
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "ID", unique = true, nullable = false, length = 32)
private String id;
/**
* 名称
*/
@Column(name = "name")
@NotNull(message = "团队名称不能为空!")
private String name;
/**
* 到期时间
*/
@Column(name = "expire_date")
@NotNull(message = "团队到期时间不能为空!")
private Date expireDate;
/**
* 是否签约
*/
@Column(name = "contract")
@NotNull(message = "团队签约状态不能为空!")
private Integer contract;
/**
* ak
*/
@Column(name = "app_key")
@NotNull(message = "团队ak不能为空!")
private String appKey;
/**
* 密钥
*/
@NotNull(message = "团队secret不能为空!")
@Column(name = "secret")
private String secret;
/**
* 公司图标
*/
@Column(name = "logo")
private String logo;
/**
* 所属行业
*/
@Column(name = "business")
private String business;
/**
* 所属省
*/
@Column(name = "province")
private String province;
/**
* 所属市
*/
@Column(name = "city")
private String city;
/**
* 所属区县
*/
@Column(name = "county")
private String county;
/**
* 人数
*/
@Column(name = "size")
private String size;
/**
* 公司地址
*/
@Column(name = "address")
private String address;
/**
* 营业执照
*/
@Column(name = "charter")
private String charter;
/**
* 团队自定义条件
*/
@Column(name = "extra")
private String extra;
/**
* 创始人用户id
*/
@Column(name = "admin_id")
private String adminId;
/**
* 创建人
*/
@Column(name = "CREATED_BY")
private String createdBy;
/**
* 创建时间
*/
@Column(name = "CREATED_TIME")
@CreatedDate
private Date createdTime;
/**
* 更新人
*/
@Column(name = "UPDATED_BY")
private String updatedBy;
/**
* 更新时间
*/
@Column(name = "UPDATED_TIME")
@LastModifiedDate
private Date updatedTime;
}
...@@ -13,12 +13,10 @@ import java.util.Date; ...@@ -13,12 +13,10 @@ import java.util.Date;
/** /**
* 用户表(UserEntity)实体类 * 用户表(UserEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:11:38
*/ */
@Data @Data
@Entity @Entity
@Table(name ="user") @Table(name ="sys_user")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class UserEntity implements Serializable { public class UserEntity implements Serializable {
private static final long serialVersionUID = 595672857439664430L; private static final long serialVersionUID = 595672857439664430L;
...@@ -84,16 +82,6 @@ public class UserEntity implements Serializable { ...@@ -84,16 +82,6 @@ public class UserEntity implements Serializable {
@Column(name = "LAST_LOGIN_TIME") @Column(name = "LAST_LOGIN_TIME")
private Date lastLoginTime; private Date lastLoginTime;
/** /**
* 微博唯一识别id
*/
@Column(name = "weibo")
private String weibo;
/**
* qq唯一识别id
*/
@Column(name = "qq")
private String qq;
/**
* 微信小程序识别id * 微信小程序识别id
*/ */
@Column(name = "wechat_mini_program") @Column(name = "wechat_mini_program")
......
...@@ -14,12 +14,10 @@ import java.util.Date; ...@@ -14,12 +14,10 @@ import java.util.Date;
/** /**
* 用户角色关系表(UserRoleEntity)实体类 * 用户角色关系表(UserRoleEntity)实体类
* *
* @author zl
* @since 2020-12-09 15:12:06
*/ */
@Data @Data
@Entity @Entity
@Table(name ="user_role") @Table(name ="sys_user_role")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class UserRoleEntity implements Serializable { public class UserRoleEntity implements Serializable {
private static final long serialVersionUID = -30812324643312481L; private static final long serialVersionUID = -30812324643312481L;
......
package com.dituhui.pea.user.entity;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* 用户所属团队表(UserTeamEntity)实体类
*
* @author zl
* @since 2020-12-09 15:12:19
*/
@Data
@Entity
@Table(name ="user_team")
@EntityListeners(AuditingEntityListener.class)
public class UserTeamEntity implements Serializable {
private static final long serialVersionUID = 544874589204245131L;
/**
* 主键
*/
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "ID", unique = true, nullable = false, length = 32)
private String id;
/**
* 用户id
*/
@Column(name = "user_id")
@NotNull(message = "用户ID为空")
private String userId;
/**
* 团队id
*/
@Column(name = "team_id")
@NotNull(message = "团队ID为空")
private String teamId;
/**
* 状态
*/
@Column(name = "status")
@NotNull(message = "用户状态为空")
private Integer status;
/**
* 创建人
*/
@Column(name = "CREATED_BY")
private String createdBy;
/**
* 创建时间
*/
@Column(name = "CREATED_TIME")
@CreatedDate
private Date createdTime;
/**
* 更新人
*/
@Column(name = "UPDATED_BY")
private String updatedBy;
/**
* 更新时间
*/
@Column(name = "UPDATED_TIME")
@LastModifiedDate
private Date updatedTime;
}
package com.dituhui.pea.user.factory;
import com.dituhui.pea.user.entity.UserEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* QqThirdStrategy
*
* @author zhouyun
* 2021/5/21 15:08
* <p>Company: 成都地图慧科技有限公司</p>
*/
@Component("QQ")
public class QqThirdStrategy extends AbstractThirdStrategy {
@Override
public UserEntity getUser(String id) {
List<UserEntity> allUserEntityList = userDao.findByQq(id);
if (CollectionUtils.isEmpty(allUserEntityList)) {
return null;
}
// 如果存在多个qq用户 默认取第一个
return allUserEntityList.get(0);
}
}
package com.dituhui.pea.user.factory;
import com.dituhui.pea.user.entity.UserEntity;
import org.springframework.stereotype.Component;
/**
* WeiboThirdStrategy
*
* @author zhouyun
* 2021/5/21 15:09
* <p>Company: 成都地图慧科技有限公司</p>
*/
@Component("WEIBO")
public class WeiboThirdStrategy extends AbstractThirdStrategy{
@Override
public UserEntity getUser(String id) {
return userDao.findByWeibo(id).orElse(null);
}
}
...@@ -79,7 +79,7 @@ public class RoleService { ...@@ -79,7 +79,7 @@ public class RoleService {
throw new BusinessException(StatusCodeEnum.ROLE_RESOURCE_EMPTY); throw new BusinessException(StatusCodeEnum.ROLE_RESOURCE_EMPTY);
} }
// 保存用户角色关系 // 保存用户角色关系
UserRoleEntity userRoleEntity = assembleUserRoleEntity(roleId, userId, roleEntity.getTeamId()); UserRoleEntity userRoleEntity = assembleUserRoleEntity(roleId, userId);
userRoleDao.save(userRoleEntity); userRoleDao.save(userRoleEntity);
} }
...@@ -173,11 +173,10 @@ public class RoleService { ...@@ -173,11 +173,10 @@ public class RoleService {
} }
private UserRoleEntity assembleUserRoleEntity(String roleId, String userId, String teamId) { private UserRoleEntity assembleUserRoleEntity(String roleId, String userId) {
UserRoleEntity userRoleEntity = new UserRoleEntity(); UserRoleEntity userRoleEntity = new UserRoleEntity();
userRoleEntity.setRoleId(roleId); userRoleEntity.setRoleId(roleId);
userRoleEntity.setUserId(userId); userRoleEntity.setUserId(userId);
userRoleEntity.setTeamId(teamId);
return userRoleEntity; return userRoleEntity;
} }
......
package com.dituhui.pea.user.service; package com.dituhui.pea.user.service;
import cn.hutool.core.bean.BeanUtil; import java.util.Date;
import cn.hutool.core.collection.CollUtil; import java.util.List;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator; import javax.persistence.criteria.Path;
import cn.hutool.core.util.IdUtil; import javax.persistence.criteria.Predicate;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil; import org.apache.commons.lang.StringUtils;
import com.dituhui.pea.constants.TeamConstant; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dituhui.pea.enums.StatusCodeEnum; import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.enums.TeamContractEnum;
import com.dituhui.pea.enums.ThirdPartyEnum; import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.enums.UserStatusEnum;
import com.dituhui.pea.exception.BusinessException; import com.dituhui.pea.exception.BusinessException;
import com.dituhui.pea.pojo.ThirdUserInfo; import com.dituhui.pea.pojo.ThirdUserInfo;
import com.dituhui.pea.pojo.UserInfo; import com.dituhui.pea.pojo.UserInfo;
import com.dituhui.pea.user.constant.TextConstant; import com.dituhui.pea.user.constant.TextConstant;
import com.dituhui.pea.user.dao.TeamDao;
import com.dituhui.pea.user.dao.UserDao; import com.dituhui.pea.user.dao.UserDao;
import com.dituhui.pea.user.dao.UserTeamDao;
import com.dituhui.pea.user.entity.TeamEntity;
import com.dituhui.pea.user.entity.UserEntity; import com.dituhui.pea.user.entity.UserEntity;
import com.dituhui.pea.user.entity.UserTeamEntity;
import com.dituhui.pea.user.factory.ThirdStrategy; import com.dituhui.pea.user.factory.ThirdStrategy;
import com.dituhui.pea.user.factory.ThirdStrategyFactory; import com.dituhui.pea.user.factory.ThirdStrategyFactory;
import com.dituhui.pea.user.utils.TextHelper; import com.dituhui.pea.user.utils.TextHelper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.*; import cn.hutool.core.bean.BeanUtil;
import java.util.Date; import cn.hutool.core.collection.CollUtil;
import java.util.List; import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
/** /**
* 用户业务层 * 用户业务层
...@@ -43,20 +37,12 @@ import java.util.List; ...@@ -43,20 +37,12 @@ import java.util.List;
@Service @Service
public class UserService { public class UserService {
@Autowired @Autowired
UserDao userDao; UserDao userDao;
@Autowired @Autowired
TeamDao teamDao;
@Autowired
UserTeamDao userTeamDao;
@Autowired
ThirdStrategyFactory thirdStrategyFactory; ThirdStrategyFactory thirdStrategyFactory;
public String getUserName(String userId) { public String getUserName(String userId) {
return "Jown Snow " + userId; return "Jown Snow " + userId;
} }
...@@ -74,8 +60,6 @@ public class UserService { ...@@ -74,8 +60,6 @@ public class UserService {
throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST); throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST);
} }
UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class); UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class);
// 设置用户信息对应的默认团队
user.setTeamId(queryTeamByUserId(user.getId()));
return user; return user;
} }
...@@ -91,8 +75,6 @@ public class UserService { ...@@ -91,8 +75,6 @@ public class UserService {
throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST); throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST);
} }
UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class); UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class);
// 设置用户信息对应的默认团队
user.setTeamId(queryTeamByUserId(user.getId()));
return user; return user;
} }
...@@ -118,28 +100,10 @@ public class UserService { ...@@ -118,28 +100,10 @@ public class UserService {
throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST); throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST);
} }
UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class); UserInfo user = BeanUtil.copyProperties(userEntity, UserInfo.class);
// 设置用户信息对应的默认团队
user.setTeamId(queryTeamByUserId(user.getId()));
return user; return user;
} }
/** /**
* 查询用户默认团队id
*
* @param userId 用户id
* @return
*/
private String queryTeamByUserId(String userId) {
List<UserTeamEntity> userTeamEntityList = userTeamDao.findAllByUserIdAndStatusOrderByCreatedByDesc(userId,
UserStatusEnum.NORMAL.getStatus());
if (CollectionUtils.isEmpty(userTeamEntityList)) {
throw new BusinessException(StatusCodeEnum.TEAM_DOES_NOT_EXIST);
}
return userTeamEntityList.get(0).getTeamId();
}
/**
* 查询用户信息 * 查询用户信息
* @param id 用户ID * @param id 用户ID
* @return * @return
...@@ -166,16 +130,6 @@ public class UserService { ...@@ -166,16 +130,6 @@ public class UserService {
userEntity.setPassword(SecureUtil.md5(userInfo.getPassword())); userEntity.setPassword(SecureUtil.md5(userInfo.getPassword()));
// 保存用户信息 // 保存用户信息
userEntity = userDao.save(userEntity); userEntity = userDao.save(userEntity);
// 保存用户和团队的关系
String teamId = userInfo.getTeamId();
if (StringUtils.isNotBlank(teamId)) {
TeamEntity teamEntity = teamDao.findById(teamId).orElse(null);
if (ObjectUtil.isNull(teamEntity)) {
throw new BusinessException(StatusCodeEnum.TEAM_DOES_NOT_EXIST);
}
UserTeamEntity userTeamEntity = assembleUserTeamEntity(userEntity, teamEntity);
userTeamDao.save(userTeamEntity);
}
return BeanUtil.copyProperties(userEntity, UserInfo.class); return BeanUtil.copyProperties(userEntity, UserInfo.class);
} }
...@@ -204,14 +158,7 @@ public class UserService { ...@@ -204,14 +158,7 @@ public class UserService {
userEntity.setPassword(SecureUtil.md5(userInfo.getPassword())); userEntity.setPassword(SecureUtil.md5(userInfo.getPassword()));
// 保存用户信息 // 保存用户信息
userEntity = userDao.save(userEntity); userEntity = userDao.save(userEntity);
// 保存团队信息
TeamEntity teamEntity = assembleTeamEntity(userEntity);
teamEntity = teamDao.save(teamEntity);
// 保存用户团队关系表
UserTeamEntity userTeamEntity = assembleUserTeamEntity(userEntity, teamEntity);
userTeamDao.save(userTeamEntity);
userInfo.setId(userEntity.getId()); userInfo.setId(userEntity.getId());
userInfo.setTeamId(teamEntity.getId());
return userInfo; return userInfo;
} }
...@@ -225,15 +172,9 @@ public class UserService { ...@@ -225,15 +172,9 @@ public class UserService {
userEntity.setCreatedTime(new Date()); userEntity.setCreatedTime(new Date());
ThirdPartyEnum thirdPartyEnum = ThirdPartyEnum.valueOf(thirdUserInfo.getThirdType()); ThirdPartyEnum thirdPartyEnum = ThirdPartyEnum.valueOf(thirdUserInfo.getThirdType());
switch (thirdPartyEnum) { switch (thirdPartyEnum) {
case QQ:
userEntity.setQq(thirdUserInfo.getThirdId());
break;
case WECHAT: case WECHAT:
userEntity.setWechat(thirdUserInfo.getThirdId()); userEntity.setWechat(thirdUserInfo.getThirdId());
break; break;
case WEIBO:
userEntity.setWeibo(thirdUserInfo.getThirdId());
break;
case WECHAT_MINI_PROGRAM: case WECHAT_MINI_PROGRAM:
userEntity.setWechatMiniProgram(thirdUserInfo.getThirdId()); userEntity.setWechatMiniProgram(thirdUserInfo.getThirdId());
userEntity.setPhone(thirdUserInfo.getPhone()); userEntity.setPhone(thirdUserInfo.getPhone());
...@@ -252,15 +193,7 @@ public class UserService { ...@@ -252,15 +193,7 @@ public class UserService {
userEntity = userDao.save(userEntity); userEntity = userDao.save(userEntity);
// 对象转换 // 对象转换
UserInfo userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class); UserInfo userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class);
// 保存团队信息
TeamEntity teamEntity = assembleTeamEntity(userEntity);
teamEntity = teamDao.save(teamEntity);
// 保存用户团队关系表
UserTeamEntity userTeamEntity = assembleUserTeamEntity(userEntity, teamEntity);
userTeamDao.save(userTeamEntity);
userInfo.setId(userEntity.getId()); userInfo.setId(userEntity.getId());
userInfo.setTeamId(teamEntity.getId());
return userInfo; return userInfo;
} }
...@@ -276,15 +209,9 @@ public class UserService { ...@@ -276,15 +209,9 @@ public class UserService {
return null; return null;
} }
switch (thirdPartyEnum) { switch (thirdPartyEnum) {
case QQ:
userEntity.setQq(thirdId);
break;
case WECHAT: case WECHAT:
userEntity.setWechat(thirdId); userEntity.setWechat(thirdId);
break; break;
case WEIBO:
userEntity.setWeibo(thirdId);
break;
case WECHAT_MINI_PROGRAM: case WECHAT_MINI_PROGRAM:
userEntity.setWechatMiniProgram(thirdId); userEntity.setWechatMiniProgram(thirdId);
default: default:
...@@ -292,8 +219,6 @@ public class UserService { ...@@ -292,8 +219,6 @@ public class UserService {
userEntity = userDao.save(userEntity); userEntity = userDao.save(userEntity);
// 对象转换 // 对象转换
UserInfo userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class); UserInfo userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class);
UserTeamEntity userTeamEntity = userTeamDao.findByUserId(userInfo.getId());
userInfo.setTeamId(userTeamEntity.getTeamId());
return userInfo; return userInfo;
} }
...@@ -343,20 +268,6 @@ public class UserService { ...@@ -343,20 +268,6 @@ public class UserService {
if (ObjectUtil.isNull(userEntity)) { if (ObjectUtil.isNull(userEntity)) {
throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST); throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST);
} }
// 查询团队是否存在
if (StringUtils.isNotBlank(userInfo.getTeamId())) {
TeamEntity teamEntity = teamDao.findById(userInfo.getTeamId()).orElse(null);
if (ObjectUtil.isNull(teamEntity)) {
throw new BusinessException(StatusCodeEnum.TEAM_DOES_NOT_EXIST);
}
// 查询用户团队关系表 没有记录就添加
UserTeamEntity userTeamEntity =
userTeamDao.findByUserIdAndTeamId(userInfo.getId(), userInfo.getTeamId());
if (ObjectUtil.isNull(userTeamEntity)) {
userTeamEntity = assembleUserTeamEntity(userEntity, teamEntity);
userTeamDao.save(userTeamEntity);
}
}
assembleUpdateUserInfo(userInfo, userEntity); assembleUpdateUserInfo(userInfo, userEntity);
userEntity = userDao.save(userEntity); userEntity = userDao.save(userEntity);
userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class); userInfo = BeanUtil.copyProperties(userEntity, UserInfo.class);
...@@ -376,46 +287,10 @@ public class UserService { ...@@ -376,46 +287,10 @@ public class UserService {
if (ObjectUtil.isNull(userEntity)) { if (ObjectUtil.isNull(userEntity)) {
throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST); throw new BusinessException(StatusCodeEnum.USER_DOES_NOT_EXIST);
} }
// 删除用户和团队的关系
userTeamDao.deleteByUserId(userId);
// 删除用户 // 删除用户
userDao.deleteById(userId); userDao.deleteById(userId);
} }
/**
* 组装用户团队关系表
* @param userEntity 用户信息
* @param teamEntity 团队信息
* @return
*/
private UserTeamEntity assembleUserTeamEntity(UserEntity userEntity, TeamEntity teamEntity) {
UserTeamEntity userTeamEntity = new UserTeamEntity();
userTeamEntity.setUserId(userEntity.getId());
userTeamEntity.setTeamId(teamEntity.getId());
userTeamEntity.setStatus(UserStatusEnum.NORMAL.getStatus());
return userTeamEntity;
}
/**
* 组装团队信息
* @param userEntity 用户信息
* @return
*/
private TeamEntity assembleTeamEntity(UserEntity userEntity) {
// 创建团队
TeamEntity teamEntity = new TeamEntity();
teamEntity.setName(userEntity.getNickname() + TeamConstant.TEAM_NAME_SUFFIX);
teamEntity.setAdminId(userEntity.getId());
// 新建团队默认有一周时间的试用期
teamEntity.setExpireDate(DateUtil.offsetDay(new Date(), 7));
teamEntity.setContract(TeamContractEnum.NO_CONTRACT.getStatus());
teamEntity.setAppKey(IdUtil.simpleUUID());
teamEntity.setSecret(IdUtil.simpleUUID());
return teamEntity;
}
/** /**
* 校验 [账号 手机号] 是否存在 * 校验 [账号 手机号] 是否存在
* @param phone 手机号 * @param phone 手机号
......
...@@ -109,16 +109,4 @@ public class TextHelper { ...@@ -109,16 +109,4 @@ public class TextHelper {
return str.matches(regex); return str.matches(regex);
} }
/**
* 执行正则表达式
*
* @param pat 表达式
* @param str 待验证字符串
* @return 返回true, 否则为false
*/
private static boolean match(String pat, String str) {
Pattern pattern = Pattern.compile(pat);
Matcher match = pattern.matcher(str);
return match.find();
}
} }
...@@ -15,16 +15,15 @@ spring: ...@@ -15,16 +15,15 @@ spring:
file-extension: yaml file-extension: yaml
config: config:
import: import:
- optional:nacos:project-user.yaml?group=project&refreshEnabled=true
- optional:nacos:datasource-config.yaml?group=project&refreshEnabled=true
- optional:nacos:redis-config.yaml?group=project&refreshEnabled=true - optional:nacos:redis-config.yaml?group=project&refreshEnabled=true
main: main:
allow-bean-definition-overriding: true allow-bean-definition-overriding: true
datasource: datasource:
url: jdbc:postgresql://project-pg:8432/project driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: org.postgresql.Driver url: jdbc:mysql://10.10.0.54:3306/saas_aftersale_test?serverTimezone=Asia/Shanghai
username: 'postgres' username: root
password: 'postgres' password: 123456
type: com.alibaba.druid.pool.DruidDataSource
redis: redis:
database: 0 database: 0
host: redis host: redis
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!