新增店铺密钥接口
This commit is contained in:
parent
8ef1760b9d
commit
20b90b6c34
@ -8,8 +8,7 @@
|
||||
|
||||
package com.suisung.mall.common.modules.sync;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -17,6 +16,8 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@ -25,6 +26,7 @@ import java.util.Date;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
@ApiModel(value = "第三方App同步设置", description = "第三方App同步设置")
|
||||
@TableName("sync_app")
|
||||
public class SyncApp implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -34,26 +36,39 @@ public class SyncApp implements Serializable {
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "app key")
|
||||
@TableField(value = "app_key",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@NotEmpty(message = "app key不能为空")
|
||||
private String app_key;
|
||||
|
||||
@ApiModelProperty(value = "app 密钥")
|
||||
@TableField(value = "app_secret",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@NotEmpty(message = "app 密钥不能为空")
|
||||
private String app_secret;
|
||||
|
||||
@ApiModelProperty(value = "关联店铺Id")
|
||||
@TableField(value = "store_id",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@NotEmpty(message = "店铺id不能为空")
|
||||
private String store_id;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
@ApiModelProperty(value = "店铺名称")
|
||||
@TableField(value = "name",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@NotEmpty(message = "店铺名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "介绍")
|
||||
@TableField(value = "intro",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
private String intro;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
@ApiModelProperty(value = "状态,1可用,2不可用,3不校验签名")
|
||||
@TableField(value = "status",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@NotNull(message = "密钥状态状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "新增时间")
|
||||
@TableField(value = "created_at",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
private Date created_at;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
@TableField(value = "updated_at",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
private Date updated_at;
|
||||
}
|
||||
|
||||
@ -0,0 +1,107 @@
|
||||
package com.suisung.mall.shop.sync.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.domain.UserDto;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
import com.suisung.mall.common.modules.sync.SyncApp;
|
||||
import com.suisung.mall.common.service.impl.BaseControllerImpl;
|
||||
import com.suisung.mall.common.utils.ContextUtil;
|
||||
import com.suisung.mall.shop.sync.service.SyncAppService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Api(tags = "页面导航表-新入住商家密钥配置")
|
||||
@RestController
|
||||
@RequestMapping("/admin/shop/sync-app")
|
||||
public class SyncAppController extends BaseControllerImpl {
|
||||
|
||||
@Autowired
|
||||
private SyncAppService syncAppService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "列表查询-分页列表查询店铺数据库连接配置", notes = "列表查询-分页列表查询店铺数据库连接配置")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public IPage<SyncApp> list(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
UserDto userDto= ContextUtil.getCurrentUser();
|
||||
assert userDto != null;
|
||||
if(userDto.getRole_id()!=9){
|
||||
throw new ApiException("权限不足");
|
||||
}
|
||||
String name=getParameter("name");
|
||||
return syncAppService.pageSyncAppList(name,null,pageNum,pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param syncApp
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "新增-店铺密钥", notes = "新增-店铺密钥")
|
||||
@RequestMapping(value = "/saveSyncApp", method = RequestMethod.POST)
|
||||
public CommonResult saveSyncApp(@RequestBody @Valid SyncApp syncApp) {
|
||||
UserDto userDto= ContextUtil.getCurrentUser();
|
||||
assert userDto != null;
|
||||
if(userDto.getRole_id()!=9){
|
||||
throw new ApiException("权限不足");
|
||||
}
|
||||
boolean result= syncAppService.addSyncApp(syncApp);
|
||||
if(result){
|
||||
return CommonResult.success("操作成功");
|
||||
}
|
||||
return CommonResult.failed("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param syncApp
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "更新-密钥", notes = "更新-密钥")
|
||||
@RequestMapping(value = "/editSyncApp", method = RequestMethod.PUT)
|
||||
public CommonResult editSyncApp(@RequestBody @Valid SyncApp syncApp) {
|
||||
UserDto userDto= ContextUtil.getCurrentUser();
|
||||
assert userDto != null;
|
||||
if(userDto.getRole_id()!=9){
|
||||
throw new ApiException("权限不足");
|
||||
}
|
||||
boolean result= syncAppService.updateSyncApp(syncApp);
|
||||
if(result){
|
||||
return CommonResult.success("操作成功");
|
||||
}
|
||||
return CommonResult.failed("操作失败");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param syncAppId
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除-密钥", notes = "删除-密钥")
|
||||
@RequestMapping(value = "/delSyncApp", method = RequestMethod.DELETE)
|
||||
public CommonResult delSyncApp(@RequestParam Long syncAppId) {
|
||||
UserDto userDto= ContextUtil.getCurrentUser();
|
||||
assert userDto != null;
|
||||
if(userDto.getRole_id()!=9){
|
||||
throw new ApiException("权限不足");
|
||||
}
|
||||
boolean result= syncAppService.deleteSyncApp(syncAppId);
|
||||
if(result){
|
||||
return CommonResult.success("操作成功");
|
||||
}
|
||||
return CommonResult.failed("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
@ -54,11 +54,10 @@ public interface SyncAppService extends IService<SyncApp> {
|
||||
/**
|
||||
* 修改 app key 和 app 密钥
|
||||
*
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @param syncApp
|
||||
* @return
|
||||
*/
|
||||
Boolean updateAppKey(String appKey, String appSecret);
|
||||
Boolean updateAppKey(SyncApp syncApp);
|
||||
|
||||
/**
|
||||
* 删除一条记录
|
||||
|
||||
@ -8,15 +8,17 @@
|
||||
|
||||
package com.suisung.mall.shop.sync.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreBase;
|
||||
import com.suisung.mall.common.modules.sync.SyncApp;
|
||||
import com.suisung.mall.common.utils.CommonUtil;
|
||||
import com.suisung.mall.common.utils.StringUtils;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||
import com.suisung.mall.shop.sync.Utils.CryptoUtils;
|
||||
import com.suisung.mall.shop.sync.mapper.SyncAppMapper;
|
||||
import com.suisung.mall.shop.sync.service.SyncAppService;
|
||||
@ -25,8 +27,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Service
|
||||
@lombok.extern.slf4j.Slf4j
|
||||
@ -35,6 +37,9 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
|
||||
@Autowired
|
||||
private SyncAppMapper syncAppMapper;
|
||||
|
||||
@Autowired
|
||||
private ShopStoreBaseService shopStoreBaseService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据 appKey 获取一条记录
|
||||
@ -65,17 +70,15 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
|
||||
@Override
|
||||
public IPage<SyncApp> pageSyncAppList(String keyword, Integer status, Integer pageNum, Integer pageSize) {
|
||||
QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>();
|
||||
if(StrUtil.isNotBlank(keyword)){
|
||||
queryWrapper.like("name", keyword);
|
||||
|
||||
QueryWrapper<SyncApp> queryWrapper2 = new QueryWrapper<>();
|
||||
queryWrapper2.like("intro", keyword).or((Consumer<QueryWrapper<SyncApp>>) queryWrapper);
|
||||
|
||||
}
|
||||
if (status != null && status > 0) {
|
||||
queryWrapper.eq("status", status);
|
||||
queryWrapper2.eq("status", status);
|
||||
queryWrapper.eq("status", status);
|
||||
}
|
||||
|
||||
return lists(queryWrapper2, pageNum, pageSize);
|
||||
return lists(queryWrapper, pageNum, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,6 +92,19 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
|
||||
if (syncApp == null) {
|
||||
return false;
|
||||
}
|
||||
QueryWrapper<ShopStoreBase> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("store_id", Integer.valueOf(syncApp.getStore_id()));
|
||||
queryWrapper.eq("store_name", syncApp.getName());
|
||||
List<ShopStoreBase> storeBaseList=shopStoreBaseService.list(queryWrapper);
|
||||
if(storeBaseList.isEmpty()){
|
||||
throw new ApiException("不存在店铺");
|
||||
}
|
||||
QueryWrapper<SyncApp> queryWrapperSync = new QueryWrapper<>();
|
||||
queryWrapperSync.eq("store_id", syncApp.getStore_id());
|
||||
List<SyncApp> syncAppList= list(queryWrapperSync);
|
||||
if(!syncAppList.isEmpty()){
|
||||
throw new ApiException("已存在店铺密钥信息");
|
||||
}
|
||||
return add(syncApp);
|
||||
}
|
||||
|
||||
@ -103,26 +119,39 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
|
||||
if (syncApp == null) {
|
||||
return false;
|
||||
}
|
||||
return updateById(syncApp);
|
||||
if(syncApp.getId() == null){
|
||||
return false;
|
||||
}
|
||||
QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", syncApp.getId());
|
||||
List<SyncApp> syncAppList= list(queryWrapper);
|
||||
if(syncAppList.isEmpty()){
|
||||
throw new ApiException("不存在该店铺密钥信息,请新增");
|
||||
}
|
||||
SyncApp newSyncApp= syncAppList.get(0);
|
||||
newSyncApp.setApp_key(syncApp.getApp_key());
|
||||
newSyncApp.setApp_secret(syncApp.getApp_secret());
|
||||
newSyncApp.setIntro(syncApp.getIntro());
|
||||
newSyncApp.setStatus(syncApp.getStatus());
|
||||
return updateById(newSyncApp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 app key 和 app 密钥
|
||||
*
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @param syncApp
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateAppKey(String appKey, String appSecret) {
|
||||
if (appKey == null || appSecret == null) {
|
||||
public Boolean updateAppKey(SyncApp syncApp) {
|
||||
if (StringUtils.isEmpty(syncApp.getApp_key()) || StringUtils.isEmpty(syncApp.getApp_secret())
|
||||
|| syncApp.getId()==null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateWrapper<SyncApp> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("app_key", appKey);
|
||||
updateWrapper.eq("app_secret", appSecret);
|
||||
|
||||
updateWrapper.set("app_key", syncApp.getApp_key());
|
||||
updateWrapper.set("app_secret", syncApp.getApp_secret());
|
||||
updateWrapper.eq("app_key", syncApp.getId());
|
||||
|
||||
return update(updateWrapper);
|
||||
}
|
||||
@ -176,6 +205,10 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
|
||||
return null;
|
||||
}
|
||||
|
||||
if (result.getStatus().equals(2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(result.getStatus().equals(3)){
|
||||
// 不验证签名
|
||||
return result;
|
||||
|
||||
4
sql/shop/dev/20250920_dml.sql
Normal file
4
sql/shop/dev/20250920_dml.sql
Normal file
@ -0,0 +1,4 @@
|
||||
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/sync-app/list', 'index', 'master', '', '0', '/admin/shop/sync-app/list','分页查询密钥列表');
|
||||
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/sync-app/saveSyncApp', 'index', 'master', '', '0', '/admin/shop/sync-app/saveSyncApp','新增店铺密钥');
|
||||
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/sync-app/editSyncApp', 'index', 'master', '', '0', '/admin/shop/sync-app/editSyncApp','修改店铺密钥信息');
|
||||
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/sync-app/delSyncApp', 'index', 'master', '', '0', '/admin/shop/sync-app/delSyncApp','删除店铺密钥信息');
|
||||
Loading…
Reference in New Issue
Block a user