1.控制类添加服务层
This commit is contained in:
@@ -5,10 +5,13 @@ import vvpkassistant.Data.ResponseData;
|
|||||||
import vvpkassistant.Data.ResponseInfo;
|
import vvpkassistant.Data.ResponseInfo;
|
||||||
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
|
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
|
||||||
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
|
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
|
||||||
|
import vvpkassistant.FunctionConfig.service.FunctionConfigService;
|
||||||
import vvpkassistant.common.ErrorCode;
|
import vvpkassistant.common.ErrorCode;
|
||||||
import vvpkassistant.config.FunctionConfigHolder;
|
import vvpkassistant.config.FunctionConfigHolder;
|
||||||
import vvpkassistant.exception.BusinessException;
|
import vvpkassistant.exception.BusinessException;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("config")
|
@RequestMapping("config")
|
||||||
public class FunctionConfigController {
|
public class FunctionConfigController {
|
||||||
@@ -16,6 +19,9 @@ public class FunctionConfigController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private FunctionConfigMapper configMapper;
|
private FunctionConfigMapper configMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FunctionConfigService functionConfigService;
|
||||||
|
|
||||||
// 获取所有配置
|
// 获取所有配置
|
||||||
@GetMapping("getAllConfig")
|
@GetMapping("getAllConfig")
|
||||||
public ResponseData<Object> getAllConfig() {
|
public ResponseData<Object> getAllConfig() {
|
||||||
@@ -26,7 +32,7 @@ public class FunctionConfigController {
|
|||||||
@PostMapping("updateConfigValue")
|
@PostMapping("updateConfigValue")
|
||||||
public ResponseData<Object> updateConfigValue(@RequestBody FunctionConfigModel model) {
|
public ResponseData<Object> updateConfigValue(@RequestBody FunctionConfigModel model) {
|
||||||
// 1. 更新数据库
|
// 1. 更新数据库
|
||||||
configMapper.updateById(model);
|
functionConfigService.updateById(model);
|
||||||
// 2. 更新内存
|
// 2. 更新内存
|
||||||
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getFunctionName().equals(c.getFunctionName()));
|
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getFunctionName().equals(c.getFunctionName()));
|
||||||
FunctionConfigHolder.CONFIGS.add(model);
|
FunctionConfigHolder.CONFIGS.add(model);
|
||||||
@@ -41,7 +47,7 @@ public class FunctionConfigController {
|
|||||||
if (isDuplicate) {
|
if (isDuplicate) {
|
||||||
throw new BusinessException(ErrorCode.CONFIG_NAME_DUPLICATE);
|
throw new BusinessException(ErrorCode.CONFIG_NAME_DUPLICATE);
|
||||||
}else {
|
}else {
|
||||||
configMapper.insert(newModel);
|
functionConfigService.save(newModel);
|
||||||
FunctionConfigHolder.CONFIGS.add(newModel);
|
FunctionConfigHolder.CONFIGS.add(newModel);
|
||||||
return ResponseData.success("");
|
return ResponseData.success("");
|
||||||
}
|
}
|
||||||
@@ -49,8 +55,7 @@ public class FunctionConfigController {
|
|||||||
|
|
||||||
@PostMapping("deleteConfigById")
|
@PostMapping("deleteConfigById")
|
||||||
public ResponseData<Object> deleteConfigById(@RequestBody FunctionConfigModel model) {
|
public ResponseData<Object> deleteConfigById(@RequestBody FunctionConfigModel model) {
|
||||||
int i = configMapper.deleteById(model);
|
if (functionConfigService.removeById(model)) {
|
||||||
if (i == 1) {
|
|
||||||
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getId().equals(c.getId()));
|
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getId().equals(c.getId()));
|
||||||
return ResponseData.success("");
|
return ResponseData.success("");
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package vvpkassistant.FunctionConfig.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/4 13:37
|
||||||
|
*/
|
||||||
|
public interface FunctionConfigService extends IService<FunctionConfigModel> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package vvpkassistant.FunctionConfig.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
|
||||||
|
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/4 13:38
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class FunctionConfigServiceImpl extends ServiceImpl<FunctionConfigMapper,FunctionConfigModel> implements FunctionConfigService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FunctionConfigMapper functionConfigMapper;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -112,8 +112,7 @@ public class UserController {
|
|||||||
//否则直接返回用户
|
//否则直接返回用户
|
||||||
return ResponseData.success(result);
|
return ResponseData.success(result);
|
||||||
}
|
}
|
||||||
|
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||||
return ResponseData.error(ErrorCode.SYSTEM_ERROR.getCode(),"未知错误");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手机号登录 / 注册
|
// 手机号登录 / 注册
|
||||||
|
|||||||
Reference in New Issue
Block a user