@@ -40,8 +40,8 @@ | |||
<dependency> | |||
<groupId>cn.hutool</groupId> | |||
<artifactId>hutool-core</artifactId> | |||
<version>5.4.4</version> | |||
<artifactId>hutool-all</artifactId> | |||
<version>5.1.0</version> | |||
</dependency> | |||
<!-- 数据库 --> | |||
<dependency> |
@@ -15,6 +15,15 @@ public class CommonConfig { | |||
* 机场地址 | |||
*/ | |||
public static String airportURL; | |||
/** | |||
* DSP地址 | |||
*/ | |||
public static String dspURL; | |||
/** | |||
* 高德KEY | |||
*/ | |||
public static String gaodeKey; | |||
/** | |||
* 机场url | |||
@@ -24,4 +33,23 @@ public class CommonConfig { | |||
public void airportURL(String url) { | |||
airportURL = url; | |||
} | |||
/** | |||
* DSPurl | |||
* @param url | |||
*/ | |||
@Value("${tuoheng.dsp-url}") | |||
public void dspURL(String url) { | |||
dspURL = url; | |||
} | |||
/** | |||
* 高德KEY赋值 | |||
* | |||
* @param key 高德KEY | |||
*/ | |||
@Value("${tuoheng.gaodeKey}") | |||
public void setGaodeKey(String key) { | |||
gaodeKey = key; | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.tuoheng.common; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Getter; | |||
/** | |||
* 业务异常 枚举 | |||
* | |||
* @Author xiaoying | |||
* @Date 2023/3/10 9:33 | |||
*/ | |||
@AllArgsConstructor | |||
public enum ServiceExceptionEnum implements ExceptionInterface { | |||
/** | |||
* 未查询到数据 | |||
*/ | |||
GET_NO_DATA(10001, "未查到该记录!"), | |||
/** | |||
* 参数为空 | |||
*/ | |||
PARAMETER_IS_NULL(10002, "参数为空!"), | |||
/** | |||
* 有效期已过 | |||
*/ | |||
EXPIRATION_DATE(11111, "该账号已过有效期,请先更改有效期再启用账号"); | |||
@Getter | |||
private final int code; | |||
@Getter | |||
private final String message; | |||
} |
@@ -0,0 +1,59 @@ | |||
package com.tuoheng.config; | |||
import com.fasterxml.jackson.databind.ObjectMapper; | |||
import com.fasterxml.jackson.databind.module.SimpleModule; | |||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | |||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | |||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; | |||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | |||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; | |||
import org.springframework.stereotype.Component; | |||
import java.math.BigInteger; | |||
import java.time.LocalDate; | |||
import java.time.LocalDateTime; | |||
import java.time.LocalTime; | |||
import java.time.format.DateTimeFormatter; | |||
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; | |||
/** | |||
* 对象映射器:序列化和反序列化时,数据格式指定。 | |||
* 本转换器继承自Jackson中提供的转换核心类ObjectMapper | |||
* 支持 | |||
* 指定格式的日期时间字符串与LocalDateTime的序列化和反序列化 | |||
* BigInteger、Long --> String的序列化 | |||
*/ | |||
@Component | |||
public class OptimizationObjectMapper extends ObjectMapper { | |||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; | |||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; | |||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss"; | |||
public OptimizationObjectMapper() { | |||
super(); | |||
// 反序列化特性:反序列化时属性不存在的兼容处理,未知属性时不报异常 | |||
this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); | |||
this.getDeserializationConfig().withoutFeatures(FAIL_ON_UNKNOWN_PROPERTIES); | |||
// 新建功能模块,并添加序列化器和反序列化器 | |||
SimpleModule simpleModule = new SimpleModule() | |||
// 添加指定规则的反序列化器 | |||
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))) | |||
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))) | |||
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT))) | |||
// 添加指定规则的序列化器 | |||
.addSerializer(BigInteger.class, ToStringSerializer.instance) | |||
// Long --> String,可以解决本案中的问题 | |||
.addSerializer(Long.class, ToStringSerializer.instance) | |||
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))) | |||
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))) | |||
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT))); | |||
//注册功能模块 | |||
this.registerModule(simpleModule); | |||
} | |||
} |
@@ -1,6 +1,8 @@ | |||
package com.tuoheng.config; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.http.converter.HttpMessageConverter; | |||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | |||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||
@@ -23,4 +25,19 @@ public class WebConfig implements WebMvcConfigurer { | |||
argumentResolvers.add(loginUserHandler); | |||
} | |||
/** | |||
* 扩展mvc框架的消息转换器 | |||
* | |||
* @param converters 转换器列表集合 | |||
*/ | |||
@Override | |||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { | |||
//创建消息转换器对象 | |||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); | |||
//设置自定义的对象转换器 | |||
converter.setObjectMapper(new OptimizationObjectMapper()); | |||
// 通过设置索引,让自己的转换器放在最前面,否则默认的jackson转换器会在前面,用不上自己配置的转换器 | |||
converters.add(0, converter); | |||
} | |||
} |
@@ -17,6 +17,7 @@ public final class CommonConstant { | |||
/** | |||
* 常用数值,符号 | |||
*/ | |||
public static final Integer ZERO = 0; | |||
public static final Integer ONE = 1; | |||
public static final Integer TWO = 2; | |||
public static final Integer THREE = 3; | |||
@@ -31,5 +32,20 @@ public final class CommonConstant { | |||
*/ | |||
public static final String SLASH = "/"; | |||
/** | |||
* 顿号 | |||
*/ | |||
public static final String SIGN = "、"; | |||
/** | |||
* 波浪号 | |||
*/ | |||
public static final String TILDE = "~"; | |||
/** | |||
* 杠号 | |||
*/ | |||
public static final String BARS = "-"; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.constant; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/8 8:49 | |||
*/ | |||
@Data | |||
public class DspConstant { | |||
public static final String DSP_CLIENT = "tuoheng-dsp"; | |||
public static final String DSP_NAME = "dsp服务平台"; | |||
/** | |||
* 获取算法的调度包行业信息及对应的算法实例 | |||
*/ | |||
public static final String FIND_EXAMPLE = "/industryServiceInst/list"; | |||
} |
@@ -33,4 +33,14 @@ public class FreeWayConstant { | |||
* 逻辑删除租户 | |||
*/ | |||
public static final String DELETE_TENANT = "/oidc/callback/tenant/deleted"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_ROLE = "/oidc/callback/getRoleList"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_MENU = "/oidc/callback/getMenuList/{roleId}"; | |||
} |
@@ -30,6 +30,18 @@ public class HhzUrlConstant { | |||
public static final String DELETE_TENANT = "/oidcTenant/delete"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_ROLE = "/oidcTenant/getRoleList"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_MENU = "/oidcTenant/getMenuList/{roleId}"; | |||
} |
@@ -27,4 +27,8 @@ public class PilotConstant { | |||
public static final String UPDATE_TENANT = "/oidcTenant/edit"; | |||
public static final String DELETE_TENANT = "/oidcTenant/delete"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_ROLE = "/oidcTenant/getRoleList"; | |||
} |
@@ -34,4 +34,13 @@ public class WaterWayConstant { | |||
* 逻辑删除租户 | |||
*/ | |||
public static final String DELETE_TENANT = "/oidc/callback/tenant/deleted"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_ROLE = "/oidc/callback/getRoleList"; | |||
/** | |||
* 查询可用角色 | |||
*/ | |||
public static final String FIND_MENU = "/oidc/callback/getMenuList/{roleId}"; | |||
} |
@@ -0,0 +1,86 @@ | |||
package com.tuoheng.controller; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.enums.MarkTypeEnum; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.tuoheng.model.query.AreaQuery; | |||
import com.tuoheng.service.AreaService; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.validation.annotation.Validated; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* (Area)表控制层 | |||
* | |||
* @author xiaoying | |||
* @since 2023-03-06 14:59:16 | |||
*/ | |||
@RestController | |||
@RequestMapping("/area") | |||
public class AreaController { | |||
/** | |||
* 服务对象 | |||
*/ | |||
@Autowired | |||
private AreaService areaService; | |||
/** | |||
* 查询区域信息 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(AreaQuery query) { | |||
return areaService.index(query); | |||
} | |||
/** | |||
* 查询存在的区域信息 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult list() { | |||
return JsonResult.success(areaService.list(Wrappers.<Area>lambdaQuery().eq(Area::getMark, MarkTypeEnum.VALID.getCode()))); | |||
} | |||
/** | |||
* 新增区域信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody @Validated Area entity, @CurrentUser LoginUser loginUser) { | |||
return areaService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 新增区域信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody @Validated Area entity, @CurrentUser LoginUser loginUser) { | |||
return areaService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 逻辑删除/批量 | |||
* | |||
* @param ids | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{ids}") | |||
public JsonResult delete(@PathVariable("ids") Long[] ids) { | |||
return areaService.deleteByIds(ids); | |||
} | |||
} | |||
@@ -0,0 +1,88 @@ | |||
package com.tuoheng.controller; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.tuoheng.model.entity.Marker; | |||
import com.tuoheng.model.query.AreaQuery; | |||
import com.tuoheng.model.query.MarkerQuery; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.service.MarkerService; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.validation.annotation.Validated; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* (Marker)表控制层 | |||
* | |||
* @author xiaoying | |||
* @since 2023-03-07 14:59:16 | |||
*/ | |||
@RestController | |||
@RequestMapping("/marker") | |||
public class MarkerController { | |||
/** | |||
* 服务对象 | |||
*/ | |||
@Autowired | |||
private MarkerService markerService; | |||
/** | |||
* 查询营销人员信息 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(MarkerQuery query) { | |||
return markerService.index(query); | |||
} | |||
/** | |||
* 根据区域id查询出对应营销人员 | |||
* @param query | |||
* @return | |||
*/ | |||
@GetMapping("/getMarkerList") | |||
public JsonResult getMarkerList(MarkerQuery query){ | |||
return markerService.getMarkerList(query); | |||
} | |||
/** | |||
* 新增营销人员信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody @Validated Marker entity, @CurrentUser LoginUser loginUser) { | |||
return markerService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 新增营销人员信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@PutMapping("/edit") | |||
public JsonResult edit(@RequestBody @Validated Marker entity, @CurrentUser LoginUser loginUser) { | |||
return markerService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 逻辑删除/批量 | |||
* @param ids | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{ids}") | |||
public JsonResult delete(@PathVariable("ids") Long[] ids) { | |||
return markerService.deleteByIds(ids); | |||
} | |||
} |
@@ -5,8 +5,10 @@ import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.OidcTenantDto; | |||
import com.tuoheng.model.param.CreateClientTenantDto; | |||
import com.tuoheng.model.query.TenantQuery; | |||
import com.tuoheng.model.query.UserQuery; | |||
import com.tuoheng.service.ClientUserSevice; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.service.TenantService; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
@@ -23,52 +25,77 @@ import org.springframework.web.bind.annotation.*; | |||
public class TenantController { | |||
@Autowired | |||
private ClientUserSevice clientUserSevice; | |||
private TenantService tenantService; | |||
@PostMapping("/create") | |||
@PostMapping("/createTenant") | |||
public JsonResult createClientTenant(@RequestBody CreateClientTenantDto createClientTenantDto, | |||
@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.createClientTenant(createClientTenantDto, loginUser); | |||
@CurrentUser LoginUser loginUser) { | |||
return tenantService.createClientTenant(createClientTenantDto, loginUser); | |||
} | |||
/** | |||
* 新增业务平台的租户基本数据 | |||
* @param dto | |||
* 查询租户列表 | |||
* | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.addTenant(dto,loginUser); | |||
@GetMapping("/list") | |||
public JsonResult list(TenantQuery query) { | |||
return tenantService.findTenants(query); | |||
} | |||
/** | |||
* 查询租户列表 | |||
* 根据id查询出租户详情 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult list(TenantQuery query){ | |||
return clientUserSevice.findTenants(query); | |||
@GetMapping("/getDetaile") | |||
public JsonResult getDetaile(TenantQuery query) { | |||
return tenantService.getDetaile(query); | |||
} | |||
/** | |||
* 查询租户下所有的用户数据 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/findUserLis") | |||
public JsonResult findUserLis(UserQuery query) { | |||
return tenantService.findUserList(query); | |||
} | |||
/** | |||
* 更新业务租户信息及密码接口 | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@PostMapping("/edit") | |||
public JsonResult edit(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.editTenant(dto,loginUser); | |||
public JsonResult edit(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) { | |||
return tenantService.editTenant(dto, loginUser); | |||
} | |||
/** | |||
* 删除租户(逻辑删除) | |||
* 更新租户状态(1 启用 0禁用) | |||
* | |||
* @return | |||
*/ | |||
@PostMapping ("/delete") | |||
public JsonResult delete(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.deleteTenant(dto,loginUser); | |||
@PostMapping("/status") | |||
public JsonResult updateStatus(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) { | |||
return tenantService.updateStatus(dto, loginUser); | |||
} | |||
/** | |||
* 重置密码 | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@PostMapping("/reset") | |||
public JsonResult resetPassward(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) { | |||
return tenantService.resetPassward(dto, loginUser); | |||
} | |||
} |
@@ -48,28 +48,4 @@ public class UserController { | |||
@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.updateUserClientRole(updateUserClientRoleDto, loginUser); | |||
} | |||
/** | |||
* 更新 用户/租户对应关系的系统or角色id | |||
* @param createClientUserDto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@PostMapping("/updateAuthorities") | |||
public JsonResult updateAuthorities(@RequestBody @Validated CreateClientUserDto createClientUserDto, | |||
@CurrentUser LoginUser loginUser){ | |||
return clientUserSevice.updateAuthorities(createClientUserDto, loginUser); | |||
} | |||
/** | |||
* 查询对应租户下的所有用户数据 | |||
* @param query | |||
* @return | |||
*/ | |||
@GetMapping("/findUserList") | |||
public JsonResult findUserList(UserQuery query){ | |||
return clientUserSevice.findUserList(query); | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
package com.tuoheng.enums; | |||
import lombok.Getter; | |||
/** | |||
* 逻辑删除标记类型 | |||
* @author chenyukun | |||
*/ | |||
public enum MarkTypeEnum { | |||
/** | |||
* 有效 | |||
*/ | |||
VALID(1,"有效"), | |||
/** | |||
* 无效 | |||
*/ | |||
NOTVALID(0,"失效"); | |||
MarkTypeEnum(int code, String description){ | |||
this.code = code; | |||
this.description = description; | |||
} | |||
@Getter | |||
private int code; | |||
@Getter | |||
private String description; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper; | |||
import com.tuoheng.model.entity.Area; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_area】的数据库操作Mapper | |||
* @createDate 2023-03-06 14:58:40 | |||
* @Entity com.tuoheng.model.entity.Area | |||
*/ | |||
@Mapper | |||
public interface AreaMapper extends BaseMapper<Area> { | |||
} | |||
@@ -1,6 +1,7 @@ | |||
package com.tuoheng.mapper; | |||
import com.tuoheng.model.po.AuthoritiesPo; | |||
import com.tuoheng.model.query.TenantQuery; | |||
import org.apache.ibatis.annotations.Mapper; | |||
import org.apache.ibatis.annotations.Param; | |||
@@ -18,4 +19,8 @@ public interface AuthoritiesMapper { | |||
List<AuthoritiesPo> selectByUserId(@Param("userId") Long userId); | |||
List<AuthoritiesPo> selectListByUserIdAndClientId(@Param("userId") Long userId, @Param("query") TenantQuery query); | |||
List<AuthoritiesPo> selectByUserIds(@Param("list") List<Long> userIdList); | |||
} |
@@ -20,4 +20,5 @@ public interface ClientUserRoleMapper { | |||
int updateUserClientRole(ClientUserRolePo clientUserRolePo); | |||
List<ClientUserRolePo> selectListByUserId(Long userId); | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper; | |||
import com.tuoheng.model.entity.Marker; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_marker】的数据库操作Mapper | |||
* @createDate 2023-03-07 15:21:36 | |||
* @Entity com.tuoheng.model.entity.Marker | |||
*/ | |||
@Mapper | |||
public interface MarkerMapper extends BaseMapper<Marker> { | |||
} | |||
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.model.entity.TenantEmploy; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_ employ】的数据库操作Mapper | |||
* @createDate 2023-03-08 14:33:40 | |||
* @Entity com.tuoheng.model.entity.Tenant employ | |||
*/ | |||
@Mapper | |||
public interface TenantEmployMapper extends BaseMapper<TenantEmploy> { | |||
} | |||
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper; | |||
import com.tuoheng.model.entity.TenantItem; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_item】的数据库操作Mapper | |||
* @createDate 2023-03-08 14:11:43 | |||
* @Entity com.tuoheng.model.entity.TenantItem | |||
*/ | |||
@Mapper | |||
public interface TenantItemMapper extends BaseMapper<TenantItem> { | |||
} | |||
@@ -24,7 +24,7 @@ public interface TenantMapper { | |||
TTenant getByCode(@Param("code") String code); | |||
IPage<TenantPo> findList(@Param("page") IPage<TenantVo> page, @Param("query") TenantQuery query); | |||
IPage<TenantVo> findList(@Param("page") IPage<TenantVo> page, @Param("query") TenantQuery query); | |||
void updateById(TenantPo tenantPo); | |||
@@ -0,0 +1,23 @@ | |||
package com.tuoheng.model.dto; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/3 17:44 | |||
*/ | |||
@Data | |||
public class ClientRoleListDto { | |||
private String clientId; | |||
/** | |||
* 平台名称 | |||
*/ | |||
private String platformName; | |||
private List<RoleDto> roleDtoList; | |||
} |
@@ -1,7 +1,10 @@ | |||
package com.tuoheng.model.dto; | |||
import com.tuoheng.model.param.ClientRoleDto; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* oidc-新增租户第三方 | |||
* @Author xiaoying | |||
@@ -22,9 +25,9 @@ public class OidcTenantDto { | |||
*/ | |||
private String tenantName; | |||
/** | |||
* 平台 | |||
* 平台集合 | |||
*/ | |||
private String clientId; | |||
private List<ClientRoleDto> clientRoleDtos; | |||
/** | |||
* 密码 | |||
*/ |
@@ -18,8 +18,8 @@ public class Platform implements Serializable { | |||
/** | |||
* 主键 | |||
*/ | |||
@TableId | |||
private String id; | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** | |||
* 平台编码 |
@@ -0,0 +1,33 @@ | |||
package com.tuoheng.model.dto; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 系统角色表 | |||
* </p> | |||
* | |||
* @author 拓恒 | |||
* @since 2020-10-31 | |||
*/ | |||
@Data | |||
public class RoleDto { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer id; | |||
/** | |||
* 角色名称 | |||
*/ | |||
private String roleName; | |||
/** | |||
* 角色标签 | |||
*/ | |||
private String code; | |||
} |
@@ -18,7 +18,7 @@ public class TTenant implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** |
@@ -0,0 +1,81 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import javax.validation.constraints.NotBlank; | |||
/** | |||
* | |||
* @TableName t_area | |||
*/ | |||
@TableName(value ="t_area") | |||
@Data | |||
public class Area implements Serializable { | |||
/** | |||
* id | |||
*/ | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Long createUser; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Long updateUser; | |||
/** | |||
* 区域名称 | |||
*/ | |||
@NotBlank(message = "分区名称不能为空") | |||
private String name; | |||
/** | |||
* 省份code(多个用逗号隔开) | |||
*/ | |||
@NotBlank(message = "省份code不能为空") | |||
private String cityCode; | |||
/** | |||
* 省份名称(多个用逗号隔开) | |||
*/ | |||
private String cityName; | |||
/** | |||
* 1:可用;0:不可使用 | |||
*/ | |||
private Integer mark; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 编辑人 | |||
*/ | |||
private String editorName; | |||
} |
@@ -0,0 +1,83 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import javax.validation.constraints.NotBlank; | |||
import javax.validation.constraints.NotNull; | |||
/** | |||
* | |||
* @TableName t_marker | |||
*/ | |||
@TableName(value ="t_marker") | |||
@Data | |||
public class Marker implements Serializable { | |||
/** | |||
* id | |||
*/ | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Long createUser; | |||
/** | |||
* 更新人 | |||
*/ | |||
private Long updateUser; | |||
/** | |||
* 人员姓名 | |||
*/ | |||
@NotBlank(message = "姓名不能为空") | |||
private String name; | |||
/** | |||
* 所属区域Id | |||
*/ | |||
@NotNull(message = "所属区域不能为空") | |||
private Long areaId; | |||
/** | |||
* 联系方式 | |||
*/ | |||
@NotBlank(message = "联系方式不能为空") | |||
private String phone; | |||
/** | |||
* 1:可用;0:不可使用 | |||
*/ | |||
private Integer mark; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 编辑人 | |||
*/ | |||
private String editorName; | |||
} |
@@ -0,0 +1,60 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import lombok.Data; | |||
/** | |||
* | |||
* @TableName t_tenant_employ | |||
*/ | |||
@TableName(value ="t_tenant_employ") | |||
@Data | |||
public class TenantEmploy implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** | |||
* | |||
*/ | |||
private Date createTime; | |||
/** | |||
* | |||
*/ | |||
private Date updateTime; | |||
/** | |||
* | |||
*/ | |||
private Long createUser; | |||
/** | |||
* | |||
*/ | |||
private Long updateUser; | |||
/** | |||
* 租户id | |||
*/ | |||
private Long tenantId; | |||
/** | |||
* 服务实例id | |||
*/ | |||
private String serviceId; | |||
/** | |||
* 业务平台对应标识 | |||
*/ | |||
private String platformCode; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -0,0 +1,87 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
/** | |||
* | |||
* @TableName t_tenant_item | |||
*/ | |||
@TableName(value ="t_tenant_item") | |||
@Data | |||
public class TenantItem implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.ASSIGN_ID) | |||
private Long id; | |||
/** | |||
* | |||
*/ | |||
private Date createTime; | |||
/** | |||
* | |||
*/ | |||
private Date updateTime; | |||
/** | |||
* | |||
*/ | |||
private Long createUser; | |||
/** | |||
* | |||
*/ | |||
private Long updateUser; | |||
/** | |||
* 销售人员id | |||
*/ | |||
private Long markerId; | |||
/** | |||
* 租户id | |||
*/ | |||
private Long tenantId; | |||
/** | |||
* 区域id | |||
*/ | |||
private Long areaId; | |||
/** | |||
* 立项编号 | |||
*/ | |||
private String projectCode; | |||
/** | |||
* 合同编号 | |||
*/ | |||
private String contractCode; | |||
/** | |||
* 项目起始时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") | |||
private Date beginTime; | |||
/** | |||
* 项目失效时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") | |||
private Date endTime; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -9,9 +9,22 @@ import lombok.Data; | |||
*/ | |||
@Data | |||
public class ClientRoleDto { | |||
/** | |||
* 平台标识 | |||
*/ | |||
private String clientId; | |||
/** | |||
* 该平台对应服务实例id(多个逗号隔开) | |||
*/ | |||
private String serviceId;; | |||
/** | |||
* 该平台对应角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 角色名 | |||
*/ | |||
private String roleName; | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.tuoheng.model.param; | |||
import com.tuoheng.model.entity.TenantItem; | |||
import lombok.Data; | |||
import javax.validation.constraints.NotEmpty; | |||
@@ -13,16 +14,69 @@ import java.util.List; | |||
*/ | |||
@Data | |||
public class CreateClientTenantDto { | |||
/** | |||
* 租户id | |||
*/ | |||
private Long id; | |||
@NotEmpty(message = "username can not be empty!") | |||
private String username; | |||
@NotEmpty(message = "password can not be empty!") | |||
private String password; | |||
private String remark; | |||
@NotNull(message = "clientRoleDtoList can not be null!") | |||
private List<ClientRoleDto> clientRoleDtoList; | |||
/** | |||
* 租户名称 | |||
*/ | |||
private String tenantName; | |||
/** | |||
* 租户code | |||
*/ | |||
private String tenantCode; | |||
/** | |||
* 省级编码 | |||
*/ | |||
private String provinceCode; | |||
/** | |||
* 省份名称 | |||
*/ | |||
private String provinceName; | |||
/** | |||
* 市区编号 | |||
*/ | |||
private String cityCode; | |||
/** | |||
* 市区名称 | |||
*/ | |||
private String cityName; | |||
/** | |||
* 区县编号 | |||
*/ | |||
private String districtCode; | |||
/** | |||
* 区县名称 | |||
*/ | |||
private String districtName; | |||
/** | |||
* 租户对应项目基本信息 | |||
*/ | |||
private TenantItem tenantItem; | |||
private String customer; | |||
private String customerPhone; | |||
private String adress; | |||
private String lng; | |||
private String lat; | |||
/** | |||
* 1 启用 0禁用 | |||
*/ | |||
private Integer status; | |||
} |
@@ -22,4 +22,6 @@ public class ClientUserRolePo extends BasePo { | |||
private Integer status; | |||
private String roleName; | |||
} |
@@ -49,5 +49,15 @@ public class TenantPo extends BasePo { | |||
*/ | |||
private String districtName; | |||
private String username; | |||
private String customer; | |||
private String customerPhone; | |||
private String adress; | |||
private String lng; | |||
private String lat; | |||
private Integer status; | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.tuoheng.model.query; | |||
import com.tuoheng.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/6 15:03 | |||
*/ | |||
@Data | |||
public class AreaQuery extends BaseQuery { | |||
/** | |||
* 分区名称 | |||
*/ | |||
private String name; | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.model.query; | |||
import com.tuoheng.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/7 15:27 | |||
*/ | |||
@Data | |||
public class MarkerQuery extends BaseQuery { | |||
/** | |||
* 人员名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 区域id | |||
*/ | |||
private Long areaId; | |||
} |
@@ -9,6 +9,10 @@ import lombok.Data; | |||
*/ | |||
@Data | |||
public class TenantQuery extends BaseQuery { | |||
/** | |||
* 租户id | |||
*/ | |||
private Long id; | |||
/** | |||
* 租户名称 | |||
*/ | |||
@@ -17,4 +21,12 @@ public class TenantQuery extends BaseQuery { | |||
* 租户账号 | |||
*/ | |||
private String username; | |||
/** | |||
* 平台标识 | |||
*/ | |||
private String clientId; | |||
/** | |||
* 状态 1启用 0禁用 | |||
*/ | |||
private Integer status; | |||
} |
@@ -0,0 +1,36 @@ | |||
package com.tuoheng.model.vo; | |||
import lombok.Data; | |||
/** | |||
* 创建租户完成返回实体类 | |||
* | |||
* @Author xiaoying | |||
* @Date 2023/3/8 15:44 | |||
*/ | |||
@Data | |||
public class CreateTenantVo { | |||
/** | |||
* 租户名称 | |||
*/ | |||
private String tenantName; | |||
/** | |||
* 租户账号 | |||
*/ | |||
private String username; | |||
/** | |||
* 密码 | |||
*/ | |||
private String password; | |||
/** | |||
* 平台名称(多个逗号分隔) | |||
*/ | |||
private String platformName; | |||
/** | |||
* 系统有效期 | |||
*/ | |||
private String effectiveDate; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Marker; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/7 15:48 | |||
*/ | |||
@Data | |||
public class MarkerVo extends Marker { | |||
/** | |||
* 所属区域名称 | |||
*/ | |||
private String areaName; | |||
} |
@@ -72,4 +72,26 @@ public class TenantVo { | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
private Long userId; | |||
/** | |||
* 1,启用 0禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 客户联系人 | |||
*/ | |||
private String customer; | |||
/** | |||
* 客户联系方式 | |||
*/ | |||
private String customerPhone; | |||
/** | |||
* 剩余天数 | |||
*/ | |||
private Long remainDays; | |||
/** | |||
* 系统有效期 | |||
*/ | |||
private String effectiveDate; | |||
} |
@@ -0,0 +1,31 @@ | |||
package com.tuoheng.service; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.query.AreaQuery; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_area】的数据库操作Service | |||
* @createDate 2023-03-06 14:58:40 | |||
*/ | |||
public interface AreaService extends IService<Area> { | |||
/** | |||
* 查询区域信息 | |||
* @param query | |||
* @return | |||
*/ | |||
JsonResult index(AreaQuery query); | |||
/** | |||
* 新增区域信息 | |||
* @param entity | |||
* @return | |||
*/ | |||
JsonResult edit(Area entity, LoginUser loginUser); | |||
JsonResult deleteByIds(Long[] ids); | |||
} |
@@ -21,38 +21,8 @@ public interface ClientUserSevice { | |||
JsonResult createClientUser(CreateClientUserDto createClientUserDto, LoginUser loginUser); | |||
JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser); | |||
JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser); | |||
JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser); | |||
/** | |||
* 新增业务平台的租户基本数据 | |||
* @param dto | |||
* @return | |||
*/ | |||
JsonResult addTenant(OidcTenantDto dto,LoginUser loginUser); | |||
JsonResult findTenants(TenantQuery query); | |||
JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser); | |||
/** | |||
* 删除租户(逻辑删除) | |||
* @return | |||
*/ | |||
JsonResult deleteTenant(OidcTenantDto dto, LoginUser loginUser); | |||
/** | |||
* 更新 用户/租户对应关系的系统or角色id | |||
* @param createClientUserDto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
JsonResult updateAuthorities(CreateClientUserDto createClientUserDto, LoginUser loginUser); | |||
/** | |||
* 查询对应租户下的所有用户数据 | |||
* @param query | |||
* @return | |||
*/ | |||
JsonResult findUserList(UserQuery query); | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.tuoheng.service; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.tuoheng.model.entity.Marker; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.query.MarkerQuery; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_marker】的数据库操作Service | |||
* @createDate 2023-03-07 15:21:37 | |||
*/ | |||
public interface MarkerService extends IService<Marker> { | |||
JsonResult index(MarkerQuery query); | |||
JsonResult edit(Marker entity, LoginUser loginUser); | |||
JsonResult deleteByIds(Long[] ids); | |||
/** | |||
* 根据区域id查询出对应营销人员 | |||
* @param query | |||
* @return | |||
*/ | |||
JsonResult getMarkerList(MarkerQuery query); | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.service; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.entity.TenantEmploy; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_ employ】的数据库操作Service | |||
* @createDate 2023-03-08 14:33:40 | |||
*/ | |||
public interface TenantEmployService extends IService<TenantEmploy> { | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.service; | |||
import com.tuoheng.model.entity.TenantItem; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_item】的数据库操作Service | |||
* @createDate 2023-03-08 14:11:43 | |||
*/ | |||
public interface TenantItemService extends IService<TenantItem> { | |||
} |
@@ -0,0 +1,55 @@ | |||
package com.tuoheng.service; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.OidcTenantDto; | |||
import com.tuoheng.model.param.CreateClientTenantDto; | |||
import com.tuoheng.model.param.CreateClientUserDto; | |||
import com.tuoheng.model.query.TenantQuery; | |||
import com.tuoheng.model.query.UserQuery; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/6 11:26 | |||
*/ | |||
public interface TenantService { | |||
JsonResult findTenants(TenantQuery query); | |||
JsonResult editTenant(CreateClientTenantDto dto, LoginUser loginUser); | |||
/** | |||
* 删除租户(逻辑删除) | |||
* @return | |||
*/ | |||
JsonResult deleteTenant(CreateClientTenantDto dto, LoginUser loginUser); | |||
/** | |||
* 更新 用户/租户对应关系的系统or角色id | |||
* @param createClientUserDto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
JsonResult updateAuthorities(CreateClientUserDto createClientUserDto, LoginUser loginUser); | |||
/** | |||
* 查询对应租户下的所有用户数据 | |||
* @param query | |||
* @return | |||
*/ | |||
JsonResult findUserList(UserQuery query); | |||
JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser); | |||
/** | |||
* 根据id查询出租户详情 | |||
* | |||
* @return | |||
*/ | |||
JsonResult getDetaile(TenantQuery query); | |||
/** | |||
* 更新租户状态(1 启用 0禁用) | |||
* @return | |||
*/ | |||
JsonResult updateStatus(CreateClientTenantDto dto, LoginUser loginUser); | |||
JsonResult resetPassward(CreateClientTenantDto dto, LoginUser loginUser); | |||
} |
@@ -0,0 +1,129 @@ | |||
package com.tuoheng.service.impl; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.constant.CommonConstant; | |||
import com.tuoheng.enums.MarkTypeEnum; | |||
import com.tuoheng.mapper.AreaMapper; | |||
import com.tuoheng.mapper.CityMapper; | |||
import com.tuoheng.model.dto.City; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.tuoheng.model.entity.Marker; | |||
import com.tuoheng.model.query.AreaQuery; | |||
import com.tuoheng.service.AreaService; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_area】的数据库操作Service实现 | |||
* @createDate 2023-03-06 14:58:40 | |||
*/ | |||
@Service | |||
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> | |||
implements AreaService { | |||
@Autowired | |||
private AreaMapper areaMapper; | |||
@Autowired | |||
private CityMapper cityMapper; | |||
/** | |||
* 查询区域信息 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult index(AreaQuery query) { | |||
//分页参数校验 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<Area> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<Area> areaPage = areaMapper.selectPage(page, Wrappers.<Area>lambdaQuery() | |||
.eq(Area::getMark, MarkTypeEnum.VALID.getCode()) | |||
.like(ObjectUtil.isNotEmpty(query.getName()), Area::getName, query.getName()) | |||
.orderByDesc(Area::getCreateTime)); | |||
return JsonResult.success(areaPage); | |||
} | |||
/** | |||
* 新增区域信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(Area entity, LoginUser loginUser) { | |||
if (ObjectUtil.isNull(entity.getId())) { | |||
//新增 | |||
setCityName(entity); | |||
entity.setEditorName(loginUser.getUsername()); | |||
entity.setCreateUser(loginUser.getUserId()); | |||
this.save(entity); | |||
} else { | |||
//编辑 | |||
setCityName(entity); | |||
entity.setEditorName(loginUser.getUsername()); | |||
entity.setUpdateUser(loginUser.getUserId()); | |||
this.updateById(entity); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 更新区域 | |||
* | |||
* @param entity | |||
*/ | |||
private void setCityName(Area entity) { | |||
if (entity.getCityCode().contains(CommonConstant.COMMA)) { | |||
StringBuilder cityName = new StringBuilder(); | |||
for (String code : entity.getCityCode().split(CommonConstant.COMMA)) { | |||
City city = cityMapper.selectOne(Wrappers.<City>lambdaQuery() | |||
.eq(City::getMark, MarkTypeEnum.VALID.getCode()) | |||
.eq(City::getCitycode, code)); | |||
cityName.append(city.getName()); | |||
cityName.append(CommonConstant.SIGN); | |||
} | |||
//切割拼接 | |||
entity.setCityName(cityName.substring(CommonConstant.ZERO, cityName.toString().lastIndexOf(CommonConstant.SIGN))); | |||
} else { | |||
City city = cityMapper.selectOne(Wrappers.<City>lambdaQuery() | |||
.eq(City::getMark, MarkTypeEnum.VALID.getCode()) | |||
.eq(City::getCitycode, entity.getCityCode())); | |||
entity.setCityName(city.getName()); | |||
} | |||
} | |||
/** | |||
* 删除 | |||
* | |||
* @param ids | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult deleteByIds(Long[] ids) { | |||
for (Long id : ids) { | |||
Area marker = areaMapper.selectById(id); | |||
marker.setMark(MarkTypeEnum.NOTVALID.getCode()); | |||
areaMapper.updateById(marker); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} | |||
@@ -8,10 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.common.ServiceException; | |||
import com.tuoheng.constant.*; | |||
import com.tuoheng.mapper.*; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.OidcTenantDto; | |||
import com.tuoheng.model.dto.Platform; | |||
import com.tuoheng.model.dto.TTenant; | |||
import com.tuoheng.model.dto.*; | |||
import com.tuoheng.model.param.*; | |||
import com.tuoheng.model.po.AuthoritiesPo; | |||
import com.tuoheng.model.po.ClientUserRolePo; | |||
@@ -25,8 +22,9 @@ import com.tuoheng.model.vo.UserVo; | |||
import com.tuoheng.service.ClientUserSevice; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.annotation.Id; | |||
import org.springframework.core.ParameterizedTypeReference; | |||
import org.springframework.http.*; | |||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | |||
import org.springframework.stereotype.Service; | |||
@@ -58,14 +56,6 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
@Autowired | |||
private ClientUserRoleMapper clientUserRoleMapper; | |||
@Autowired | |||
private RestTemplate restTemplate; | |||
@Autowired | |||
private PlatformMapper platformMapper; | |||
@Autowired | |||
private Oauth2RegisteredClientMapper oauth2RegisteredClientMapper; | |||
@Override | |||
@Transactional(readOnly = true) | |||
public JsonResult judgeCreate(String username) { | |||
@@ -156,49 +146,6 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
return JsonResult.success(userPo.getId()); | |||
} | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser) { | |||
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { | |||
return JsonResult.error("该用户名称已存在!"); | |||
} | |||
UserPo userPo = new UserPo() | |||
.setIsTenant(1) | |||
.setUsername(createClientTenantDto.getUsername()) | |||
.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(createClientTenantDto.getPassword())); | |||
userPo.setCreateUser(loginUser.getUserId()); | |||
clientUserMapper.insertClientUser(userPo); | |||
TenantPo tenantPo = new TenantPo() | |||
.setUserId(userPo.getId()) | |||
.setRemark(createClientTenantDto.getRemark()); | |||
tenantMapper.insertTenant(tenantPo); | |||
List<AuthoritiesPo> authoritiesPos = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>(); | |||
for (ClientRoleDto clientRoleDto : createClientTenantDto.getClientRoleDtoList()) { | |||
AuthoritiesPo authoritiesPo = new AuthoritiesPo() | |||
.setUserId(userPo.getId()) | |||
.setUsername(createClientTenantDto.getUsername()) | |||
.setAuthority(clientRoleDto.getClientId()); | |||
authoritiesPo.setCreateUser(loginUser.getUserId()); | |||
authoritiesPos.add(authoritiesPo); | |||
ClientUserRolePo clientUserRolePo = new ClientUserRolePo() | |||
.setUserId(userPo.getId()) | |||
.setClientId(clientRoleDto.getClientId()) | |||
.setRoleId(clientRoleDto.getRoleId()); | |||
clientUserRolePo.setCreateUser(loginUser.getUserId()); | |||
clientUserRolePoArrayList.add(clientUserRolePo); | |||
} | |||
authoritiesMapper.batchInsert(authoritiesPos); | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
//todo:调用业务系统完成租户创建 | |||
return JsonResult.success(userPo.getId()); | |||
} | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser) { | |||
@@ -213,7 +160,6 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
clientUserMapper.updatePass(userPo); | |||
return JsonResult.success(true); | |||
} | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser) { | |||
@@ -239,451 +185,4 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
} | |||
return JsonResult.success(true); | |||
} | |||
/** | |||
* 查询对应租户下的所有用户数据 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult findUserList(UserQuery query) { | |||
//分页参数校验 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<UserPo> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<UserVo> pageData = clientUserMapper.selectByTenantIdAndPage(query, page); | |||
pageData.convert(x -> { | |||
String platformCode = x.getPlatformCode(); | |||
if (platformCode.contains(HhzUrlConstant.HHZ_CLIENT)) { | |||
x.setPlatformName(HhzUrlConstant.HHZ_NAME); | |||
} else if (platformCode.contains(WaterWayConstant.WATERWAY_CLIENT)) { | |||
x.setPlatformName(WaterWayConstant.WATERWAY_NAME); | |||
} else if (platformCode.contains(FreeWayConstant.FREEWAY_CLIENT)) { | |||
x.setPlatformName(FreeWayConstant.FREEWAY_NAME); | |||
} else if (platformCode.contains(PilotConstant.PILOT_CLIENT)) { | |||
x.setPlatformName(PilotConstant.PILOT_NAME); | |||
} else if (platformCode.contains(AirportConstant.AIRPORT_CLIENT)) { | |||
x.setPlatformName(AirportConstant.AIRPORT_NAME); | |||
} | |||
return x; | |||
}); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 更新 用户/租户对应关系的系统or角色id | |||
* | |||
* @param createClientUserDto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult updateAuthorities(CreateClientUserDto createClientUserDto, LoginUser loginUser) { | |||
UserPo userPo = clientUserMapper.getUserByUserName(createClientUserDto.getUsername()); | |||
if (ObjectUtil.isNull(userPo)) { | |||
return JsonResult.error("此用户不存在"); | |||
} | |||
List<AuthoritiesPo> authoritiesPos = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>(); | |||
for (ClientRoleDto clientRoleDto : createClientUserDto.getClientRoleDtoList()) { | |||
AuthoritiesPo authoritiesPo = new AuthoritiesPo() | |||
.setUserId(userPo.getId()) | |||
.setUsername(createClientUserDto.getUsername()) | |||
.setAuthority(clientRoleDto.getClientId()); | |||
authoritiesPo.setCreateUser(loginUser.getUserId()); | |||
authoritiesPos.add(authoritiesPo); | |||
ClientUserRolePo clientUserRolePo = new ClientUserRolePo() | |||
.setUserId(userPo.getId()) | |||
.setClientId(clientRoleDto.getClientId()) | |||
.setRoleId(clientRoleDto.getRoleId()); | |||
clientUserRolePo.setCreateUser(loginUser.getUserId()); | |||
clientUserRolePoArrayList.add(clientUserRolePo); | |||
} | |||
authoritiesMapper.batchInsert(authoritiesPos); | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 新增业务平台的租户基本数据 | |||
* | |||
* @param dto | |||
* @return | |||
*/ | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult addTenant(OidcTenantDto dto, LoginUser loginUser) { | |||
if (clientUserMapper.judgeCreateByUserName(dto.getUsername()) > 0) { | |||
return JsonResult.error("该租户账号已存在!"); | |||
} | |||
if (ObjectUtil.isEmpty(dto.getTenantCode())) { | |||
return JsonResult.error("租户code不能为空"); | |||
} | |||
TTenant tTenant = tenantMapper.getByCode(dto.getTenantCode()); | |||
if (ObjectUtil.isNotNull(tTenant)) { | |||
return JsonResult.error("该租户code已存在,请重新输入"); | |||
} | |||
if (dto.getClientId().contains(CommonConstant.COMMA)) { | |||
String[] codes = dto.getClientId().split(CommonConstant.COMMA); | |||
for (String code : codes) { | |||
JsonResult result = getResult(dto, code, loginUser); | |||
if (result.getCode() != JsonResult.SUCCESS) { | |||
return result; | |||
} | |||
} | |||
} else { | |||
JsonResult result = getResult(dto, dto.getClientId(), loginUser); | |||
if (result.getCode() != JsonResult.SUCCESS) { | |||
return result; | |||
} | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 查询租户以及该租户对应绑定的系统等 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult findTenants(TenantQuery query) { | |||
//分页参数校验 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<TenantVo> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<TenantPo> pageData = tenantMapper.findList(page, query); | |||
pageData.convert(x -> { | |||
TenantVo vo = Convert.convert(TenantVo.class, x); | |||
vo.setTenantId(x.getUserId()); | |||
vo.setTenantCode(x.getCode()); | |||
vo.setTenantName(x.getName()); | |||
Long userId = x.getUserId(); | |||
List<AuthoritiesPo> poList = authoritiesMapper.selectByUserId(userId); | |||
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>(); | |||
for (AuthoritiesPo authoritiesPo : poList) { | |||
//TODO 后期维护各个业务平台 | |||
if (authoritiesPo.getAuthority().contains("hhz")) { | |||
businessSystemVoList.add(getbusinessSystemVo(HhzUrlConstant.HHZ_CLIENT, HhzUrlConstant.HHZ_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains("airport")) { | |||
businessSystemVoList.add(getbusinessSystemVo(AirportConstant.AIRPORT_CLIENT, AirportConstant.AIRPORT_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains("waterway")) { | |||
businessSystemVoList.add(getbusinessSystemVo(WaterWayConstant.WATERWAY_CLIENT, WaterWayConstant.WATERWAY_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains("freeway")) { | |||
businessSystemVoList.add(getbusinessSystemVo(FreeWayConstant.FREEWAY_CLIENT, FreeWayConstant.FREEWAY_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains("pilot")) { | |||
businessSystemVoList.add(getbusinessSystemVo(PilotConstant.PILOT_CLIENT, PilotConstant.PILOT_NAME)); | |||
} | |||
} | |||
businessSystemVoList = businessSystemVoList.stream().distinct().collect(Collectors.toList()); | |||
vo.setList(businessSystemVoList); | |||
return vo; | |||
}); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 封装返回展示类 | |||
* | |||
* @param client | |||
* @param name | |||
* @return | |||
*/ | |||
private BusinessSystemVo getbusinessSystemVo(String client, String name) { | |||
BusinessSystemVo businessSystemVo = new BusinessSystemVo(); | |||
businessSystemVo.setClientId(client); | |||
businessSystemVo.setName(name); | |||
return businessSystemVo; | |||
} | |||
/** | |||
* 删除租户(逻辑删除) | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult deleteTenant(OidcTenantDto dto, LoginUser loginUser) { | |||
TenantPo tenantPo = tenantMapper.selectById(dto.getId()); | |||
List<UserPo> list = clientUserMapper.selectByTenantId(tenantPo.getUserId()); | |||
if (ObjectUtil.isNotEmpty(list)) { | |||
return JsonResult.error("该租户下含有关联用户,不能进行删除"); | |||
} | |||
tenantPo.setEnabled(0); | |||
tenantMapper.updateById(tenantPo); | |||
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); | |||
userPo.setEnabled(0); | |||
clientUserMapper.updatePass(userPo); | |||
if (dto.getClientId().contains(CommonConstant.COMMA)) { | |||
String[] codes = dto.getClientId().split(CommonConstant.COMMA); | |||
for (String code : codes) { | |||
JsonResult jsonResult = deleteResult(dto, code, loginUser); | |||
if (jsonResult.getCode() != JsonResult.SUCCESS) { | |||
return jsonResult; | |||
} | |||
} | |||
} else { | |||
JsonResult jsonResult = deleteResult(dto, dto.getClientId(), loginUser); | |||
if (jsonResult.getCode() != JsonResult.SUCCESS) { | |||
return jsonResult; | |||
} | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 更新业务平台租户的相关基本信息 | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser) { | |||
if (ObjectUtil.isEmpty(dto.getTenantCode())) { | |||
return JsonResult.error("租户code不能为空"); | |||
} | |||
if (dto.getClientId().contains(CommonConstant.COMMA)) { | |||
String[] codes = dto.getClientId().split(CommonConstant.COMMA); | |||
for (String code : codes) { | |||
JsonResult jsonResult = editResult(dto, code, loginUser); | |||
if (jsonResult.getCode() != JsonResult.SUCCESS) { | |||
return jsonResult; | |||
} | |||
} | |||
} else { | |||
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser); | |||
if (jsonResult.getCode() != JsonResult.SUCCESS) { | |||
return jsonResult; | |||
} | |||
} | |||
TTenant tTenant = tenantMapper.getByCode(dto.getTenantCode()); | |||
dto.setId(tTenant.getId()); | |||
TenantPo tenantPo = new TenantPo(); | |||
tenantPo.setName(dto.getTenantName()) | |||
.setId(dto.getId()) | |||
.setCityCode(dto.getCityCode()) | |||
.setCityName(dto.getCityName()) | |||
.setProvinceName(dto.getProvinceName()) | |||
.setProvinceCode(dto.getProvinceCode()) | |||
.setDistrictCode(dto.getDistrictCode()) | |||
.setDistrictName(dto.getDistrictName()); | |||
tenantMapper.updateById(tenantPo); | |||
//更新密码 | |||
if (ObjectUtil.isNotEmpty(dto.getPassword())) { | |||
UserPo userPo = new UserPo(); | |||
userPo.setUsername(dto.getUsername()); | |||
dto.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(dto.getPassword())); | |||
userPo.setPassword(dto.getPassword()); | |||
clientUserMapper.updatePass(userPo); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 新增请求 | |||
* | |||
* @param dto | |||
* @param code | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private JsonResult getResult(OidcTenantDto dto, String code, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, code) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
//设置地址 | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 ->并修改对应标识权限 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.CREATE_TENANT; | |||
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); | |||
break; | |||
//机场 | |||
case AirportConstant.AIRPORT_CLIENT: | |||
url = url + AirportConstant.CREATE_TENANT; | |||
break; | |||
//高速 | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.CREATE_TENANT; | |||
dto.setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); | |||
break; | |||
//航道 | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.CREATE_TENANT; | |||
dto.setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.CREATE_TENANT; | |||
dto.setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); | |||
break; | |||
default: | |||
break; | |||
} | |||
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); | |||
log.info("请求url:{}", url); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台新增租户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("业务平台新增租户响应失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台新增租户失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("业务平台新增租户响应失败,数据来源:" + platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 更新请求 | |||
* | |||
* @param dto | |||
* @param code | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private JsonResult editResult(OidcTenantDto dto, String code, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, code) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); | |||
//设置地址(hhz平台) | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.UPDATE_TENANT; | |||
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); | |||
break; | |||
//机场 | |||
case AirportConstant.AIRPORT_CLIENT: | |||
url = url + AirportConstant.EDIT_TENANT; | |||
break; | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.UPDATE_TENANT; | |||
dto.setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); | |||
break; | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.UPDATE_TENANT; | |||
dto.setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.UPDATE_TENANT; | |||
dto.setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); | |||
break; | |||
default: | |||
break; | |||
} | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
log.info("请求url:{}", url); | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台更新租户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("业务平台更新租户响应失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台更新租户失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("业务平台更新租户响应失败,数据来源:" + platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 删除请求 | |||
* | |||
* @param dto | |||
* @param code | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private JsonResult deleteResult(OidcTenantDto dto, String code, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, code) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); | |||
//设置地址(hhz平台) | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.DELETE_TENANT; | |||
break; | |||
//机场 | |||
case AirportConstant.AIRPORT_CLIENT: | |||
url = url + AirportConstant.DELETE_TENANT + CommonConstant.SLASH + dto.getTenantCode(); | |||
break; | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.DELETE_TENANT; | |||
break; | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.DELETE_TENANT; | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.DELETE_TENANT; | |||
break; | |||
default: | |||
break; | |||
} | |||
log.info("请求url:{}", url); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台删除租户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("业务平台删除租户响应失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台删除租户失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("业务平台删除租户响应失败,数据来源:" + platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,136 @@ | |||
package com.tuoheng.service.impl; | |||
import cn.hutool.core.convert.Convert; | |||
import cn.hutool.core.date.DateUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.enums.MarkTypeEnum; | |||
import com.tuoheng.mapper.AreaMapper; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Area; | |||
import com.tuoheng.model.entity.Marker; | |||
import com.tuoheng.model.query.MarkerQuery; | |||
import com.tuoheng.model.vo.MarkerVo; | |||
import com.tuoheng.service.MarkerService; | |||
import com.tuoheng.mapper.MarkerMapper; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_marker】的数据库操作Service实现 | |||
* @createDate 2023-03-07 15:21:37 | |||
*/ | |||
@Service | |||
public class MarkerServiceImpl extends ServiceImpl<MarkerMapper, Marker> | |||
implements MarkerService { | |||
@Autowired | |||
private MarkerMapper markerMapper; | |||
@Autowired | |||
private AreaMapper areaMapper; | |||
/** | |||
* 查询营销人员信息 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult index(MarkerQuery query) { | |||
//校验分页参数 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<Marker> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<Marker> pageDate = markerMapper.selectPage(page, Wrappers.<Marker>lambdaQuery() | |||
.eq(Marker::getMark, MarkTypeEnum.VALID.getCode()) | |||
.like(ObjectUtil.isNotEmpty(query.getName()), Marker::getName, query.getName()) | |||
.eq(ObjectUtil.isNotNull(query.getAreaId()), Marker::getAreaId, query.getAreaId()) | |||
.orderByDesc(Marker::getCreateTime)); | |||
//返回实体类进行处理 | |||
pageDate.convert(x -> { | |||
MarkerVo vo = Convert.convert(MarkerVo.class, x); | |||
Area area = areaMapper.selectById(x.getAreaId()); | |||
if (ObjectUtil.isNull(area)) { | |||
return JsonResult.error("查询不到对应的营销区域"); | |||
} | |||
vo.setAreaName(area.getName()); | |||
return vo; | |||
}); | |||
return JsonResult.success(pageDate); | |||
} | |||
/** | |||
* 新增营销人员信息 | |||
* | |||
* @param entity | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(Marker entity, LoginUser loginUser) { | |||
if (ObjectUtil.isNull(entity.getId())) { | |||
//新增 | |||
entity.setMark(1); | |||
//编辑人 | |||
entity.setEditorName(loginUser.getUsername()); | |||
entity.setCreateUser(loginUser.getUserId()); | |||
this.save(entity); | |||
} else { | |||
//更新 | |||
//编辑人 | |||
entity.setEditorName(loginUser.getUsername()); | |||
entity.setUpdateUser(loginUser.getUserId()); | |||
this.updateById(entity); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 逻辑删除/批量 | |||
* | |||
* @param ids | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult deleteByIds(Long[] ids) { | |||
for (Long id : ids) { | |||
Marker marker = markerMapper.selectById(id); | |||
marker.setMark(MarkTypeEnum.NOTVALID.getCode()); | |||
markerMapper.updateById(marker); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 根据区域id查询出对应营销人员 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getMarkerList(MarkerQuery query) { | |||
if (ObjectUtil.isNull(query.getAreaId())){ | |||
return JsonResult.error("区域id不能为空"); | |||
} | |||
List<Marker> markers = markerMapper.selectList(Wrappers.<Marker>lambdaQuery() | |||
.eq(Marker::getMark, MarkTypeEnum.VALID.getCode()) | |||
.eq(Marker::getAreaId, query.getAreaId())); | |||
return JsonResult.success(markers); | |||
} | |||
} | |||
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.service.impl; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.mapper.TenantEmployMapper; | |||
import com.tuoheng.model.entity.TenantEmploy; | |||
import com.tuoheng.service.TenantEmployService; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_ employ】的数据库操作Service实现 | |||
* @createDate 2023-03-08 14:33:40 | |||
*/ | |||
@Service | |||
public class TenantEmployServiceImpl extends ServiceImpl<TenantEmployMapper, TenantEmploy> | |||
implements TenantEmployService { | |||
} | |||
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.service.impl; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.model.entity.TenantItem; | |||
import com.tuoheng.service.TenantItemService; | |||
import com.tuoheng.mapper.TenantItemMapper; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【t_tenant_item】的数据库操作Service实现 | |||
* @createDate 2023-03-08 14:11:43 | |||
*/ | |||
@Service | |||
public class TenantItemServiceImpl extends ServiceImpl<TenantItemMapper, TenantItem> | |||
implements TenantItemService{ | |||
} | |||
@@ -0,0 +1,728 @@ | |||
package com.tuoheng.service.impl; | |||
import cn.hutool.core.date.DateUnit; | |||
import cn.hutool.core.date.DateUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.common.CommonConfig; | |||
import com.tuoheng.common.ServiceException; | |||
import com.tuoheng.common.ServiceExceptionEnum; | |||
import com.tuoheng.constant.*; | |||
import com.tuoheng.mapper.*; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.Platform; | |||
import com.tuoheng.model.entity.TenantEmploy; | |||
import com.tuoheng.model.entity.TenantItem; | |||
import com.tuoheng.model.param.ClientRoleDto; | |||
import com.tuoheng.model.param.CreateClientTenantDto; | |||
import com.tuoheng.model.param.CreateClientUserDto; | |||
import com.tuoheng.model.po.AuthoritiesPo; | |||
import com.tuoheng.model.po.ClientUserRolePo; | |||
import com.tuoheng.model.po.TenantPo; | |||
import com.tuoheng.model.po.UserPo; | |||
import com.tuoheng.model.query.TenantQuery; | |||
import com.tuoheng.model.query.UserQuery; | |||
import com.tuoheng.model.vo.BusinessSystemVo; | |||
import com.tuoheng.model.vo.CreateTenantVo; | |||
import com.tuoheng.model.vo.TenantVo; | |||
import com.tuoheng.model.vo.UserVo; | |||
import com.tuoheng.service.TenantService; | |||
import com.tuoheng.until.JsonResult; | |||
import com.tuoheng.until.MapUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.*; | |||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/6 11:26 | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class TenantServiceImpl implements TenantService { | |||
//默认密码 | |||
private static final String passward = "thjs2023"; | |||
@Autowired | |||
private ClientUserMapper clientUserMapper; | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private AuthoritiesMapper authoritiesMapper; | |||
@Autowired | |||
private ClientUserRoleMapper clientUserRoleMapper; | |||
@Autowired | |||
private RestTemplate restTemplate; | |||
@Autowired | |||
private PlatformMapper platformMapper; | |||
@Autowired | |||
private TenantEmployMapper tenantEmployMapper; | |||
@Autowired | |||
private TenantItemMapper tenantItemMapper; | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser) { | |||
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { | |||
return JsonResult.error("该用户名称已存在!"); | |||
} | |||
createClientTenantDto.setPassword(passward); | |||
//创建租户创建成功后的返回实体类 | |||
CreateTenantVo vo = new CreateTenantVo(); | |||
vo.setPassword(createClientTenantDto.getPassword()); | |||
vo.setTenantName(createClientTenantDto.getTenantName()); | |||
vo.setUsername(createClientTenantDto.getUsername()); | |||
//code复用username | |||
createClientTenantDto.setTenantCode(createClientTenantDto.getUsername()); | |||
//用户表 | |||
UserPo userPo = new UserPo() | |||
.setIsTenant(1) | |||
.setUsername(createClientTenantDto.getUsername()) | |||
.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(createClientTenantDto.getPassword())); | |||
userPo.setCreateUser(loginUser.getUserId()); | |||
clientUserMapper.insertClientUser(userPo); | |||
log.info("用户表添加完毕"); | |||
//调用高德将地址转换经纬度 | |||
Map<String, String> lonAndLat = MapUtils.getLonAndLat(createClientTenantDto.getAdress(), CommonConfig.gaodeKey); | |||
//租户表 | |||
TenantPo tenantPo = new TenantPo(); | |||
BeanUtils.copyProperties(createClientTenantDto, tenantPo); | |||
tenantPo.setName(createClientTenantDto.getTenantName()) | |||
.setCode(createClientTenantDto.getTenantCode()) | |||
.setUserId(userPo.getId()) | |||
//获取经纬度更新 | |||
.setLat(lonAndLat.get("lat").toString()) | |||
.setLng(lonAndLat.get("lng").toString()); | |||
tenantMapper.insertTenant(tenantPo); | |||
log.info("租户表添加完毕"); | |||
//添加租户对应项目详细信息表 | |||
TenantItem tenantItem = createClientTenantDto.getTenantItem(); | |||
tenantItem.setTenantId(tenantPo.getId()); | |||
tenantItemMapper.insert(tenantItem); | |||
//设置系统有效期 | |||
vo.setEffectiveDate(DateUtil.formatDate(tenantItem.getBeginTime()) + CommonConstant.TILDE + DateUtil.formatDate(tenantItem.getEndTime())); | |||
log.info("租户项目表添加完毕"); | |||
StringBuilder PlatformName = new StringBuilder(); | |||
for (ClientRoleDto clientRoleDto : createClientTenantDto.getClientRoleDtoList()) { | |||
//获取clientId查询对应平台获取平台名称 | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, clientRoleDto.getClientId()) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//添加相关对应 | |||
PlatformName.append(platform.getPlatformName()); | |||
PlatformName.append(CommonConstant.SIGN); | |||
//添加租户对应服务的相关表数据 | |||
TenantEmploy tenantEmploy = new TenantEmploy(); | |||
tenantEmploy.setTenantId(tenantPo.getId()); | |||
tenantEmploy.setPlatformCode(platform.getPlatformCode()); | |||
tenantEmploy.setServiceId(clientRoleDto.getServiceId()); | |||
tenantEmployMapper.insert(tenantEmploy); | |||
} | |||
//拼接 | |||
vo.setPlatformName(PlatformName.substring(CommonConstant.ZERO, PlatformName.lastIndexOf(CommonConstant.SIGN))); | |||
log.info("租户实例表添加完毕"); | |||
//1.开始判断租户对应需要的平台并进行匹对 | |||
List<ClientRoleDto> clientRoleDtoList = getClientRoleDtos(createClientTenantDto); | |||
List<AuthoritiesPo> authoritiesPos = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>(); | |||
//2.添加租户对应相关信息 | |||
log.info("开始创建对应各个业务平台的表"); | |||
for (ClientRoleDto clientRoleDto : clientRoleDtoList) { | |||
//添加角色权限相关 | |||
AuthoritiesPo authoritiesPo = new AuthoritiesPo() | |||
.setUserId(userPo.getId()) | |||
.setUsername(createClientTenantDto.getUsername()) | |||
.setAuthority(clientRoleDto.getClientId()); | |||
authoritiesPo.setCreateUser(loginUser.getUserId()); | |||
authoritiesPos.add(authoritiesPo); | |||
ClientUserRolePo clientUserRolePo = new ClientUserRolePo() | |||
.setUserId(userPo.getId()) | |||
.setClientId(clientRoleDto.getClientId()) | |||
.setRoleId(clientRoleDto.getRoleId()) | |||
.setRoleName(clientRoleDto.getRoleName()); | |||
clientUserRolePo.setCreateUser(loginUser.getUserId()); | |||
clientUserRolePoArrayList.add(clientUserRolePo); | |||
} | |||
authoritiesMapper.batchInsert(authoritiesPos); | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
//todo:调用业务系统完成租户创建 | |||
List<ClientRoleDto> list = createClientTenantDto.getClientRoleDtoList(); | |||
for (ClientRoleDto clientRoleDto : list) { | |||
try { | |||
log.info("参数:{}", clientRoleDto.toString()); | |||
JsonResult result = getResult(createClientTenantDto, clientRoleDto.getClientId(), loginUser); | |||
if (JsonResult.SUCCESS != result.getCode()) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), result.getMsg()); | |||
} | |||
} catch (Exception e) { | |||
//e.printStackTrace(); | |||
//事务并不会回滚 | |||
log.info("异常信息捕获,平台标识:{}", clientRoleDto.getClientId()); | |||
log.info("异常信息:{}", e.getMessage()); | |||
} | |||
} | |||
log.info("业务系统完成创建"); | |||
return JsonResult.success(vo); | |||
} | |||
/** | |||
* 匹配对应业务系统对应的标识,并封装返回方便后续操作 | |||
* | |||
* @param createClientTenantDto | |||
* @return | |||
*/ | |||
private List<ClientRoleDto> getClientRoleDtos(CreateClientTenantDto createClientTenantDto) { | |||
List<ClientRoleDto> clientRoleDtoList = new ArrayList<>(); | |||
//遍历获取参数进项封装 | |||
for (ClientRoleDto dto : createClientTenantDto.getClientRoleDtoList()) { | |||
switch (dto.getClientId()) { | |||
//暂时河湖长,动态匹配其他平台 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_MP, dto, clientRoleDtoList); | |||
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_ADMIN, dto, clientRoleDtoList); | |||
break; | |||
case PilotConstant.PILOT_CLIENT: | |||
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_ADMIN, dto, clientRoleDtoList); | |||
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_MP, dto, clientRoleDtoList); | |||
break; | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
addClientRoleDtoList(FreeWayConstant.FREEWAY_CLIENT_ADMIN, dto, clientRoleDtoList); | |||
addClientRoleDtoList(FreeWayConstant.FREEWAY_CLIENT_MP, dto, clientRoleDtoList); | |||
break; | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
addClientRoleDtoList(WaterWayConstant.WATERWAY_CLIENT_ADMIN, dto, clientRoleDtoList); | |||
addClientRoleDtoList(WaterWayConstant.WATERWAY_CLIENT_MP, dto, clientRoleDtoList); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
return clientRoleDtoList; | |||
} | |||
/** | |||
* 封装数据到 clientRoleDtoList | |||
* | |||
* @param clientId | |||
* @param dto | |||
* @param clientRoleDtoList | |||
*/ | |||
private void addClientRoleDtoList(String clientId, ClientRoleDto dto, List<ClientRoleDto> clientRoleDtoList) { | |||
ClientRoleDto clientRoleDto = new ClientRoleDto(); | |||
clientRoleDto.setClientId(clientId); | |||
clientRoleDto.setRoleId(dto.getRoleId()); | |||
clientRoleDto.setRoleName(dto.getRoleName()); | |||
clientRoleDtoList.add(clientRoleDto); | |||
} | |||
/** | |||
* 查询对应租户下的所有用户数据 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult findUserList(UserQuery query) { | |||
//分页参数校验 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<UserPo> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<UserVo> pageData = clientUserMapper.selectByTenantIdAndPage(query, page); | |||
pageData.convert(x -> { | |||
String platformCode = x.getPlatformCode(); | |||
if (platformCode.contains(HhzUrlConstant.HHZ_CLIENT)) { | |||
x.setPlatformName(HhzUrlConstant.HHZ_NAME); | |||
} else if (platformCode.contains(WaterWayConstant.WATERWAY_CLIENT)) { | |||
x.setPlatformName(WaterWayConstant.WATERWAY_NAME); | |||
} else if (platformCode.contains(FreeWayConstant.FREEWAY_CLIENT)) { | |||
x.setPlatformName(FreeWayConstant.FREEWAY_NAME); | |||
} else if (platformCode.contains(PilotConstant.PILOT_CLIENT)) { | |||
x.setPlatformName(PilotConstant.PILOT_NAME); | |||
} else if (platformCode.contains(AirportConstant.AIRPORT_CLIENT)) { | |||
x.setPlatformName(AirportConstant.AIRPORT_NAME); | |||
} | |||
return x; | |||
}); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 更新 用户/租户对应关系的系统or角色id | |||
* | |||
* @param createClientUserDto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult updateAuthorities(CreateClientUserDto createClientUserDto, LoginUser loginUser) { | |||
UserPo userPo = clientUserMapper.getUserByUserName(createClientUserDto.getUsername()); | |||
if (ObjectUtil.isNull(userPo)) { | |||
return JsonResult.error("此用户不存在"); | |||
} | |||
List<AuthoritiesPo> authoritiesPos = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>(); | |||
for (ClientRoleDto clientRoleDto : createClientUserDto.getClientRoleDtoList()) { | |||
AuthoritiesPo authoritiesPo = new AuthoritiesPo() | |||
.setUserId(userPo.getId()) | |||
.setUsername(createClientUserDto.getUsername()) | |||
.setAuthority(clientRoleDto.getClientId()); | |||
authoritiesPo.setCreateUser(loginUser.getUserId()); | |||
authoritiesPos.add(authoritiesPo); | |||
ClientUserRolePo clientUserRolePo = new ClientUserRolePo() | |||
.setUserId(userPo.getId()) | |||
.setClientId(clientRoleDto.getClientId()) | |||
.setRoleId(clientRoleDto.getRoleId()); | |||
clientUserRolePo.setCreateUser(loginUser.getUserId()); | |||
clientUserRolePoArrayList.add(clientUserRolePo); | |||
} | |||
authoritiesMapper.batchInsert(authoritiesPos); | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 查询租户以及该租户对应绑定的系统等 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult findTenants(TenantQuery query) { | |||
//分页参数校验 | |||
query.checkParam(); | |||
//开启分页 | |||
IPage<TenantVo> page = new Page<>(query.getPage(), query.getLimit()); | |||
IPage<TenantVo> pageData = tenantMapper.findList(page, query); | |||
List<TenantVo> collect = pageData.getRecords().stream().map(x -> { | |||
TenantVo vo = new TenantVo(); | |||
BeanUtils.copyProperties(x, vo); | |||
//并不是真正意义上的租户id | |||
vo.setTenantId(x.getUserId()); | |||
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, x.getId())); | |||
if (ObjectUtil.isNotNull(tenantItem)) { | |||
//获取有效期等 | |||
vo.setEffectiveDate(DateUtil.formatDate(tenantItem.getBeginTime()) + CommonConstant.TILDE + DateUtil.formatDate(tenantItem.getEndTime())); | |||
//获取剩余天数 | |||
long day = DateUtil.between(DateUtil.date(), tenantItem.getEndTime(), DateUnit.DAY); | |||
vo.setRemainDays(day); | |||
} | |||
//此处userId = tenantId 效果一致 | |||
List<AuthoritiesPo> poList = authoritiesMapper.selectListByUserIdAndClientId(x.getUserId(), query); | |||
if (ObjectUtil.isEmpty(poList)) { | |||
return null; | |||
} | |||
List<Long> userIdList = poList.stream().map(t -> t.getUserId()).distinct().collect(Collectors.toList()); | |||
List<AuthoritiesPo> list = authoritiesMapper.selectByUserIds(userIdList); | |||
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>(); | |||
for (AuthoritiesPo authoritiesPo : list) { | |||
//TODO 后期维护各个业务平台 | |||
if (authoritiesPo.getAuthority().contains(HhzUrlConstant.HHZ_CLIENT)) { | |||
businessSystemVoList.add(getbusinessSystemVo(HhzUrlConstant.HHZ_CLIENT, HhzUrlConstant.HHZ_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains(AirportConstant.AIRPORT_CLIENT)) { | |||
businessSystemVoList.add(getbusinessSystemVo(AirportConstant.AIRPORT_CLIENT, AirportConstant.AIRPORT_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains(WaterWayConstant.WATERWAY_CLIENT)) { | |||
businessSystemVoList.add(getbusinessSystemVo(WaterWayConstant.WATERWAY_CLIENT, WaterWayConstant.WATERWAY_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains(FreeWayConstant.FREEWAY_CLIENT)) { | |||
businessSystemVoList.add(getbusinessSystemVo(FreeWayConstant.FREEWAY_CLIENT, FreeWayConstant.FREEWAY_NAME)); | |||
} else if (authoritiesPo.getAuthority().contains(PilotConstant.PILOT_CLIENT)) { | |||
businessSystemVoList.add(getbusinessSystemVo(PilotConstant.PILOT_CLIENT, PilotConstant.PILOT_NAME)); | |||
} | |||
} | |||
businessSystemVoList = businessSystemVoList.stream().distinct().collect(Collectors.toList()); | |||
vo.setList(businessSystemVoList); | |||
return vo; | |||
}).filter(x -> x != null).collect(Collectors.toList()); | |||
pageData.setRecords(collect); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 根据id查询出租户详情 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getDetaile(TenantQuery query) { | |||
if (ObjectUtil.isNull(query.getId())) { | |||
return JsonResult.error("租户id不能为空"); | |||
} | |||
CreateClientTenantDto dto = new CreateClientTenantDto(); | |||
dto.setId(query.getId()); | |||
//查询出租户的相关信息 | |||
Long tenantId = query.getId(); | |||
//项目相关信息 | |||
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, tenantId)); | |||
dto.setTenantItem(tenantItem); | |||
//租户基本信息 | |||
TenantPo tenantPo = tenantMapper.selectById(tenantId); | |||
BeanUtils.copyProperties(tenantPo, dto); | |||
dto.setTenantCode(tenantPo.getCode()); | |||
dto.setTenantName(tenantPo.getName()); | |||
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); | |||
dto.setUsername(Optional.ofNullable(userPo.getUsername()).orElseThrow(() -> new ServiceException(ServiceExceptionEnum.GET_NO_DATA))); | |||
//Optional.ofNullable(userPo.getUsername()).ifPresent(t -> dto.setUsername(t)); | |||
//租户对应的业务平台相关信息 | |||
List<ClientRoleDto> list = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePos = clientUserRoleMapper.selectListByUserId(tenantPo.getUserId()); | |||
for (ClientUserRolePo clientUserRolePo : clientUserRolePos) { | |||
ClientRoleDto clientRoleDto = new ClientRoleDto(); | |||
//此处 暂时格式都为 tuoheng-hhz-web 等格式 如后续维护需要变更形式则此处代码需要更改 | |||
clientRoleDto.setRoleId(clientUserRolePo.getRoleId()); | |||
clientRoleDto.setRoleName(clientUserRolePo.getRoleName()); | |||
clientRoleDto.setClientId(clientUserRolePo.getClientId().substring(CommonConstant.ZERO, clientUserRolePo.getClientId().lastIndexOf(CommonConstant.BARS))); | |||
TenantEmploy tenantEmploy = tenantEmployMapper.selectOne(Wrappers.<TenantEmploy>lambdaQuery() | |||
.eq(TenantEmploy::getTenantId, tenantId) | |||
.eq(TenantEmploy::getPlatformCode, clientRoleDto.getClientId())); | |||
clientRoleDto.setServiceId(tenantEmploy.getServiceId()); | |||
list.add(clientRoleDto); | |||
} | |||
dto.setClientRoleDtoList(list.stream().distinct().collect(Collectors.toList())); | |||
return JsonResult.success(dto); | |||
} | |||
/** | |||
* 重置密码 | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult resetPassward(CreateClientTenantDto dto, LoginUser loginUser) { | |||
if (ObjectUtil.isNull(dto.getId())) { | |||
return JsonResult.error("租户id不能为空"); | |||
} | |||
TenantPo tenantPo = tenantMapper.selectById(dto.getId()); | |||
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); | |||
userPo.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(passward)); | |||
clientUserMapper.updatePass(userPo); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 更新租户状态(1 启用 0禁用) | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult updateStatus(CreateClientTenantDto dto, LoginUser loginUser) { | |||
if (ObjectUtil.isNull(dto.getId())) { | |||
return JsonResult.error("租户id不能为空"); | |||
} | |||
TenantPo tenantPo = tenantMapper.selectById(dto.getId()); | |||
if (CommonConstant.ONE.equals(dto.getStatus())) { | |||
//启用 ->判断当前需要启用的系统是否过了有效期 | |||
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, dto.getId())); | |||
//超过有效期则为flase | |||
boolean flag = tenantItem.getEndTime().after(DateUtil.date()); | |||
//则不给启用 | |||
if (!flag) { | |||
//有效期已过 | |||
return JsonResult.error(ServiceExceptionEnum.EXPIRATION_DATE.getMessage()); | |||
} | |||
} | |||
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); | |||
//1正常 0禁用 | |||
userPo.setEnabled(dto.getStatus()); | |||
clientUserMapper.updatePass(userPo); | |||
tenantPo.setStatus(dto.getStatus()); | |||
tenantMapper.updateById(tenantPo); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 封装返回展示类 | |||
* | |||
* @param client | |||
* @param name | |||
* @return | |||
*/ | |||
private BusinessSystemVo getbusinessSystemVo(String client, String name) { | |||
BusinessSystemVo businessSystemVo = new BusinessSystemVo(); | |||
businessSystemVo.setClientId(client); | |||
businessSystemVo.setName(name); | |||
return businessSystemVo; | |||
} | |||
/** | |||
* 删除租户(逻辑删除) | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult deleteTenant(CreateClientTenantDto dto, LoginUser loginUser) { | |||
//通知业务系统进行删除 | |||
for (ClientRoleDto clientRoleDto : dto.getClientRoleDtoList()) { | |||
deleteResult(dto, clientRoleDto.getClientId(), loginUser); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 更新业务平台租户的相关基本信息 | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
@Transactional(rollbackFor = Exception.class) | |||
public JsonResult editTenant(CreateClientTenantDto dto, LoginUser loginUser) { | |||
dto.setTenantCode(dto.getUsername()); | |||
//默认密码 | |||
dto.setPassword(passward); | |||
TenantPo tenant = tenantMapper.selectById(dto.getId()); | |||
//租户对应的业务平台相关信息 | |||
//删除这个租户原本存在的所有业务平台下的信息 | |||
List<ClientRoleDto> clientRoleDtoList = new ArrayList<>(); | |||
List<ClientUserRolePo> clientUserRolePos = clientUserRoleMapper.selectListByUserId(tenant.getUserId()); | |||
CreateClientTenantDto clientTenantDto = new CreateClientTenantDto(); | |||
BeanUtils.copyProperties(dto, clientTenantDto); | |||
log.info(clientTenantDto.toString()); | |||
for (ClientUserRolePo clientUserRolePo : clientUserRolePos) { | |||
ClientRoleDto clientRoleDto = new ClientRoleDto(); | |||
//此处 暂时格式都为 tuoheng-hhz-web 等格式 如后续维护需要变更形式则此处代码需要更改 | |||
clientRoleDto.setRoleId(clientUserRolePo.getRoleId()); | |||
clientRoleDto.setRoleName(clientUserRolePo.getRoleName()); | |||
clientRoleDto.setClientId(clientUserRolePo.getClientId().substring(CommonConstant.ZERO, clientUserRolePo.getClientId().lastIndexOf(CommonConstant.BARS))); | |||
clientRoleDtoList.add(clientRoleDto); | |||
} | |||
clientRoleDtoList = clientRoleDtoList.stream().distinct().collect(Collectors.toList()); | |||
clientTenantDto.setClientRoleDtoList(clientRoleDtoList); | |||
//符合先删后增逻辑 则直接将原有租户已经对应的关联业务数据清除 | |||
JsonResult jsonResult = deleteTenant(clientTenantDto, loginUser); | |||
if (jsonResult.getCode() != JsonResult.SUCCESS) { | |||
return jsonResult; | |||
} | |||
//更新租户创建成功后的返回实体类 | |||
CreateTenantVo vo = new CreateTenantVo(); | |||
vo.setPassword(dto.getPassword()); | |||
vo.setTenantName(dto.getTenantName()); | |||
vo.setUsername(dto.getUsername()); | |||
log.info("租户原始数据删除完毕"); | |||
//删除原本租户关联的业务实例相关表 | |||
List<TenantEmploy> tenantEmploys = tenantEmployMapper.selectList(Wrappers.<TenantEmploy>lambdaQuery() | |||
.eq(TenantEmploy::getTenantId, dto.getId())); | |||
tenantEmploys.forEach(t -> tenantEmployMapper.deleteById(t)); | |||
List<ClientRoleDto> list = dto.getClientRoleDtoList(); | |||
//新增租户关联业务服务实例相关 | |||
StringBuilder PlatformName = new StringBuilder(); | |||
for (ClientRoleDto clientRoleDto : list) { | |||
//获取clientId查询对应平台获取平台名称 | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, clientRoleDto.getClientId()) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
PlatformName.append(platform.getPlatformName()); | |||
PlatformName.append(CommonConstant.SIGN); | |||
TenantEmploy tenantEmploy = new TenantEmploy(); | |||
tenantEmploy.setTenantId(dto.getId()); | |||
tenantEmploy.setPlatformCode(clientRoleDto.getClientId()); | |||
tenantEmploy.setServiceId(clientRoleDto.getServiceId()); | |||
tenantEmployMapper.insert(tenantEmploy); | |||
} | |||
//拼接 | |||
vo.setPlatformName(PlatformName.substring(CommonConstant.ZERO, PlatformName.lastIndexOf(CommonConstant.SIGN))); | |||
log.info("租户更新的业务服务实例表更新完毕"); | |||
//更新租户原有数据基本 | |||
TenantPo tenantPo = new TenantPo(); | |||
BeanUtils.copyProperties(dto, tenantPo); | |||
tenantPo.setName(dto.getTenantName()) | |||
.setCode(dto.getTenantCode()) | |||
.setId(dto.getId()); | |||
tenantMapper.updateById(tenantPo); | |||
log.info("租户基本信息更新完毕"); | |||
TenantItem tenantItem = dto.getTenantItem(); | |||
tenantItemMapper.updateById(tenantItem); | |||
vo.setEffectiveDate(DateUtil.formatDate(tenantItem.getBeginTime()) + CommonConstant.TILDE + DateUtil.formatDate(tenantItem.getEndTime())); | |||
log.info("租户项目相关信息更新完毕"); | |||
//todo:调用业务系统完成租户创建 | |||
for (ClientRoleDto clientRoleDto : list) { | |||
try { | |||
log.info("参数:{}", clientRoleDto.toString()); | |||
JsonResult result = getResult(dto, clientRoleDto.getClientId(), loginUser); | |||
if (JsonResult.SUCCESS != result.getCode()) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), result.getMsg()); | |||
} | |||
} catch (Exception e) { | |||
//e.printStackTrace(); | |||
//事务并不会回滚 | |||
log.info("异常信息捕获,平台标识:{}", clientRoleDto.getClientId()); | |||
log.info("异常信息:{}", e.getMessage()); | |||
} | |||
} | |||
return JsonResult.success(vo); | |||
} | |||
/** | |||
* 新增请求 | |||
* | |||
* @param dto | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private JsonResult getResult(CreateClientTenantDto dto, String code, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, code) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
//设置地址 | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 ->并修改对应标识权限 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.CREATE_TENANT; | |||
break; | |||
//机场 | |||
case AirportConstant.AIRPORT_CLIENT: | |||
url = url + AirportConstant.CREATE_TENANT; | |||
break; | |||
//高速 | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.CREATE_TENANT; | |||
break; | |||
//航道 | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.CREATE_TENANT; | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.CREATE_TENANT; | |||
break; | |||
default: | |||
break; | |||
} | |||
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); | |||
log.info("请求url:{}", url); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台新增租户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("业务平台新增租户响应失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台新增租户失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("业务平台新增租户响应失败,数据来源:" + platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 删除请求 | |||
* | |||
* @param dto | |||
* @param code | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private JsonResult deleteResult(CreateClientTenantDto dto, String code, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, code) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
return JsonResult.error("该业务平台不存在"); | |||
} | |||
//设置请求头 | |||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); | |||
//设置地址(hhz平台) | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.DELETE_TENANT; | |||
break; | |||
//机场 | |||
case AirportConstant.AIRPORT_CLIENT: | |||
url = url + AirportConstant.DELETE_TENANT + CommonConstant.SLASH + dto.getTenantCode(); | |||
break; | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.DELETE_TENANT; | |||
break; | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.DELETE_TENANT; | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.DELETE_TENANT; | |||
break; | |||
default: | |||
break; | |||
} | |||
log.info("请求url:{}", url); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台删除租户失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("业务平台删除租户响应失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台删除租户失败"); | |||
} | |||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("业务平台删除租户响应失败,数据来源:" + platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
package com.tuoheng.third.controller; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.third.request.ThirdRequest; | |||
import com.tuoheng.third.service.ThirdService; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* 第三方请求响应 前端控制器 | |||
* @Author xiaoying | |||
* @Date 2023/3/8 9:01 | |||
*/ | |||
@RestController | |||
@RequestMapping("/third") | |||
public class ThirdController { | |||
@Autowired | |||
private ThirdService thirdService; | |||
/** | |||
* dsp -获取算法实例 | |||
* @return | |||
*/ | |||
@GetMapping("/findExample") | |||
public JsonResult findExample(){ | |||
return thirdService.findExample(); | |||
} | |||
/** | |||
* 查询对应业务平台的所有角色 | |||
* | |||
* @param clientId 平台标识 | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@GetMapping("/getRoleList") | |||
public JsonResult getRoleList(String clientId, @CurrentUser LoginUser loginUser) { | |||
return thirdService.getRoleList(clientId, loginUser); | |||
} | |||
/** | |||
* 查询对应业务平台角色对应的菜单 | |||
* | |||
* @param request 请求参数 | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@GetMapping("/getMenuList") | |||
public JsonResult getMenuList(ThirdRequest request, @CurrentUser LoginUser loginUser) { | |||
return thirdService.getMenuList(request, loginUser); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.third.request; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/8 10:34 | |||
*/ | |||
@Data | |||
public class ThirdRequest { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 平台标识 | |||
*/ | |||
private String clientId; | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.tuoheng.third.service; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.third.request.ThirdRequest; | |||
import com.tuoheng.until.JsonResult; | |||
public interface ThirdService { | |||
/** | |||
* dsp -获取算法实例 | |||
* @return | |||
*/ | |||
JsonResult findExample(); | |||
/** | |||
* 查询对应业务平台的所有角色 | |||
* | |||
* @param clientId 平台标识 | |||
* @param loginUser | |||
* @return | |||
*/ | |||
JsonResult getRoleList(String clientId, LoginUser loginUser); | |||
/** | |||
* 查询对应业务平台角色对应的菜单 | |||
* | |||
* @param request 角色id | |||
* @param loginUser | |||
* @return | |||
*/ | |||
JsonResult getMenuList(ThirdRequest request, LoginUser loginUser); | |||
} |
@@ -0,0 +1,255 @@ | |||
package com.tuoheng.third.service.impl; | |||
import cn.hutool.core.date.DateUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.common.CommonConfig; | |||
import com.tuoheng.common.ServiceException; | |||
import com.tuoheng.constant.*; | |||
import com.tuoheng.mapper.PlatformMapper; | |||
import com.tuoheng.model.dto.ClientRoleListDto; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.Platform; | |||
import com.tuoheng.model.dto.RoleDto; | |||
import com.tuoheng.third.request.ThirdRequest; | |||
import com.tuoheng.third.service.ThirdService; | |||
import com.tuoheng.third.vo.IndustryVo; | |||
import com.tuoheng.third.vo.RoleMenuVo; | |||
import com.tuoheng.third.vo.ServiceExampleVo; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.core.ParameterizedTypeReference; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.util.LinkedMultiValueMap; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.ArrayList; | |||
import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.Locale; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/8 9:01 | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class ThirdServiceImpl implements ThirdService { | |||
@Autowired | |||
private PlatformMapper platformMapper; | |||
@Autowired | |||
private RestTemplate restTemplate; | |||
/** | |||
* dsp -获取算法实例 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult findExample() { | |||
String url = CommonConfig.dspURL + DspConstant.FIND_EXAMPLE; | |||
ParameterizedTypeReference<JsonResult<List<IndustryVo>>> parameterizedTypeReference = | |||
new ParameterizedTypeReference<JsonResult<List<IndustryVo>>>() { | |||
}; | |||
ResponseEntity<JsonResult<List<IndustryVo>>> response; | |||
try { | |||
log.info("url:{}", url); | |||
response = restTemplate.exchange(url, HttpMethod.GET, null, parameterizedTypeReference); | |||
} catch (Exception e) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "请求发送内部出现异常!"); | |||
} | |||
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "dsp获取服务实例异常"); | |||
} | |||
List<IndustryVo> list = response.getBody().getData(); | |||
List<ServiceExampleVo> serviceInstListVoList = new ArrayList<>(); | |||
for (IndustryVo industryVo : list) { | |||
List<ServiceExampleVo> serviceExampleVos = industryVo.getServiceInstListVoList(); | |||
if (ObjectUtil.isNotEmpty(serviceExampleVos)) { | |||
serviceInstListVoList.addAll(serviceExampleVos); | |||
} | |||
} | |||
return JsonResult.success(serviceInstListVoList); | |||
} | |||
/** | |||
* 查询对应业务平台的所有角色 | |||
* | |||
* @param clientId 平台标识 | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getRoleList(String clientId, LoginUser loginUser) { | |||
if (ObjectUtil.isEmpty(clientId)) { | |||
return JsonResult.error("clientId不能为空"); | |||
} | |||
List<ClientRoleListDto> clientRoleListDtos = new ArrayList<>(); | |||
if (clientId.contains(CommonConstant.COMMA)) { | |||
String[] clientIds = clientId.split(CommonConstant.COMMA); | |||
for (String id : clientIds) { | |||
ClientRoleListDto dto = getRoleListByClinetId(id, loginUser); | |||
clientRoleListDtos.add(dto); | |||
} | |||
} else { | |||
ClientRoleListDto dto = getRoleListByClinetId(clientId, loginUser); | |||
clientRoleListDtos.add(dto); | |||
} | |||
return JsonResult.success(clientRoleListDtos); | |||
} | |||
/** | |||
* 查询对应业务平台角色对应的菜单 | |||
* | |||
* @param request 请求参数 | |||
* @param loginUser | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getMenuList(ThirdRequest request, LoginUser loginUser) { | |||
if (ObjectUtil.isEmpty(request.getClientId()) || ObjectUtil.isNull(request.getRoleId())) { | |||
return JsonResult.error("请求参数有误!"); | |||
} | |||
RoleMenuVo vo = getRoleMenuVoByThirdRequest(request, loginUser); | |||
return JsonResult.success(vo); | |||
} | |||
/** | |||
* 获取对应业务平台的角色对应的菜单列表 | |||
* | |||
* @param request | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private RoleMenuVo getRoleMenuVoByThirdRequest(ThirdRequest request, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, request.getClientId()) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "该业务平台不存在"); | |||
} | |||
RoleMenuVo vo = new RoleMenuVo(); | |||
vo.setRoleId(request.getRoleId()); | |||
String url = ""; | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = String.format(Locale.ENGLISH, "%s%s", platform.getPlatformUrl(), HhzUrlConstant.FIND_MENU); | |||
break; | |||
//高速 | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = String.format(Locale.ENGLISH, "%s%s", platform.getPlatformUrl(), FreeWayConstant.FIND_MENU); | |||
break; | |||
//航道 | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = String.format(Locale.ENGLISH, "%s%s", platform.getPlatformUrl(), WaterWayConstant.FIND_MENU); | |||
break; | |||
//飞手无菜单 | |||
case PilotConstant.PILOT_CLIENT: | |||
return null; | |||
default: | |||
break; | |||
} | |||
ParameterizedTypeReference<JsonResult<RoleMenuVo>> parameterizedTypeReference = | |||
new ParameterizedTypeReference<JsonResult<RoleMenuVo>>() { | |||
}; | |||
ResponseEntity<JsonResult<RoleMenuVo>> response; | |||
org.springframework.http.HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
HttpEntity httpEntity = new HttpEntity(resultRequestHeader); | |||
try { | |||
log.info("url:{}", url); | |||
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, parameterizedTypeReference, request.getRoleId()); | |||
} catch (Exception e) { | |||
log.error("对应平台标识:{}", platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取菜单列表失败!"); | |||
} | |||
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取菜单表响应失败!"); | |||
} | |||
return response.getBody().getData(); | |||
} | |||
/** | |||
* 访问对应系统获取对应业务平台可关联的角色 | |||
* | |||
* @param clientId | |||
* @param loginUser | |||
* @return | |||
*/ | |||
private ClientRoleListDto getRoleListByClinetId(String clientId, LoginUser loginUser) { | |||
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() | |||
.eq(Platform::getPlatformCode, clientId) | |||
.eq(Platform::getMark, 1)); | |||
if (ObjectUtil.isNull(platform)) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "该业务平台不存在"); | |||
} | |||
ClientRoleListDto clientRoleListDto = new ClientRoleListDto(); | |||
clientRoleListDto.setPlatformName(platform.getPlatformName()); | |||
clientRoleListDto.setClientId(platform.getPlatformCode()); | |||
String url = platform.getPlatformUrl(); | |||
//根据不同业务平台进行动态匹配 ->并修改对应标识权限 | |||
switch (platform.getPlatformCode()) { | |||
//河湖长 | |||
case HhzUrlConstant.HHZ_CLIENT: | |||
url = url + HhzUrlConstant.FIND_ROLE; | |||
break; | |||
////机场 | |||
//case AirportConstant.AIRPORT_CLIENT: | |||
// url = url + AirportConstant.CREATE_TENANT; | |||
// break; | |||
//高速 | |||
case FreeWayConstant.FREEWAY_CLIENT: | |||
url = url + FreeWayConstant.FIND_ROLE; | |||
break; | |||
//航道 | |||
case WaterWayConstant.WATERWAY_CLIENT: | |||
url = url + WaterWayConstant.FIND_ROLE; | |||
break; | |||
//飞手 | |||
case PilotConstant.PILOT_CLIENT: | |||
url = url + PilotConstant.FIND_ROLE; | |||
break; | |||
default: | |||
break; | |||
} | |||
ParameterizedTypeReference<JsonResult<List<RoleDto>>> parameterizedTypeReference = | |||
new ParameterizedTypeReference<JsonResult<List<RoleDto>>>() { | |||
}; | |||
ResponseEntity<JsonResult<List<RoleDto>>> response; | |||
org.springframework.http.HttpHeaders resultRequestHeader = new HttpHeaders(); | |||
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); | |||
HttpEntity httpEntity = new HttpEntity(resultRequestHeader); | |||
try { | |||
log.info("url:{}", url); | |||
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, parameterizedTypeReference); | |||
} catch (Exception e) { | |||
log.error("对应平台标识:{}", platform.getPlatformName()); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取角色列表失败!"); | |||
} | |||
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取角色列表响应失败!"); | |||
} | |||
List<RoleDto> roleDtos = response.getBody().getData(); | |||
clientRoleListDto.setRoleDtoList(roleDtos); | |||
return clientRoleListDto; | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
package com.tuoheng.third.vo; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* 行业vo 返回实体类 | |||
* @Author xiaoying | |||
* @Date 2023/3/8 9:36 | |||
*/ | |||
@Data | |||
public class IndustryVo { | |||
/** | |||
* 行业ID | |||
*/ | |||
private String industryId; | |||
/** | |||
* 行业名称 | |||
*/ | |||
private String industryName; | |||
/** | |||
* 服务实例列表 | |||
*/ | |||
private List<ServiceExampleVo> serviceInstListVoList; | |||
} |
@@ -0,0 +1,26 @@ | |||
package com.tuoheng.third.vo; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/8 10:31 | |||
*/ | |||
@Data | |||
public class MenuVo { | |||
/** | |||
* 菜单id | |||
*/ | |||
private Integer id; | |||
/** | |||
* 菜单名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 父级ID | |||
*/ | |||
private Integer parentId; | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.tuoheng.third.vo; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/8 10:30 | |||
*/ | |||
@Data | |||
public class RoleMenuVo { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
*对应的菜单集合->及子菜单(按钮) | |||
*/ | |||
private List<MenuVo> opMenusList; | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.tuoheng.third.vo; | |||
import lombok.Data; | |||
/** | |||
* 服务实例返回实体类 | |||
* @Author xiaoying | |||
* @Date 2023/3/8 9:39 | |||
*/ | |||
@Data | |||
public class ServiceExampleVo { | |||
/** | |||
* 服务实例id | |||
*/ | |||
private String id; | |||
/** | |||
* 服务定义ID | |||
*/ | |||
private String serviceDefId; | |||
/** | |||
* 服务实例名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 服务实例id | |||
*/ | |||
private String description; | |||
} |
@@ -0,0 +1,129 @@ | |||
package com.tuoheng.until; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONArray; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.CommonConfig; | |||
import com.tuoheng.constant.CommonConstant; | |||
import java.io.BufferedReader; | |||
import java.io.InputStreamReader; | |||
import java.net.URL; | |||
import java.net.URLConnection; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
public class MapUtils { | |||
/** | |||
* 地址转换为经纬度 | |||
* | |||
* @param address 地址 | |||
* @param key 高德地图应用key | |||
* @return 经纬度 | |||
*/ | |||
public static Map<String, String> getLonAndLat(String address, String key) { | |||
// 返回输入地址address的经纬度信息, 格式是 经度,纬度 | |||
String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key=" + key + "&address=" + address; | |||
// 高德接口返回的是JSON格式的字符串 | |||
String queryResult = getResponse(queryUrl); | |||
Map<String, String> map = new HashMap<String, String>(); | |||
JSONObject obj = JSONObject.parseObject(queryResult); | |||
if (CommonConstant.ONE.toString().equals(obj.get("status").toString())) { | |||
JSONObject jsonObject = JSONObject.parseObject(obj.get("geocodes").toString().substring(1, obj.get("geocodes").toString().length() - 1)); | |||
String location = jsonObject.get("location").toString(); | |||
System.out.println("经纬度:" + location); | |||
String[] lonAndLat = location.split(","); | |||
if (ObjectUtil.isNotEmpty(lonAndLat) && lonAndLat.length == 2) { | |||
map.put("lng", lonAndLat[0]); | |||
map.put("lat", lonAndLat[1]); | |||
} | |||
System.out.println(map); | |||
return map; | |||
} else { | |||
throw new RuntimeException("地址转换经纬度失败,请重新输入详细地址"); | |||
} | |||
} | |||
/** | |||
* 将经纬度getLng, getLat 通过getAMapByLngAndLat方法转换地址 | |||
* | |||
* @param getLng 经度 | |||
* @param getLat 纬度 | |||
* @param key 高德地图应用key | |||
* @return 地址名称 | |||
* @throws Exception | |||
*/ | |||
public static String getAMapByLngAndLat(String getLng, String getLat, String key) throws Exception { | |||
String url; | |||
try { | |||
url = "http://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + getLng + "," | |||
+ getLat + "&key=" + key + "&radius=0&extensions=base"; | |||
String queryResult = getResponse(url); // 高德接品返回的是JSON格式的字符串 | |||
// 将获取结果转为json数据 | |||
JSONObject obj = JSONObject.parseObject(queryResult); | |||
System.out.println("obj为:" + obj); | |||
if (obj.get("status").toString().equals("1")) { | |||
// 如果没有返回-1 | |||
JSONObject regeocode = obj.getJSONObject("regeocode"); | |||
if (regeocode.size() > 0) { | |||
// 在regeocode中拿到 formatted_address 具体位置 | |||
return regeocode.get("formatted_address").toString(); | |||
} else { | |||
throw new RuntimeException("未找到相匹配的地址!"); | |||
} | |||
} else { | |||
throw new RuntimeException("请求错误!"); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return "-1"; | |||
} | |||
/** | |||
* 根据两个定位点的经纬度算出两点间的距离 | |||
* | |||
* @param startLonLat 起始经纬度 | |||
* @param endLonLat 结束经纬度(目标经纬度) | |||
* @param key 高德地图应用key | |||
* @return 两个定位点之间的距离 | |||
*/ | |||
private static long getDistance(String startLonLat, String endLonLat, String key) { | |||
// 返回起始地startAddr与目的地endAddr之间的距离,单位:米 | |||
Long result = new Long(0); | |||
String queryUrl = "http://restapi.amap.com/v3/distance?key=" + key + "&origins=" + startLonLat + "&destination=" + endLonLat; | |||
String queryResult = getResponse(queryUrl); | |||
JSONObject obj = JSONObject.parseObject(queryResult); | |||
JSONArray ja = obj.getJSONArray("results"); | |||
JSONObject jobO = JSONObject.parseObject(ja.getString(0)); | |||
result = Long.parseLong(jobO.get("distance").toString()); | |||
System.out.println("距离:" + result); | |||
return result; | |||
} | |||
/** | |||
* 发送请求 | |||
* | |||
* @param serverUrl 请求地址 | |||
*/ | |||
private static String getResponse(String serverUrl) { | |||
// 用JAVA发起http请求,并返回json格式的结果 | |||
StringBuffer result = new StringBuffer(); | |||
try { | |||
URL url = new URL(serverUrl); | |||
URLConnection conn = url.openConnection(); | |||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); | |||
String line; | |||
while ((line = in.readLine()) != null) { | |||
result.append(line); | |||
} | |||
in.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return result.toString(); | |||
} | |||
} | |||
@@ -69,4 +69,8 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport-test.t-aaron.com | |||
airport-url: https://airport-test.t-aaron.com | |||
#dsp配置地址 | |||
dsp-url: http://106.15.64.139:7011/api/web/dsp | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -68,4 +68,6 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport.t-aaron.com | |||
airport-url: https://airport.t-aaron.com | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -68,4 +68,8 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport-test.t-aaron.com | |||
airport-url: https://airport-test.t-aaron.com | |||
#dsp配置地址 | |||
dsp-url: https://dsp-portal.t-aaron.com/api/web/dsp | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -0,0 +1,25 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.AreaMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.Area"> | |||
<id property="id" column="id" jdbcType="BIGINT"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="BIGINT"/> | |||
<result property="updateUser" column="update_user" jdbcType="BIGINT"/> | |||
<result property="name" column="name" jdbcType="VARCHAR"/> | |||
<result property="cityCode" column="city_code" jdbcType="VARCHAR"/> | |||
<result property="cityName" column="city_name" jdbcType="VARCHAR"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="editorName" column="editor_name" jdbcType="VARCHAR"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,name, | |||
city_code,city_name,mark,editor_name | |||
</sql> | |||
</mapper> |
@@ -14,5 +14,21 @@ | |||
FROM authorities | |||
WHERE user_id = #{userId} | |||
</select> | |||
<select id="selectListByUserIdAndClientId" resultType="com.tuoheng.model.po.AuthoritiesPo"> | |||
SELECT id, user_id, username, authority | |||
FROM authorities | |||
WHERE user_id = #{userId} | |||
<if test="query.clientId != null and query.clientId != ''"> | |||
and authority LIKE concat('%',#{query.clientId},'%') | |||
</if> | |||
</select> | |||
<select id="selectByUserIds" resultType="com.tuoheng.model.po.AuthoritiesPo"> | |||
SELECT id, user_id, username, authority | |||
FROM authorities | |||
where user_id IN | |||
<foreach collection="list" item="id" separator=","> | |||
(#{id}) | |||
</foreach> | |||
</select> | |||
</mapper> |
@@ -29,7 +29,6 @@ | |||
is_tenant | |||
FROM users | |||
WHERE id = #{userId} | |||
and enabled = 1 | |||
</select> | |||
<select id="selectByTenantId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT * |
@@ -3,29 +3,34 @@ | |||
<mapper namespace="com.tuoheng.mapper.ClientUserRoleMapper"> | |||
<insert id="batchInsert" parameterType="java.util.List"> | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user) | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user,role_name) | |||
VALUES | |||
<foreach collection ="list" item="it" separator =","> | |||
(#{it.userId}, #{it.clientId}, #{it.roleId}, #{it.createUser}) | |||
</foreach > | |||
<foreach collection="list" item="it" separator=","> | |||
(#{it.userId}, #{it.clientId}, #{it.roleId}, #{it.createUser},#{it.roleName}) | |||
</foreach> | |||
</insert> | |||
<insert id="insert" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user) | |||
VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}) | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user, role_name) | |||
VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}, #{it.roleName}) | |||
</insert> | |||
<update id="updateUserClientRole" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
update t_client_user_role | |||
<set> | |||
<if test="roleId != null" > | |||
<if test="roleId != null"> | |||
role_id = #{roleId}, | |||
</if> | |||
<if test="updateUser != null" > | |||
<if test="updateUser != null"> | |||
update_user = #{updateUser}, | |||
</if> | |||
</set> | |||
where user_id = #{userId} and client_id = #{clientId} | |||
</update> | |||
<select id="selectListByUserId" resultType="com.tuoheng.model.po.ClientUserRolePo"> | |||
SELECT * | |||
FROM t_client_user_role | |||
WHERE user_id = #{userId} | |||
</select> | |||
</mapper> |
@@ -0,0 +1,25 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.MarkerMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.Marker"> | |||
<id property="id" column="id" jdbcType="BIGINT"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="BIGINT"/> | |||
<result property="updateUser" column="update_user" jdbcType="BIGINT"/> | |||
<result property="name" column="name" jdbcType="VARCHAR"/> | |||
<result property="areaId" column="area_id" jdbcType="BIGINT"/> | |||
<result property="phone" column="phone" jdbcType="VARCHAR"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="editorName" column="editor_name" jdbcType="VARCHAR"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,name, | |||
area_id,phone,mark,editor_name | |||
</sql> | |||
</mapper> |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | |||
<mapper namespace="com.tuoheng.mapper.TenantEmployMapper"> | |||
</mapper> |
@@ -0,0 +1,28 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.TenantItemMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.TenantItem"> | |||
<id property="id" column="id" jdbcType="BIGINT"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="BIGINT"/> | |||
<result property="updateUser" column="update_user" jdbcType="BIGINT"/> | |||
<result property="markerId" column="marker_id" jdbcType="BIGINT"/> | |||
<result property="areaId" column="area_id" jdbcType="BIGINT"/> | |||
<result property="tenantId" column="tenant_id" jdbcType="BIGINT"/> | |||
<result property="projectCode" column="project_code" jdbcType="VARCHAR"/> | |||
<result property="contractCode" column="contract_code" jdbcType="VARCHAR"/> | |||
<result property="beginTime" column="begin_time" jdbcType="TIMESTAMP"/> | |||
<result property="endTime" column="end_time" jdbcType="TIMESTAMP"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,marker_id, | |||
tenant_id,project_code,contract_code, | |||
begin_time,end_time,area_id | |||
</sql> | |||
</mapper> |
@@ -1,12 +1,17 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.TenantMapper"> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time,create_user,update_user,user_id,remark,`code`,`name`, | |||
enabled,province_code,province_name, | |||
city_code,city_name,district_code,district_name,customer, | |||
customer_phone,adress,status,lng,lat | |||
</sql> | |||
<insert id="insertTenant" parameterType="com.tuoheng.model.po.TenantPo" keyProperty="id" useGeneratedKeys="true"> | |||
INSERT INTO t_tenant (user_id, remark, `code`, `name`, province_code, province_name, city_code, city_name, | |||
district_code, district_name) | |||
district_code, district_name, customer, customer_phone, adress, lng, lat) | |||
VALUES (#{userId}, #{remark}, #{code}, #{name}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, | |||
#{districtCode}, #{districtName}) | |||
#{districtCode}, #{districtName}, #{customer}, #{customerPhone}, #{adress}, #{lng}, #{lat}) | |||
</insert> | |||
<update id="updateById" parameterType="com.tuoheng.model.po.TenantPo"> | |||
update t_tenant | |||
@@ -17,26 +22,20 @@ | |||
<if test="enabled != null"> | |||
enabled = #{enabled}, | |||
</if> | |||
<!--<if test="provinceCode != null and provinceCode !=''"> | |||
province_code = #{provinceCode}, | |||
<if test="status != null"> | |||
status = #{status}, | |||
</if> | |||
<if test="provinceName != null and provinceName !=''"> | |||
province_name = #{provinceName}, | |||
</if> | |||
<if test="cityCode != null and cityCode !=''"> | |||
city_code = #{cityCode}, | |||
</if> | |||
<if test="cityName != null and cityName !=''"> | |||
city_name = #{cityName}, | |||
</if> | |||
<if test="districtCode != null and districtCode !=''"> | |||
district_code = #{districtCode}, | |||
</if> | |||
<if test="districtName != null and districtName !=''"> | |||
district_name = #{districtName}, | |||
</if>--> | |||
province_code=#{provinceCode},province_name=#{provinceName},city_code =#{cityCode},city_name | |||
=#{cityName},district_code =#{districtCode},district_name =#{districtName} | |||
province_code=#{provinceCode}, | |||
province_name=#{provinceName}, | |||
city_code =#{cityCode}, | |||
city_name=#{cityName}, | |||
district_code =#{districtCode}, | |||
district_name =#{districtName}, | |||
customer =#{customer}, | |||
customer_phone =#{customerPhone}, | |||
adress =#{adress}, | |||
lng =#{lng}, | |||
lat =#{lat}, | |||
</set> | |||
where id = #{id} | |||
</update> | |||
@@ -46,23 +45,29 @@ | |||
where code = #{code} | |||
and enabled = 1 | |||
</select> | |||
<select id="findList" resultType="com.tuoheng.model.po.TenantPo"> | |||
SELECT t.id, t.user_id, t.remark, t.code, | |||
t.name,t.province_code,t.province_name,t.city_code,t.city_name,t.district_code,t.district_name,u.username | |||
username | |||
<select id="findList" resultType="com.tuoheng.model.vo.TenantVo"> | |||
SELECT t.id, t.user_id userId, t.remark, t.code tenantCode, | |||
t.name tenantName,t.status,t.customer,t.customer_phone | |||
,t.province_code,t.province_name,t.city_code,t.city_name,t.district_code,t.district_name,u.username | |||
username,t.update_time updateTime,t.create_time createTime | |||
FROM t_tenant t,users u | |||
WHERE t.enabled = 1 and u.enabled =1 and t.user_id =u.id | |||
WHERE t.enabled = 1 and t.user_id =u.id | |||
<if test="query.tenantName != null and query.tenantName != ''"> | |||
and t.name LIKE concat('%',#{query.tenantName},'%') | |||
</if> | |||
<if test="query.username != null and query.username != ''"> | |||
and u.username LIKE concat('%',#{query.username},'%') | |||
</if> | |||
<if test="query.status != null"> | |||
and t.status =#{query.status} | |||
</if> | |||
ORDER BY t.create_time desc | |||
</select> | |||
<select id="selectById" resultType="com.tuoheng.model.po.TenantPo"> | |||
SELECT id, user_id, remark, enabled, code, name | |||
SELECT | |||
<include refid="Base_Column_List"/> | |||
FROM t_tenant | |||
WHERE id = #{id} | |||
and enabled = 1 | |||
</select> | |||
</mapper> |
@@ -69,4 +69,8 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport-test.t-aaron.com | |||
airport-url: https://airport-test.t-aaron.com | |||
#dsp配置地址 | |||
dsp-url: http://106.15.64.139:7011/api/web/dsp | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -69,4 +69,8 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport-test.t-aaron.com | |||
airport-url: https://airport-test.t-aaron.com | |||
#dsp配置地址 | |||
dsp-url: http://106.15.64.139:7011/api/web/dsp | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -68,4 +68,6 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport.t-aaron.com | |||
airport-url: https://airport.t-aaron.com | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -68,4 +68,8 @@ spring: | |||
# 自定义配置 | |||
tuoheng: | |||
#airport配置地址 | |||
airport-url: https://airport-test.t-aaron.com | |||
airport-url: https://airport-test.t-aaron.com | |||
#dsp配置地址 | |||
dsp-url: https://dsp-portal.t-aaron.com/api/web/dsp | |||
# 高德Key | |||
gaodeKey: 5a1f63e7563cba471a9d0773e218144a |
@@ -14,5 +14,21 @@ | |||
FROM authorities | |||
WHERE user_id = #{userId} | |||
</select> | |||
<select id="selectListByUserIdAndClientId" resultType="com.tuoheng.model.po.AuthoritiesPo"> | |||
SELECT id, user_id, username, authority | |||
FROM authorities | |||
WHERE user_id = #{userId} | |||
<if test="query.clientId != null and query.clientId != ''"> | |||
and authority LIKE concat('%',#{query.clientId},'%') | |||
</if> | |||
</select> | |||
<select id="selectByUserIds" resultType="com.tuoheng.model.po.AuthoritiesPo"> | |||
SELECT id, user_id, username, authority | |||
FROM authorities | |||
where user_id IN | |||
<foreach collection="list" item="id" separator=","> | |||
(#{id}) | |||
</foreach> | |||
</select> | |||
</mapper> |
@@ -29,7 +29,6 @@ | |||
is_tenant | |||
FROM users | |||
WHERE id = #{userId} | |||
and enabled = 1 | |||
</select> | |||
<select id="selectByTenantId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT * |
@@ -3,29 +3,34 @@ | |||
<mapper namespace="com.tuoheng.mapper.ClientUserRoleMapper"> | |||
<insert id="batchInsert" parameterType="java.util.List"> | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user) | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user,role_name) | |||
VALUES | |||
<foreach collection ="list" item="it" separator =","> | |||
(#{it.userId}, #{it.clientId}, #{it.roleId}, #{it.createUser}) | |||
</foreach > | |||
<foreach collection="list" item="it" separator=","> | |||
(#{it.userId}, #{it.clientId}, #{it.roleId}, #{it.createUser},#{it.roleName}) | |||
</foreach> | |||
</insert> | |||
<insert id="insert" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user) | |||
VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}) | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user, role_name) | |||
VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}, #{it.roleName}) | |||
</insert> | |||
<update id="updateUserClientRole" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
update t_client_user_role | |||
<set> | |||
<if test="roleId != null" > | |||
<if test="roleId != null"> | |||
role_id = #{roleId}, | |||
</if> | |||
<if test="updateUser != null" > | |||
<if test="updateUser != null"> | |||
update_user = #{updateUser}, | |||
</if> | |||
</set> | |||
where user_id = #{userId} and client_id = #{clientId} | |||
</update> | |||
<select id="selectListByUserId" resultType="com.tuoheng.model.po.ClientUserRolePo"> | |||
SELECT * | |||
FROM t_client_user_role | |||
WHERE user_id = #{userId} | |||
</select> | |||
</mapper> |