package com.glxp.api.controller.purchase; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; import com.github.pagehelper.PageInfo; 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.entity.purchase.SupCertSetEntity; import com.glxp.api.req.purchase.FilterCertSetsRequest; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.service.purchase.SupCertSetService; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @RestController public class SupCertSetController { @Resource private SupCertSetService supCertSetService; @AuthRuleAnnotation("") @GetMapping("/sup/cert/set/filter") public BaseResponse filterCertSet(FilterCertSetsRequest filterCertSetsRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } List supCertEntityList = supCertSetService.filterCertSets(filterCertSetsRequest); PageInfo pageInfo; pageInfo = new PageInfo<>(supCertEntityList); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(supCertEntityList); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/sup/cert/set/add") @Log(title = "资质证书", businessType = BusinessType.INSERT) public BaseResponse addCertSet(@RequestBody SupCertSetEntity supCertSetEntity) { if (supCertSetEntity == null) { supCertSetEntity = new SupCertSetEntity(); } //判断名字存在就返回 FilterCertSetsRequest filterCertSetsRequest = new FilterCertSetsRequest(); filterCertSetsRequest.setType(supCertSetEntity.getType()); filterCertSetsRequest.setName(supCertSetEntity.getName()); List supCertEntityList = supCertSetService.filterCertSets(filterCertSetsRequest); if (supCertEntityList.size() > 0) { return ResultVOUtils.error(999, "该证书名称已存在!"); } supCertSetEntity.setUpdateTime(new Date()); if (supCertSetEntity.getType() == 3) { if (supCertSetEntity.getFlbmList().size() > 0) { String flbm = String.join(",", supCertSetEntity.getFlbmList()); supCertSetEntity.setFlbm(flbm); } } supCertSetEntity.setId(IdUtil.getSnowflakeNextId()); boolean b = supCertSetService.insertCertSet(supCertSetEntity); return ResultVOUtils.success("添加成功!"); } @AuthRuleAnnotation("") @PostMapping("/sup/cert/set/update") @Log(title = "资质证书", businessType = BusinessType.UPDATE) public BaseResponse updateCertSet(@RequestBody SupCertSetEntity supCertSetEntity) { if (CollUtil.isNotEmpty(supCertSetEntity.getFlbmList())) { String flbm = supCertSetEntity.getFlbmList().stream().collect(Collectors.joining(",")); supCertSetEntity.setFlbm(flbm); } //判断名字存在就返回 FilterCertSetsRequest filterCertSetsRequest = new FilterCertSetsRequest(); filterCertSetsRequest.setType(supCertSetEntity.getType()); filterCertSetsRequest.setName(supCertSetEntity.getName()); filterCertSetsRequest.setId(supCertSetEntity.getId()); filterCertSetsRequest.setUpdateType(1); List supCertEntityList = supCertSetService.filterCertSets(filterCertSetsRequest); if (supCertEntityList.size() != 0) { return ResultVOUtils.error(999, "证书已存在!"); } boolean b = supCertSetService.updateCertSet(supCertSetEntity); return ResultVOUtils.success("修改成功"); } @AuthRuleAnnotation("") @PostMapping("/sup/cert/set/delete") @Log(title = "资质证书", businessType = BusinessType.DELETE) public BaseResponse deleteCertSet(@RequestBody DeleteRequest deleteRequest) { boolean b = supCertSetService.deleteById(deleteRequest.getId()); return ResultVOUtils.success("删除成功!"); } }