package com.jsh.erp.controller;
|
|
import com.jsh.erp.datasource.entities.CloudContent;
|
import com.jsh.erp.service.cloudContent.CloudContentService;
|
import com.jsh.erp.utils.BaseResponseInfo;
|
import io.swagger.annotations.Api;
|
import org.springframework.web.bind.annotation.*;
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@RestController
|
@RequestMapping("/cloudContent")
|
@Api(tags = "内容管理接口")
|
public class CloudContentController {
|
@Resource
|
private CloudContentService cloudContentService;
|
|
@GetMapping("/list")
|
public BaseResponseInfo list(@RequestParam(value = "title", required = false) String title,
|
@RequestParam(value = "type", required = false) String type,
|
@RequestParam(value = "status", required = false) Integer status,
|
@RequestParam("currentPage") Integer currentPage,
|
@RequestParam("pageSize") Integer pageSize) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
Map<String, Object> map = new HashMap<>();
|
try {
|
CloudContent query = new CloudContent();
|
query.setTitle(title);
|
query.setType(type);
|
query.setStatus(status);
|
|
List<CloudContent> dataList = cloudContentService.getList(query);
|
int total = dataList.size();
|
map.put("total", total);
|
map.put("rows", dataList);
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = map;
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@GetMapping("/getByType")
|
public BaseResponseInfo getByType(@RequestParam(value = "type", required = true) String type) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
CloudContent cloudContent = cloudContentService.getByType(type);
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = cloudContent;
|
} catch (Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@GetMapping("/{id}")
|
public BaseResponseInfo getById(@PathVariable Long id) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
CloudContent data = cloudContentService.getById(id);
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = data;
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@PostMapping
|
public BaseResponseInfo add(@RequestBody CloudContent cloudContent) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
int result = cloudContentService.add(cloudContent);
|
if(result > 0) {
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = "新增成功";
|
}
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@PutMapping
|
public BaseResponseInfo update(@RequestBody CloudContent cloudContent) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
int result = cloudContentService.update(cloudContent);
|
if(result > 0) {
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = "修改成功";
|
}
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@DeleteMapping("/{id}")
|
public BaseResponseInfo delete(@PathVariable Long id) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
int result = cloudContentService.deleteById(id);
|
if(result > 0) {
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = "删除成功";
|
}
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
|
@DeleteMapping("/deleteBatch")
|
public BaseResponseInfo deleteBatch(@RequestParam("ids") String ids) {
|
BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
|
try {
|
String[] idArray = ids.split(",");
|
int result = 0;
|
for(String id : idArray) {
|
result += cloudContentService.deleteById(Long.parseLong(id));
|
}
|
if(result > 0) {
|
baseResponseInfo.code = 200;
|
baseResponseInfo.data = "删除成功";
|
}
|
} catch(Exception e) {
|
baseResponseInfo.code = 500;
|
baseResponseInfo.data = e.getMessage();
|
}
|
return baseResponseInfo;
|
}
|
}
|