package com.terra.system.controller.data;
|
|
import com.terra.system.annotation.SysLog;
|
import com.terra.system.controller.all.BaseController;
|
import com.terra.system.entity.all.ResponseMsg;
|
import com.terra.system.entity.data.VerEntity;
|
import com.terra.system.entity.sys.UserEntity;
|
import com.terra.system.service.data.VerService;
|
import com.terra.system.service.sys.TokenService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameters;
|
import javax.annotation.Resource;
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import org.springframework.web.bind.annotation.*;
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.List;
|
|
/**
|
* 版本表
|
* @author SWS
|
* @date 2022-09.29
|
*/
|
@Tag(name = "数据管理\\版本管理")
|
@RestController
|
@RequestMapping("/ver")
|
public class VerController extends BaseController {
|
@Resource
|
VerService versionService;
|
|
@Resource
|
TokenService tokenService;
|
|
@SysLog()
|
@Operation(summary = "分页查询并返回记录数")
|
@Parameters({
|
@Parameter(name = "dirid", description = "目录ID", in = ParameterIn.QUERY, example = "10"),
|
@Parameter(name = "name", description = "名称", in = ParameterIn.QUERY, example = ""),
|
@Parameter(name = "pageSize", description = "每页条数", in = ParameterIn.QUERY, example = "10"),
|
@Parameter(name = "pageIndex", description = "分页数(从1开始)", in = ParameterIn.QUERY, example = "1")
|
})
|
@GetMapping(value = "/selectByPageAndCount")
|
public ResponseMsg<List<VerEntity>> selectByPageAndCount(Integer dirid, String name, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
|
int count = versionService.selectCount(dirid, name);
|
if (count == 0) {
|
return success(0, null);
|
}
|
|
List<VerEntity> rs = versionService.selectByPage(dirid, name, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "插入一条")
|
@Parameters({
|
@Parameter(name = "entity", description = "实体类", example = "")
|
})
|
@PostMapping(value = "/insertVersion", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> insertVersion(@RequestBody VerEntity entity, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue != null) {
|
entity.setCreateUser(ue.getId());
|
}
|
|
int count = versionService.insertVersion(entity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex, -1);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "插入多条")
|
@Parameters({
|
@Parameter(name = "list", description = "实体类集合", schema = @Schema(type = "array"), example = "")
|
})
|
@PostMapping(value = "/insertVersions", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> insertVersions(@RequestParam List<VerEntity> list, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue != null) {
|
for (VerEntity entity : list) {
|
entity.setCreateUser(ue.getId());
|
}
|
}
|
|
int count = versionService.insertVersions(list);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex, -1);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "删除一条")
|
@Parameters({
|
@Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1")
|
})
|
@GetMapping(value = "/deleteVersion")
|
public ResponseMsg<Integer> deleteVersion(int id) {
|
try {
|
int count = versionService.deleteVersion(id);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex, -1);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "删除多条")
|
@Parameters({
|
@Parameter(name = "ids", description = "ID数组", schema = @Schema(type = "array"), in = ParameterIn.QUERY, example = "1,2")
|
})
|
@GetMapping(value = "/deleteVersions")
|
public ResponseMsg<Integer> deleteVersions(@RequestParam List<Integer> ids) {
|
try {
|
if (ids == null || ids.isEmpty()) {
|
return fail("id数组不能为空", -1);
|
}
|
int count = versionService.deleteVersions(ids);
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex, -1);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "更新一条")
|
@Parameters({
|
@Parameter(name = "entity", description = "实体类", example = "")
|
})
|
@ResponseBody
|
@PostMapping(value = "/updateVersion", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> updateVersion(@RequestBody VerEntity entity, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue != null) {
|
entity.setUpdateUser(ue.getId());
|
}
|
|
int count = versionService.updateVersion(entity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex, -1);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "根据ID查询")
|
@Parameters({
|
@Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1")
|
})
|
@GetMapping(value = "/selectVersion")
|
public ResponseMsg<VerEntity> selectVersion(int id) {
|
try {
|
VerEntity verEntity = versionService.selectVersion(id);
|
|
return success(verEntity);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@Operation(summary = "查询所有")
|
@GetMapping(value = "/selectVersionAll")
|
public ResponseMsg<List<VerEntity>> selectVersionAll() {
|
try {
|
List<VerEntity> list = versionService.selectVersionAll();
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
}
|