131 lines
3.8 KiB
Java
131 lines
3.8 KiB
Java
package com.whdc.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.whdc.model.entity.Organization;
|
|
import com.whdc.model.entity.UnitDict;
|
|
import com.whdc.model.group.Find;
|
|
import com.whdc.model.group.Insert;
|
|
import com.whdc.model.group.Update;
|
|
import com.whdc.service.IOrganizationService;
|
|
import com.whdc.service.IUnitDictService;
|
|
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.apache.commons.lang3.StringUtils;
|
|
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("/unitdict")
|
|
public class UnitDictController {
|
|
|
|
@Autowired
|
|
private IUnitDictService service;
|
|
@Autowired
|
|
private IOrganizationService organizationService;
|
|
|
|
|
|
@ApiOperation(value = "查询所有")
|
|
@PostMapping(value = "find")
|
|
public ResultJson<UnitDict> find(@RequestBody @Validated(Find.class) UnitDict dto) {
|
|
|
|
if (Objects.isNull(organizationService.getById( dto.getOId()))) {
|
|
return ResultJson.error("组织类型Id不存在");
|
|
}
|
|
|
|
|
|
LambdaQueryChainWrapper<UnitDict> query = service.lambdaQuery();
|
|
String name = dto.getName();
|
|
if (StringUtils.isNotBlank(name)) {
|
|
query.like(UnitDict::getName, name);
|
|
}
|
|
query.eq(UnitDict::getOId, dto.getOId());
|
|
|
|
query.orderByAsc(UnitDict::getSort);
|
|
return ResultJson.ok(query.list());
|
|
|
|
|
|
}
|
|
|
|
// @ApiOperation(value = "分页查询")
|
|
// @PostMapping(value = "page")
|
|
public ResultJson<UnitDict> page(@RequestBody UnitDict dto) {
|
|
|
|
return ResultJson.ok(service.page(dto));
|
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "添加")
|
|
@PostMapping(value = "save")
|
|
public ResultJson insert(@RequestBody @Validated(Insert.class) UnitDict model) {
|
|
|
|
if (Objects.isNull(organizationService.getById( model.getOId()))) {
|
|
return ResultJson.error("组织类型Id不存在");
|
|
}
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
service.lambdaQuery()
|
|
.eq(UnitDict::getName, String.valueOf(model.getName()).trim())
|
|
.eq(UnitDict::getOId, String.valueOf(model.getOId()).trim())
|
|
.list())
|
|
) {
|
|
return ResultJson.error("该名称重复");
|
|
}
|
|
|
|
return ResultJson.ok(service.save(model));
|
|
|
|
}
|
|
|
|
@ApiOperation(value = "修改")
|
|
@PostMapping(value = "edit")
|
|
public ResultJson update(@RequestBody @Validated(Update.class) UnitDict model) {
|
|
|
|
|
|
if (Objects.isNull(organizationService.getById( model.getOId()))) {
|
|
return ResultJson.error("组织类型Id不存在");
|
|
}
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
service.lambdaQuery()
|
|
.eq(UnitDict::getName, String.valueOf(model.getName()).trim())
|
|
.eq(UnitDict::getOId, String.valueOf(model.getOId()).trim())
|
|
.ne(UnitDict::getId, model.getId())
|
|
.list())
|
|
) {
|
|
return ResultJson.error("该名称重复");
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|