| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package com.its.op.service.database;
- import com.its.op.model.dto.database.CmmnCdDto;
- import com.its.op.model.entity.database.CmmnCd;
- import com.its.op.model.entity.database.CmmnCdKey;
- import com.its.op.repository.database.CmmnCdRepository;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- @Slf4j
- @RequiredArgsConstructor
- @Service
- public class CmmnCdService {
- private final CmmnCdRepository repo;
- public List<CmmnCd> findAll() {
- try {
- return this.repo.findAll();
- }
- catch (Exception e) {
- log.error("{}.findAll: Exception: {}", getClass().getSimpleName(), e.getMessage());
- }
- return new ArrayList<>();
- }
- public List<CmmnCd> findAllByCmmnClsfCd(String CMMN_CLSF_CD) {
- try {
- return this.repo.findAllByCmmnClsfCd(CMMN_CLSF_CD);
- }
- catch (Exception e) {
- log.error("{}.findAllByCmmnClsfCd: Exception: {}", getClass().getSimpleName(), e.getMessage());
- }
- return new ArrayList<>();
- }
- public CmmnCd findAllByCmmnClsfCdCmmnCd(String CMMN_CLSF_CD, String CMMN_CD) {
- try {
- CmmnCd data = this.repo.findAllByCmmnClsfCdCmmnCd(CMMN_CLSF_CD, CMMN_CD);
- return data;
- }
- catch (Exception e) {
- log.error("{}.findById: Exception: {}", getClass().getSimpleName(), e.getMessage());
- }
- return null;
- }
- public CmmnCd mergeInfo(CmmnCdDto.CmmnCdUpdateReq req) {
- try {
- CmmnCdKey key = new CmmnCdKey(req.getCMMN_CLSF_CD(), req.getCMMN_CD());
- Optional<CmmnCd> data = this.repo.findById(key);
- CmmnCd newObj = data.orElseGet(() -> new CmmnCd(req.getCMMN_CLSF_CD(), req.getCMMN_CD()));
- newObj.updateInfo(req);
- this.repo.save(newObj);
- return newObj;
- }
- catch (Exception e) {
- log.error("{}.mergeInfo: Object: {}, Exception: {}", getClass().getSimpleName(), req, e.getMessage());
- }
- return null;
- }
- public CmmnCd deleteById(String id, String sub) {
- try {
- CmmnCdKey key = new CmmnCdKey(id, sub);
- Optional<CmmnCd> data = this.repo.findById(key);
- if (data.isPresent()) {
- CmmnCd obj = data.get();
- this.repo.deleteById(key);
- return obj;
- }
- }
- catch (Exception e) {
- log.error("{}.deleteById: Object: {}, Exception: {}", getClass().getSimpleName(), id, e.getMessage());
- }
- return null;
- }
- }
|