add:添加应用信息相关接口
parent
0e1dd0ebad
commit
88d8133e14
|
@ -1,6 +1,6 @@
|
|||
[
|
||||
{
|
||||
"id": "629e1d7fa176d816952f1e81",
|
||||
"id": 13123123123213,
|
||||
"uid": "13480802157",
|
||||
"ownerId": "1",
|
||||
"secret": "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F78574F4778613764564338594E666770595A376177",
|
||||
|
@ -16,7 +16,7 @@
|
|||
"createAt": 1654529407977
|
||||
},
|
||||
{
|
||||
"id": "6286886077b91b031115e6a6",
|
||||
"id": 141231312312,
|
||||
"uid": "guest1",
|
||||
"ownerId": "1",
|
||||
"nickName": "演示账户",
|
||||
|
@ -31,7 +31,7 @@
|
|||
"createAt": 1647592821770
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"id": 13123123,
|
||||
"uid": "iotkit",
|
||||
"ownerId": "1",
|
||||
"nickName": "管理员",
|
||||
|
@ -48,7 +48,7 @@
|
|||
"createAt": 1647592821770
|
||||
},
|
||||
{
|
||||
"id": "a1051e81-f4fc-4182-a750-1a53a27f4c71",
|
||||
"id": 12312312312,
|
||||
"uid": "du2",
|
||||
"ownerId": "1",
|
||||
"nickName": "小度接入2",
|
||||
|
@ -62,7 +62,7 @@
|
|||
"createAt": 1651230139460
|
||||
},
|
||||
{
|
||||
"id": "5c0bea53-a318-42ed-a7c5-6e05e6db4ef2",
|
||||
"id": 23423423,
|
||||
"uid": "tm3",
|
||||
"ownerId": "1",
|
||||
"nickName": "天猫精灵test3",
|
||||
|
@ -76,7 +76,7 @@
|
|||
"createAt": 1647982036151
|
||||
},
|
||||
{
|
||||
"id": "2bb3e6f1-17ba-4bf5-9d5e-85fdffd8b85d",
|
||||
"id": 45234345,
|
||||
"uid": "du1",
|
||||
"ownerId": "1",
|
||||
"nickName": "小度接入1",
|
||||
|
@ -92,7 +92,7 @@
|
|||
"createAt": 1651226639006
|
||||
},
|
||||
{
|
||||
"id": "0ca377e2-66ff-49f3-90c3-108a86bc90eb",
|
||||
"id": 3454543,
|
||||
"uid": "tm1",
|
||||
"ownerId": "1",
|
||||
"nickName": "天猫精灵1",
|
||||
|
@ -106,7 +106,7 @@
|
|||
"createAt": 1648486563107
|
||||
},
|
||||
{
|
||||
"id": "04c6722f-9a6d-40f3-ac9b-cd791b4c8933",
|
||||
"id": 432323,
|
||||
"uid": "18126045687",
|
||||
"ownerId": "1",
|
||||
"nickName": "song",
|
||||
|
|
|
@ -23,12 +23,12 @@ import java.util.List;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserInfo implements Id<String> {
|
||||
public class UserInfo implements Id<Long> {
|
||||
|
||||
public static final int USER_TYPE_PLATFORM = 0;
|
||||
public static final int USER_TYPE_CLIENT = 1;
|
||||
|
||||
private String id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package cc.iotkit.model.system;
|
||||
|
||||
import cc.iotkit.model.Id;
|
||||
import cc.iotkit.model.TenantModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 对象 SYS_APP
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysApp extends TenantModel implements Id<Long>, Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* appSecret
|
||||
*/
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*/
|
||||
private String appType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import cc.iotkit.model.UserInfo;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserInfoData extends ICommonData<UserInfo, String> {
|
||||
public interface IUserInfoData extends ICommonData<UserInfo, Long> {
|
||||
|
||||
UserInfo findByUid(String uid);
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package cc.iotkit.data.system;
|
||||
|
||||
import cc.iotkit.data.ICommonData;
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
|
||||
/**
|
||||
* 数据接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
public interface ISysAppData extends ICommonData<SysApp, Long> {
|
||||
|
||||
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package cc.iotkit.data.service;
|
||||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.constant.Constants;
|
||||
import cc.iotkit.data.manager.IUserInfoData;
|
||||
import cc.iotkit.data.cache.UserInfoCacheEvict;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.constant.Constants;
|
||||
import cc.iotkit.data.cache.UserInfoCacheEvict;
|
||||
import cc.iotkit.data.manager.IUserInfoData;
|
||||
import cc.iotkit.model.UserInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -40,12 +40,12 @@ public class UserInfoDataCache implements IUserInfoData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public UserInfo findById(String s) {
|
||||
public UserInfo findById(Long s) {
|
||||
return userInfoData.findById(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserInfo> findByIds(Collection<String> id) {
|
||||
public List<UserInfo> findByIds(Collection<Long> id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -63,12 +63,12 @@ public class UserInfoDataCache implements IUserInfoData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(String s) {
|
||||
public void deleteById(Long s) {
|
||||
userInfoData.deleteById(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByIds(Collection<String> strings) {
|
||||
public void deleteByIds(Collection<Long> longs) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package cc.iotkit.data.dao;
|
||||
|
||||
import cc.iotkit.data.model.TbSysApp;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
|
||||
/**
|
||||
* 应用信息对象 SYS_APP
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
public interface SysAppRepository extends JpaRepository<TbSysApp, Long>, QuerydslPredicateExecutor<TbSysApp> {
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package cc.iotkit.data.model;
|
||||
|
||||
import cc.iotkit.common.tenant.dao.TenantAware;
|
||||
import cc.iotkit.common.tenant.listener.TenantListener;
|
||||
import cc.iotkit.model.TenantModel;
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.annotations.Filter;
|
||||
import org.hibernate.annotations.FilterDef;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.ParamDef;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 应用信息表对象 SYS_APP
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Entity
|
||||
@Table(name = "SYS_APP")
|
||||
@AutoMapper(target = SysApp.class)
|
||||
@ApiModel(value = "应用信息表")
|
||||
@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "string")})
|
||||
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
|
||||
@EntityListeners(TenantListener.class)
|
||||
public class TbSysApp extends TenantModel implements TenantAware {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
@ApiModelProperty(value = "appId")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* appSecret
|
||||
*/
|
||||
@ApiModelProperty(value = "appSecret")
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*/
|
||||
@ApiModelProperty(value = "应用类型")
|
||||
private String appType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String REMARK;
|
||||
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ public class TbUserInfo {
|
|||
@Id
|
||||
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||
private String id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package cc.iotkit.data.service;
|
||||
|
||||
import cc.iotkit.data.dao.IJPACommData;
|
||||
import cc.iotkit.data.dao.SysAppRepository;
|
||||
import cc.iotkit.data.model.TbSysApp;
|
||||
import cc.iotkit.data.system.ISysAppData;
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据实现接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysAppDataImpl implements ISysAppData, IJPACommData<SysApp, Long> {
|
||||
|
||||
private final SysAppRepository baseRepository;
|
||||
|
||||
private final JPAQueryFactory jpaQueryFactory;
|
||||
|
||||
// @Override
|
||||
// public Paging<SysApp> findAll(PageRequest<SysApp> pageRequest) {
|
||||
// return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysApp.class);
|
||||
// }
|
||||
|
||||
// private Predicate buildQueryCondition(SysApp bo) {
|
||||
// PredicateBuilder builder = PredicateBuilder.instance();
|
||||
// if(Objects.nonNull(bo)) {
|
||||
//
|
||||
// builder.and(StringUtils.isNotBlank(bo.getId()), () -> tbSysApp.ID.eq(bo.getId()));
|
||||
// builder.and(StringUtils.isNotBlank(bo.getTenantId()), () -> tbSysApp.tenantId.eq(bo.getTenantId()));
|
||||
// builder.and(StringUtils.isNotBlank(bo.getAppId()), () -> tbSysApp.appId.eq(bo.getAppId()));
|
||||
// builder.and(StringUtils.isNotBlank(bo.getAppSecret()), () -> tbSysApp.appSecret.eq(bo.getAppSecret()));
|
||||
// builder.and(StringUtils.isNotBlank(bo.getAppType()), () -> tbSysApp.appType.eq(bo.getAppType()));
|
||||
// builder.and(StringUtils.isNotBlank(bo.getRemark()), () -> tbSysApp.REMARK.eq(bo.getRemark()));
|
||||
// }
|
||||
// return builder.build();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public JpaRepository getBaseRepository() {
|
||||
return baseRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getJpaRepositoryClass() {
|
||||
return TbSysApp.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getTClass() {
|
||||
return SysApp.class;
|
||||
}
|
||||
}
|
|
@ -16,20 +16,17 @@ import cc.iotkit.data.manager.IUserInfoData;
|
|||
import cc.iotkit.data.model.TbUserInfo;
|
||||
import cc.iotkit.model.UserInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Primary
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, String> {
|
||||
public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, Long> {
|
||||
|
||||
@Autowired
|
||||
private UserInfoRepository userInfoRepository;
|
||||
|
@ -64,40 +61,5 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, S
|
|||
return UserInfo.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo findById(String s) {
|
||||
return MapstructUtils.convert(userInfoRepository.findById(s).orElse(null), UserInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserInfo> findByIds(Collection<String> id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo save(UserInfo data) {
|
||||
if (StringUtils.isBlank(data.getId())) {
|
||||
data.setId(UUID.randomUUID().toString());
|
||||
data.setCreateAt(System.currentTimeMillis());
|
||||
}
|
||||
userInfoRepository.save(MapstructUtils.convert(data, TbUserInfo.class));
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteById(String s) {
|
||||
userInfoRepository.deleteById(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserInfo> findAll() {
|
||||
return MapstructUtils.convert(userInfoRepository.findAll(), UserInfo.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ public class SpaceDeviceController {
|
|||
}
|
||||
|
||||
String uid = AuthUtil.getUserId();
|
||||
UserInfo userInfo = userInfoData.findById(uid);
|
||||
UserInfo userInfo = userInfoData.findById(Long.valueOf(uid));
|
||||
if (userInfo == null) {
|
||||
throw new BizException(ErrCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ public class SpaceDeviceController {
|
|||
|
||||
spaceDeviceData.deleteById(spaceDevice.getId());
|
||||
DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
|
||||
UserInfo userInfo = userInfoData.findById(uid);
|
||||
UserInfo userInfo = userInfoData.findById(Long.valueOf(uid));
|
||||
if (userInfo == null) {
|
||||
throw new BizException(ErrCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Api(tags = {"用户"})
|
||||
@RestController
|
||||
|
@ -61,7 +60,7 @@ public class UserInfoController {
|
|||
@PostMapping("/platform/user/add")
|
||||
public void addPlatformUser(@RequestBody UserInfo user) {
|
||||
try {
|
||||
user.setId(UUID.randomUUID().toString());
|
||||
// user.setId(UUID.randomUUID().toString());
|
||||
user.setType(UserInfo.USER_TYPE_PLATFORM);
|
||||
user.setOwnerId(AuthUtil.getUserId());
|
||||
user.setRoles(Collections.singletonList(Constants.ROLE_SYSTEM));
|
||||
|
@ -118,7 +117,7 @@ public class UserInfoController {
|
|||
.address("")
|
||||
.deviceNum(0)
|
||||
.spaceNum(0)
|
||||
.uid(user.getId())
|
||||
// .uid(user.getId())
|
||||
.current(true)
|
||||
.build());
|
||||
|
||||
|
@ -127,14 +126,14 @@ public class UserInfoController {
|
|||
spaceData.save(Space.builder()
|
||||
.homeId(home.getId())
|
||||
.name(name)
|
||||
.uid(user.getId())
|
||||
// .uid(user.getId())
|
||||
.createAt(System.currentTimeMillis())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/client/user/{id}/delete")
|
||||
public void deleteClientUser(@PathVariable("id") String id) {
|
||||
public void deleteClientUser(@PathVariable("id") Long id) {
|
||||
UserInfo user = userInfoData.findById(id);
|
||||
if (user == null) {
|
||||
throw new BizException(ErrCode.USER_NOT_FOUND);
|
||||
|
|
|
@ -40,9 +40,9 @@ public class ScreenVerticle extends AbstractVerticle {
|
|||
public void start() {
|
||||
httpServer = vertx.createHttpServer();
|
||||
Router router = Router.router(vertx);
|
||||
router.route(screenConfig.screenAdmin + "/*").handler(StaticHandler.create(screenConfig.getScreenDir()+"/"+apiHandler.getScreenId()+"/"+packageName));
|
||||
router.route(screenConfig.screenAdmin + "/*").handler(StaticHandler.create(screenConfig.getScreenDir() + "/" + apiHandler.getScreenId() + "/" + packageName));
|
||||
router.get(screenConfig.screenAdmin).handler(ctx -> {
|
||||
ctx.response().sendFile(screenConfig.getScreenDir()+"/"+apiHandler.getScreenId() +"/"+packageName+ "/index.html");
|
||||
ctx.response().sendFile(screenConfig.getScreenDir() + "/" + apiHandler.getScreenId() + "/" + packageName + "/index.html");
|
||||
});
|
||||
router.get("/*").handler(ctx -> {
|
||||
String res = apiHandler.httpReq(ctx.request(), ctx.response());
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
package cc.iotkit.system.controller;
|
||||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.api.Request;
|
||||
import cc.iotkit.common.excel.utils.ExcelUtil;
|
||||
import cc.iotkit.common.log.annotation.Log;
|
||||
import cc.iotkit.common.log.enums.BusinessType;
|
||||
import cc.iotkit.common.validate.AddGroup;
|
||||
import cc.iotkit.common.validate.EditGroup;
|
||||
import cc.iotkit.common.web.core.BaseController;
|
||||
import cc.iotkit.system.dto.bo.SysAppBo;
|
||||
import cc.iotkit.system.dto.vo.SysAppVo;
|
||||
import cc.iotkit.system.service.ISysAppService;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 应用信息
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/app")
|
||||
public class SysAppController extends BaseController {
|
||||
|
||||
private final ISysAppService sysAppService;
|
||||
|
||||
/**
|
||||
* 查询应用信息列表
|
||||
*/
|
||||
@SaCheckPermission("system:app:list")
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询应用信息列表")
|
||||
public Paging<SysAppVo> list( PageRequest<SysAppBo> pageQuery) {
|
||||
return sysAppService.queryPageList(pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出应用信息列表
|
||||
*/
|
||||
@ApiOperation("导出应用信息列表")
|
||||
@SaCheckPermission("system:app:export")
|
||||
@Log(title = "应用信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(SysAppBo bo, HttpServletResponse response) {
|
||||
List<SysAppVo> list = sysAppService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "应用信息", SysAppVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用信息详细信息
|
||||
*
|
||||
*/
|
||||
@SaCheckPermission("system:app:query")
|
||||
@PostMapping("/getDetail")
|
||||
@ApiOperation("获取应用信息详细信息")
|
||||
public SysAppVo getDetail(@Validated @RequestBody Request<Long> request) {
|
||||
return sysAppService.queryById(request.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增应用信息
|
||||
*/
|
||||
@SaCheckPermission("system:app:add")
|
||||
@Log(title = "应用信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/add")
|
||||
@ApiOperation("新增应用信息")
|
||||
public Long add(@Validated(AddGroup.class) @RequestBody Request<SysAppBo> request) {
|
||||
return sysAppService.insertByBo(request.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改应用信息
|
||||
*/
|
||||
@SaCheckPermission("system:app:edit")
|
||||
@Log(title = "应用信息", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
@ApiOperation("修改应用信息")
|
||||
public boolean edit(@Validated(EditGroup.class) @RequestBody Request<SysAppBo> request) {
|
||||
return sysAppService.updateByBo(request.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除应用信息
|
||||
*
|
||||
*/
|
||||
@SaCheckPermission("system:app:remove")
|
||||
@Log(title = "应用信息", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除应用信息")
|
||||
public boolean remove(@Validated @RequestBody Request<List<Long>> query) {
|
||||
return sysAppService.deleteWithValidByIds(query.getData(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package cc.iotkit.system.dto.bo;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import cc.iotkit.common.validate.AddGroup;
|
||||
import cc.iotkit.common.validate.EditGroup;
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 应用信息业务对象 SYS_APP
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = SysApp.class, reverseConvertGenerate = false)
|
||||
public class SysAppBo extends BaseDto {
|
||||
|
||||
|
||||
@NotBlank(message = "id不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
@NotBlank(message = "appId不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
@ApiModelProperty(value = "appId", required = true)
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* appSecret
|
||||
*/
|
||||
@NotBlank(message = "appSecret不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
@ApiModelProperty(value = "appSecret", required = true)
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*/
|
||||
@NotBlank(message = "应用类型不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
@ApiModelProperty(value = "应用类型", required = true)
|
||||
private String appType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "备注", required = true)
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package cc.iotkit.system.dto.vo;
|
||||
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 应用信息视图对象 SYS_APP
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = SysApp.class)
|
||||
public class SysAppVo implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
@ApiModelProperty(value = "appId")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* appSecret
|
||||
*/
|
||||
@ApiModelProperty(value = "appSecret")
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*/
|
||||
@ApiModelProperty(value = "应用类型")
|
||||
private String appType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cc.iotkit.system.service;
|
||||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.system.dto.bo.SysAppBo;
|
||||
import cc.iotkit.system.dto.vo.SysAppVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用信息Service接口
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
public interface ISysAppService {
|
||||
|
||||
/**
|
||||
* 查询应用信息
|
||||
*/
|
||||
SysAppVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询应用信息列表
|
||||
*/
|
||||
Paging<SysAppVo> queryPageList(PageRequest<SysAppBo> pageQuery);
|
||||
|
||||
/**
|
||||
* 查询应用信息列表
|
||||
*/
|
||||
List<SysAppVo> queryList(SysAppBo bo);
|
||||
|
||||
/**
|
||||
* 新增应用信息
|
||||
*/
|
||||
Long insertByBo(SysAppBo bo);
|
||||
|
||||
/**
|
||||
* 修改应用信息
|
||||
*/
|
||||
Boolean updateByBo(SysAppBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除应用信息信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package cc.iotkit.system.service.impl;
|
||||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.exception.BizException;
|
||||
import cc.iotkit.common.utils.MapstructUtils;
|
||||
import cc.iotkit.data.system.ISysAppData;
|
||||
import cc.iotkit.model.system.SysApp;
|
||||
import cc.iotkit.system.dto.bo.SysAppBo;
|
||||
import cc.iotkit.system.dto.vo.SysAppVo;
|
||||
import cc.iotkit.system.service.ISysAppService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 应用信息Service业务层处理
|
||||
*
|
||||
* @author tfd
|
||||
* @date 2023-08-10
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysAppServiceImpl implements ISysAppService {
|
||||
|
||||
private final ISysAppData baseData;
|
||||
|
||||
/**
|
||||
* 查询应用信息
|
||||
*/
|
||||
@Override
|
||||
public SysAppVo queryById(Long id){
|
||||
return MapstructUtils.convert(baseData.findById(id), SysAppVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用信息列表
|
||||
*/
|
||||
@Override
|
||||
public Paging<SysAppVo> queryPageList(PageRequest<SysAppBo> pageQuery) {
|
||||
Paging<SysAppVo> result = baseData.findAll(pageQuery.to(SysApp.class)).to(SysAppVo.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用信息列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysAppVo> queryList(SysAppBo bo) {
|
||||
|
||||
return MapstructUtils.convert(baseData.findAllByCondition(bo.to(SysApp.class)), SysAppVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增应用信息
|
||||
*/
|
||||
@Override
|
||||
public Long insertByBo(SysAppBo bo) {
|
||||
SysApp add = MapstructUtils.convert(bo, SysApp.class);
|
||||
validEntityBeforeSave(add);
|
||||
baseData.save(add);
|
||||
if (add == null) {
|
||||
throw new BizException("新增失败");
|
||||
}
|
||||
return add.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改应用信息
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(SysAppBo bo) {
|
||||
SysApp update = MapstructUtils.convert(bo, SysApp.class);
|
||||
validEntityBeforeSave(update);
|
||||
SysApp ret = baseData.save(update);
|
||||
if(ret == null){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SysApp entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除应用信息
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
baseData.deleteByIds(ids);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,12 @@ import cc.iotkit.common.constant.GlobalConstants;
|
|||
import cc.iotkit.common.enums.DeviceType;
|
||||
import cc.iotkit.common.enums.LoginType;
|
||||
import cc.iotkit.common.enums.UserStatus;
|
||||
import cc.iotkit.common.enums.UserType;
|
||||
import cc.iotkit.common.exception.BizException;
|
||||
import cc.iotkit.common.exception.user.UserException;
|
||||
import cc.iotkit.common.log.event.LogininforEvent;
|
||||
import cc.iotkit.common.redis.utils.RedisUtils;
|
||||
import cc.iotkit.common.satoken.utils.AuthUtil;
|
||||
import cc.iotkit.common.satoken.utils.LoginHelper;
|
||||
import cc.iotkit.common.tenant.helper.TenantHelper;
|
||||
import cc.iotkit.common.undefined.LoginUser;
|
||||
|
@ -17,7 +19,9 @@ import cc.iotkit.common.undefined.XcxLoginUser;
|
|||
import cc.iotkit.common.utils.*;
|
||||
import cc.iotkit.common.web.config.properties.CaptchaProperties;
|
||||
import cc.iotkit.common.web.utils.ServletUtils;
|
||||
import cc.iotkit.data.manager.IUserInfoData;
|
||||
import cc.iotkit.data.system.ISysUserData;
|
||||
import cc.iotkit.model.UserInfo;
|
||||
import cc.iotkit.model.system.SysUser;
|
||||
import cc.iotkit.system.dto.vo.SysUserVo;
|
||||
import cc.iotkit.system.service.ISysPermissionService;
|
||||
|
@ -33,6 +37,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -47,6 +52,7 @@ import java.util.function.Supplier;
|
|||
public class SysLoginService {
|
||||
|
||||
private final ISysUserData userData;
|
||||
private final IUserInfoData userInfoData;
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysTenantService tenantService;
|
||||
|
@ -57,6 +63,15 @@ public class SysLoginService {
|
|||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
|
||||
@Value("${weixin.appid}")
|
||||
private String appid;
|
||||
|
||||
@Value("${weixin.secret}")
|
||||
private String secret;
|
||||
|
||||
@Value("${weixin.authUrl}")
|
||||
private String authUrl;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
|
@ -127,25 +142,29 @@ public class SysLoginService {
|
|||
|
||||
public String xcxLogin(String xcxCode) {
|
||||
// xcxCode 为 小程序调用 wx.login 授权后获取
|
||||
// todo 以下自行实现
|
||||
// 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid
|
||||
String openid = "";
|
||||
SysUserVo user = loadUserByOpenid(openid);
|
||||
String url=authUrl+"?appid="+appid+"&secret="+secret+"&js_code="+xcxCode+"&grant_type=authorization_code";
|
||||
String ret=WeChatUtil.httpRequest(url,"GET",null);
|
||||
String openid = JsonUtils.parseMap(ret).getStr("openid");;
|
||||
UserInfo user = null;
|
||||
try {
|
||||
user = loadUserByOpenid(openid);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 校验租户
|
||||
checkTenant(user.getTenantId());
|
||||
// checkTenant(user.getTenantId());
|
||||
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||
XcxLoginUser loginUser = new XcxLoginUser();
|
||||
loginUser.setTenantId(user.getTenantId());
|
||||
loginUser.setUserId(user.getId());
|
||||
loginUser.setUsername(user.getUserName());
|
||||
loginUser.setUserType(user.getUserType());
|
||||
loginUser.setUsername(user.getNickName());
|
||||
loginUser.setUserType(UserType.APP_USER.getUserType());
|
||||
loginUser.setOpenid(openid);
|
||||
// 生成token
|
||||
LoginHelper.loginByDevice(loginUser, DeviceType.XCX);
|
||||
|
||||
recordLoginInfo(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
recordLoginInfo(user.getId());
|
||||
recordLoginInfo(loginUser.getTenantId(), user.getNickName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
// recordLoginInfo(user.getId());
|
||||
return StpUtil.getTokenValue();
|
||||
}
|
||||
|
||||
|
@ -278,16 +297,18 @@ public class SysLoginService {
|
|||
|
||||
}
|
||||
|
||||
private SysUserVo loadUserByOpenid(String openid) {
|
||||
private UserInfo loadUserByOpenid(String openid) throws Exception {
|
||||
// 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户
|
||||
// todo 自行实现 userService.selectUserByOpenid(openid);
|
||||
SysUserVo user = new SysUserVo();
|
||||
UserInfo user=userInfoData.findByUid(openid);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", openid);
|
||||
// todo 用户不存在 业务逻辑自行实现
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", openid);
|
||||
// todo 用户已被停用 业务逻辑自行实现
|
||||
user=new UserInfo();
|
||||
user.setType(UserInfo.USER_TYPE_CLIENT);
|
||||
user.setUid(openid);
|
||||
user.setRoles(Collections.singletonList(Constants.ROLE_CLIENT));
|
||||
user.setCreateAt(System.currentTimeMillis());
|
||||
user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_CLIENT_USER));
|
||||
user = userInfoData.save(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue