4 changed files with 146 additions and 0 deletions
-
74src/main/java/com/iflytop/gd/app/controller/SolutionsController.java
-
13src/main/java/com/iflytop/gd/app/mapper/SolutionsMapper.java
-
20src/main/java/com/iflytop/gd/app/model/entity/Solutions.java
-
39src/main/java/com/iflytop/gd/app/service/SolutionsService.java
@ -0,0 +1,74 @@ |
|||||
|
package com.iflytop.gd.app.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.iflytop.gd.app.model.entity.Solutions; |
||||
|
import com.iflytop.gd.app.service.SolutionsService; |
||||
|
import com.iflytop.gd.common.result.PageResult; |
||||
|
import com.iflytop.gd.common.result.Result; |
||||
|
import com.iflytop.gd.common.result.ResultCode; |
||||
|
import com.iflytop.gd.infrastructure.repository.base.BasePageQuery; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
@Tag(name = "溶液管理") |
||||
|
@RestController |
||||
|
@RequestMapping("/api/sols") |
||||
|
@RequiredArgsConstructor |
||||
|
@Slf4j |
||||
|
public class SolutionsController { |
||||
|
private final SolutionsService solutionsService; |
||||
|
|
||||
|
@Operation(summary = "溶液列表") |
||||
|
@GetMapping("/list") |
||||
|
public PageResult<Solutions> getAllSols(BasePageQuery pageQuery) { |
||||
|
IPage<Solutions> result = solutionsService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null); |
||||
|
return PageResult.success(result); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "添加新溶液") |
||||
|
@PostMapping("/") |
||||
|
public Result<String> addSolutions(@RequestBody Solutions solutions) { |
||||
|
Solutions existingSolutions = solutionsService.findByName(solutions.getName()); |
||||
|
if (existingSolutions == null) { |
||||
|
boolean isSuccess = solutionsService.addSolutions(solutions); |
||||
|
if (isSuccess) { |
||||
|
return Result.success(); |
||||
|
} |
||||
|
} else { |
||||
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS); |
||||
|
} |
||||
|
return Result.failed(); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "更新溶液") |
||||
|
@PutMapping("/{id}") |
||||
|
public Result<String> updateSolutions(@PathVariable Long id, @RequestBody Solutions solutions) { |
||||
|
Solutions existingSolutions = solutionsService.findByName(solutions.getName()); |
||||
|
if (existingSolutions == null) { |
||||
|
solutions.setId(id); |
||||
|
boolean isSuccess = solutionsService.updateSolutions(solutions); |
||||
|
if (isSuccess) { |
||||
|
return Result.success(); |
||||
|
} |
||||
|
} else { |
||||
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS); |
||||
|
} |
||||
|
return Result.failed(); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "删除溶液") |
||||
|
@DeleteMapping("/{ids}") |
||||
|
public Result<String> deleteUser(@Parameter(description = "溶液ID,多个以英文逗号(,)分割") @PathVariable String ids) { |
||||
|
boolean isSuccess = solutionsService.deleteSolutions(ids); |
||||
|
if (isSuccess) { |
||||
|
return Result.success(); |
||||
|
} |
||||
|
return Result.failed(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package com.iflytop.gd.app.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.iflytop.gd.app.model.entity.Solutions; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 溶液持久层接口 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface SolutionsMapper extends BaseMapper<Solutions> { |
||||
|
|
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package com.iflytop.gd.app.model.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.iflytop.gd.infrastructure.repository.base.BaseEntity; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import jakarta.validation.constraints.NotBlank; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@Schema(description = "溶液") |
||||
|
@TableName("solutions") |
||||
|
@Data |
||||
|
public class Solutions extends BaseEntity { |
||||
|
|
||||
|
@NotBlank() |
||||
|
@Schema(description = "溶液名称") |
||||
|
private String name; |
||||
|
|
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
package com.iflytop.gd.app.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.iflytop.gd.app.mapper.SolutionsMapper; |
||||
|
import com.iflytop.gd.app.model.entity.Solutions; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 溶液业务实现类 |
||||
|
*/ |
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class SolutionsService extends ServiceImpl<SolutionsMapper, Solutions> { |
||||
|
|
||||
|
public Solutions findByName(String name) { |
||||
|
return this.getOne(new LambdaQueryWrapper<Solutions>().eq(Solutions::getName, name)); |
||||
|
} |
||||
|
|
||||
|
public boolean addSolutions(Solutions solutions) { |
||||
|
return this.save(solutions); |
||||
|
} |
||||
|
|
||||
|
public boolean updateSolutions(Solutions solutions) { |
||||
|
return this.updateById(solutions); |
||||
|
} |
||||
|
|
||||
|
public boolean deleteSolutions(String idsStr) { |
||||
|
List<Long> ids = Arrays.stream(idsStr.split(",")) |
||||
|
.map(Long::parseLong) |
||||
|
.collect(Collectors.toList()); |
||||
|
return this.removeByIds(ids); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue