package org.example.ssmico.demos.web.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.example.ssmico.demos.web.entity.IcoOrder;
|
import org.example.ssmico.demos.web.entity.TConfiguration;
|
import org.example.ssmico.demos.web.service.TConfigurationService;
|
import org.example.ssmico.demos.web.util.ResultObject;
|
import org.example.ssmico.demos.web.util.ServerResponse;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.List;
|
|
/**
|
* @program: ssm-ico
|
* @description: 配置表
|
* @create: 2024-04-15 11:11
|
**/
|
@Controller
|
@RequestMapping({"/wap/api/tConfiguration"})
|
@CrossOrigin
|
public class TConfigurationController {
|
|
@Autowired
|
private TConfigurationService service;
|
|
@ResponseBody
|
@RequestMapping(value = "/add")
|
public ServerResponse add(TConfiguration tConfiguration){
|
try {
|
long count = service.count(new LambdaQueryWrapper<TConfiguration>()
|
.eq(TConfiguration::getConfigKey, tConfiguration.getConfigKey()));
|
if(count > 0){
|
return ServerResponse.createByErrorMsg("当前配置key已存在");
|
}
|
service.save(tConfiguration);
|
return ServerResponse.createBySuccess();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ServerResponse.createByErrorMsg("系统错误");
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/getPageList")
|
public ServerResponse getPageList(String key,Integer pageNo,Integer size){
|
try {
|
if (null == pageNo || null == size) {
|
pageNo = 1;
|
size = 10;
|
}
|
// 创建分页对象
|
Page<TConfiguration> page = new Page<>(pageNo, size);
|
Page<TConfiguration> pageList = service.page(page, new LambdaQueryWrapper<TConfiguration>().like(!StringUtils.isBlank(key),TConfiguration::getConfigKey, key));
|
return ServerResponse.createBySuccess(pageList);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ServerResponse.createByErrorMsg("系统错误");
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/update")
|
public ServerResponse update(TConfiguration tConfiguration){
|
try {
|
long count = service.count(new LambdaQueryWrapper<TConfiguration>()
|
.eq(TConfiguration::getConfigKey, tConfiguration.getConfigKey())
|
.ne(TConfiguration::getId, tConfiguration.getId()));
|
if(count > 0){
|
return ServerResponse.createByErrorMsg("当前配置key已存在");
|
}
|
service.updateById(tConfiguration);
|
return ServerResponse.createBySuccess();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ServerResponse.createByErrorMsg("系统错误");
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/delete")
|
public ServerResponse delete(Integer id){
|
try {
|
service.removeById(id);
|
return ServerResponse.createBySuccess();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ServerResponse.createByErrorMsg("系统错误");
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/getConfiguration")
|
public ResultObject getConfiguration(){
|
ResultObject resultObject= new ResultObject();
|
try {
|
List<TConfiguration> list = service.list();
|
resultObject.setData(list);
|
return resultObject;
|
}catch (Exception e){
|
e.printStackTrace();
|
resultObject.setCode("1");
|
resultObject.setMsg("程序错误");
|
return resultObject;
|
}
|
}
|
}
|