浏览代码

공통코드 PK 중복체크 로직 추가

gagamel 4 年之前
父节点
当前提交
600675cdae

+ 9 - 0
src/main/java/com/style24/admin/biz/dao/TsaSystemDao.java

@@ -207,6 +207,15 @@ public interface TsaSystemDao {
 	 */
 	void createMenuAccessHistory(MenuAccessHst menuAccessHst);
 
+	/**
+	 * 공통코드PK 건수
+	 * @param commoncode - 공통코드 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 7. 22
+	 */
+	int getCommonCodePrimaryKeyCount(CommonCode commoncode);
+
 	/**
 	 * 공통코드 등록/수정
 	 * @param commoncode - 공통코드 정보

+ 5 - 1
src/main/java/com/style24/admin/biz/service/TsaSystemService.java

@@ -412,9 +412,13 @@ public class TsaSystemService {
 	 */
 	@Transactional("shopTxnManager")
 	public void saveCommonCode(CommonCode commoncode) {
+		if (systemDao.getCommonCodePrimaryKeyCount(commoncode) > 0) {
+			throw new IllegalStateException("이미 등록된 코드가 있습니다.(코드구분: " + commoncode.getCdGb() + ", 코드: " + commoncode.getCd() + ")");
+		}
+
 		commoncode.setRegNo(TsaSession.getInfo().getUserNo());
 		commoncode.setUpdNo(TsaSession.getInfo().getUserNo());
-		commoncode.setCdNm(commoncode.getCdNm().replace(">", ">"));
+//		commoncode.setCdNm(commoncode.getCdNm().replace(">", ">"));
 		systemDao.saveCommonCode(commoncode);
 	}
 

+ 9 - 0
src/main/java/com/style24/persistence/mybatis/shop/TsaSystem.xml

@@ -565,6 +565,15 @@
 		ORDER  BY DISP_ORD
 	</select>
 
+	<!-- 공통코드PK 건수 -->
+	<select id="getCommonCodePrimaryKeyCount" parameterType="CommonCode" resultType="int">
+		/* TsaSystem.getCommonCodePrimaryKeyCount */
+		SELECT COUNT(*) AS CNT
+		FROM   TB_COMMON_CODE
+		WHERE  CD_GB = #{cdGb}
+		AND    CD = #{cd}
+	</select>
+	
 	<!-- 공통코드 등록/수정 -->
 	<insert id="saveCommonCode" parameterType="CommonCode">
 		/* TsaSystem.saveCommonCode */