| | |
| | | package com.linghu.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.entity.Sectionalization; |
| | | import com.linghu.model.vo.SectionalizationUserVO; |
| | | import com.linghu.service.SectionalizationService; |
| | | import com.linghu.service.UserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @RequestMapping("/sectionalization") |
| | |
| | | @Autowired |
| | | private SectionalizationService sectionalizationService; |
| | | |
| | | /* |
| | | @PostMapping |
| | | @ApiOperation(value = "添加类型") |
| | | public ResponseResult<User> add(@RequestBody User user) { |
| | | boolean success = typeService.save(type); |
| | | if (success) { |
| | | return ResponseResult.success(type); |
| | | } |
| | | return ResponseResult.error("添加类型失败"); |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 新增分组 |
| | | */ |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加") |
| | | public ResponseResult add(@RequestBody Sectionalization sectionalization) { |
| | | List<Sectionalization> list = sectionalizationService.list(new LambdaQueryWrapper<Sectionalization>().eq(Sectionalization::getSectionalization_name, sectionalization.getSectionalization_name())); |
| | | if (list != null && list.size() > 0) { |
| | | return ResponseResult.error("该分组已存在"); |
| | | } |
| | | sectionalizationService.save(sectionalization); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | /** |
| | | * 修改分组 |
| | | */ |
| | | |
| | | @PutMapping |
| | | @ApiOperation(value = "修改") |
| | | public ResponseResult edit(@RequestBody Sectionalization sectionalization) { |
| | | List<Sectionalization> list = sectionalizationService.list(new LambdaQueryWrapper<Sectionalization>() |
| | | .ne(Sectionalization::getSectionalization_id, sectionalization.getSectionalization_id()) |
| | | .eq(Sectionalization::getSectionalization_name, sectionalization.getSectionalization_name())); |
| | | if (list != null && list.size() > 0) { |
| | | return ResponseResult.error("该分组已存在"); |
| | | } |
| | | sectionalizationService.updateById(sectionalization); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除分组 |
| | | */ |
| | | @DeleteMapping("/{sectionalization_id}") |
| | | @ApiOperation(value = "删除") |
| | | public ResponseResult delete(@PathVariable("sectionalization_id") Integer sectionalization_id) { |
| | | sectionalizationService.removeById(sectionalization_id); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 分组列表 |
| | | */ |
| | | @GetMapping() |
| | | @ApiOperation(value = "获取分组列表") |
| | | public ResponseResult<List<Sectionalization>> list() { |
| | | List<Sectionalization> list = sectionalizationService.list(); |
| | | return ResponseResult.success(list); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 列表和底下用户数据 |
| | | */ |
| | | @GetMapping("/sectionalizationUser") |
| | | @ApiOperation(value = "获取分组列表和底下用户数据") |
| | | public ResponseResult<List<SectionalizationUserVO>> sectionalizationUser() { |
| | | List<SectionalizationUserVO> list = sectionalizationService.SectionalizationUser(); |
| | | return ResponseResult.success(list); |
| | | |
| | | } |
| | | } |