package com.glxp.api.controller.anno; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.Log; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; import com.glxp.api.controller.BaseController; import com.glxp.api.dto.DictDto; import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.stat.AnncmntYlqxzcrEntity; import com.glxp.api.req.anno.AnncmntYlqxzcrEntityRequest; import com.glxp.api.req.auth.FilterInvWarehouseRequest; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.service.stat.AnncmntYlqxzcrService; import com.glxp.api.util.BeanCopyUtils; import com.glxp.api.util.StringUtils; import lombok.RequiredArgsConstructor; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 用户信息 * */ @ApiIgnore @Validated @RequiredArgsConstructor @RestController @RequestMapping("/anno/anncmnt/ylqxzcr") public class AnncmntYlqxzcrController extends BaseController { private final AnncmntYlqxzcrService anncmntYlqxzcrService; @GetMapping("/list") public BaseResponse list(AnncmntYlqxzcrEntityRequest request, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } int offset = (request.getPage() - 1) * request.getLimit(); Page pages = PageHelper.offsetPage(offset, request.getLimit()); List list = anncmntYlqxzcrService.list(getQueryWrapper(request)); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pages.getTotal()); pageSimpleResponse.setList(list); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/save") @Log(title = "器械公告管理", businessType = BusinessType.INSERT) public BaseResponse save(@RequestBody AnncmntYlqxzcrEntity entity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } entity.setCreateTime(new Date()); entity.setUdpateTime(new Date()); boolean b = anncmntYlqxzcrService.save(entity); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success("添加成功!"); } @AuthRuleAnnotation("") @PostMapping("/edit") @Log(title = "器械公告管理", businessType = BusinessType.UPDATE) public BaseResponse edit(@RequestBody @Valid AnncmntYlqxzcrEntity entity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } if (entity.getId() == null) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } AnncmntYlqxzcrEntity originEntity = anncmntYlqxzcrService.getById(entity.getId()); if (originEntity == null) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } entity.setUdpateTime(new Date()); boolean b = anncmntYlqxzcrService.updateById(entity); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success("修改成功!"); } @AuthRuleAnnotation("") @PostMapping("/delete") @Log(title = "器械公告管理", businessType = BusinessType.DELETE) public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) { if (StringUtils.isEmpty(deleteRequest.getId())) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); } boolean b = anncmntYlqxzcrService.removeById(deleteRequest.getId()); if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success(); } public static QueryWrapper getQueryWrapper(AnncmntYlqxzcrEntityRequest request) { AnncmntYlqxzcrEntity entity = new AnncmntYlqxzcrEntity(); BeanCopyUtils.copy(request, entity); QueryWrapper queryWrapper = new QueryWrapper(entity); return queryWrapper; } @GetMapping("getList") public BaseResponse getList(AnncmntYlqxzcrEntityRequest request) { List list = anncmntYlqxzcrService.list(); List reList = list.stream().map(s-> { DictDto dictDto = new DictDto(s.getCreditCode(),s.getName()); return dictDto; }).collect(Collectors.toList()); return ResultVOUtils.success(reList); } }