110 lines
3.0 KiB
Java
110 lines
3.0 KiB
Java
package com.whdc.controller;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.whdc.model.dto.FcDto;
|
|
import com.whdc.model.entity.Fc;
|
|
import com.whdc.model.group.Find;
|
|
import com.whdc.model.group.Insert;
|
|
import com.whdc.model.group.Update;
|
|
import com.whdc.model.vo.FcVo;
|
|
import com.whdc.service.IFcService;
|
|
import com.whdc.utils.ResultJson;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* @author xusan
|
|
* @date 2024-05-11
|
|
*/
|
|
@Slf4j
|
|
@Api(tags = "常用联系人 - Controller")
|
|
@RestController
|
|
@RequestMapping("/fc")
|
|
public class FcController {
|
|
|
|
@Autowired
|
|
private IFcService service;
|
|
|
|
|
|
|
|
// @ApiOperation(value = "查询所有")
|
|
// @PostMapping(value = "find")
|
|
public ResultJson<Fc> find(@RequestBody Fc dto) {
|
|
|
|
return ResultJson.ok(service.find(dto));
|
|
|
|
}
|
|
|
|
// @ApiOperation(value = "分页查询")
|
|
// @PostMapping(value = "page")
|
|
public ResultJson<FcVo> page(@RequestBody @Validated(Find.class) FcDto dto) {
|
|
|
|
return ResultJson.ok(service.page(dto));
|
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "添加")
|
|
@PostMapping(value = "save")
|
|
public ResultJson insert(@RequestBody @Validated(Insert.class) Fc model) {
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
service.lambdaQuery()
|
|
.eq(Fc::getUserId,String.valueOf(model.getUserId()).trim())
|
|
.eq(Fc::getAbId,String.valueOf(model.getAbId()).trim())
|
|
.list())
|
|
){
|
|
return ResultJson.error("该名称重复");
|
|
}
|
|
|
|
model.setUserId(Integer.valueOf(String.valueOf(StpUtil.getLoginId())));
|
|
|
|
return ResultJson.ok(service.save(model));
|
|
|
|
}
|
|
|
|
@ApiOperation(value = "修改")
|
|
@PostMapping(value = "edit")
|
|
public ResultJson update(@RequestBody @Validated(Update.class) Fc model) {
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
service.lambdaQuery()
|
|
.eq(Fc::getUserId,String.valueOf(model.getUserId()).trim())
|
|
.eq(Fc::getAbId,String.valueOf(model.getAbId()).trim())
|
|
.eq(Fc::getType,String.valueOf(model.getType()).trim())
|
|
.ne(Fc::getId, model.getId())
|
|
.list())
|
|
){
|
|
return ResultJson.error("该排序已添加");
|
|
}
|
|
model.setUserId(Integer.valueOf(String.valueOf(StpUtil.getLoginId())));
|
|
|
|
return ResultJson.ok(service.updateById(model));
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "删除")
|
|
@GetMapping(value = "del/{id}")
|
|
public ResultJson delete(@PathVariable("id") Integer id) {
|
|
|
|
|
|
if (Objects.isNull(service.getById(id))) {
|
|
|
|
return ResultJson.error("当前数据不存在");
|
|
|
|
}
|
|
|
|
return ResultJson.ok(service.removeById(id));
|
|
|
|
}
|
|
|
|
}
|