|
| 1 | +package m.cmp.wfManager.common.controller; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.regex.Pattern; |
| 5 | + |
| 6 | +import org.apache.commons.lang3.StringUtils; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 9 | +import org.springframework.web.bind.annotation.GetMapping; |
| 10 | +import org.springframework.web.bind.annotation.PathVariable; |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | +import org.springframework.web.bind.annotation.RestController; |
| 15 | + |
| 16 | +import io.swagger.v3.oas.annotations.Operation; |
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 18 | +import m.cmp.wfManager.api.response.ResponseCode; |
| 19 | +import m.cmp.wfManager.api.response.ResponseWrapper; |
| 20 | +import m.cmp.wfManager.common.model.CommonCode; |
| 21 | +import m.cmp.wfManager.common.service.CommonService; |
| 22 | + |
| 23 | + |
| 24 | +@Tag(name = "공통코드", description = "공통코드 조회") |
| 25 | +@RestController |
| 26 | +@RequestMapping("/common") |
| 27 | +public class CommonController { |
| 28 | + |
| 29 | + @Autowired |
| 30 | + private CommonService commonService; |
| 31 | + |
| 32 | + @Operation(summary = "공통코드 목록 조회", description = "") |
| 33 | + @GetMapping("/group/{commonGroupCd}") |
| 34 | + public ResponseWrapper<List<CommonCode>> getCommonCodeList(@PathVariable String commonGroupCd) { |
| 35 | + List<CommonCode> data = commonService.getCommonCodeList(commonGroupCd); |
| 36 | + return new ResponseWrapper<>(data); |
| 37 | + } |
| 38 | + |
| 39 | + @Operation(summary = "공통코드 추가", description = "") |
| 40 | + @PostMapping("/group/{commonGroupCd}/code") |
| 41 | + public ResponseWrapper<String> createCommonCode(@PathVariable String commonGroupCd, @RequestBody CommonCode code) { |
| 42 | + if ( StringUtils.isBlank(commonGroupCd) ) { |
| 43 | + return new ResponseWrapper<>(ResponseCode.BAD_REQUEST, "commonGroupCd"); |
| 44 | + } |
| 45 | + |
| 46 | + if ( StringUtils.isBlank(code.getCodeName()) ) { |
| 47 | + return new ResponseWrapper<>(ResponseCode.BAD_REQUEST, "codeName"); |
| 48 | + } |
| 49 | + else { |
| 50 | + if ( !Pattern.matches("[a-zA-Z0-9\' \']*", code.getCodeName()) ) { |
| 51 | + return new ResponseWrapper<>(ResponseCode.BAD_REQUEST, "codeName은 영문/숫자/공백만 가능합니다."); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + if ( StringUtils.isBlank(code.getCommonGroupCd()) ) { |
| 56 | + code.setCommonGroupCd(commonGroupCd); |
| 57 | + } |
| 58 | + |
| 59 | + code.setRegId("admin"); |
| 60 | + code.setRegName("admin"); |
| 61 | + |
| 62 | + return new ResponseWrapper<>(commonService.createCommonCode(code)); |
| 63 | + } |
| 64 | + |
| 65 | + @Operation(summary = "공통코드 삭제", description = "") |
| 66 | + @DeleteMapping("/group/{commonGroupCd}/code/{commonCd}") |
| 67 | + public ResponseWrapper<Integer> deleteCommonCode(@PathVariable String commonGroupCd, @PathVariable String commonCd) { |
| 68 | + if ( StringUtils.isBlank(commonGroupCd) ) { |
| 69 | + return new ResponseWrapper<>(ResponseCode.BAD_REQUEST, "commonGroupCd"); |
| 70 | + } |
| 71 | + |
| 72 | + if ( StringUtils.isBlank(commonCd) ) { |
| 73 | + return new ResponseWrapper<>(ResponseCode.BAD_REQUEST, "commonCd"); |
| 74 | + } |
| 75 | + |
| 76 | + return new ResponseWrapper<>(commonService.deleteCommonCode(commonGroupCd, commonCd)); |
| 77 | + } |
| 78 | +} |
0 commit comments