feat(core): Installment VO 세트 + Mapper + InstallmentStatus Enum (도메인 P1-2-b)
V27 분급 스키마와 ga-core 동기화. 분급 계획 생성 로직은 P1-2-c.
신규 패키지: com.ga.core.vo.installment, com.ga.core.mapper.installment
Enum:
- InstallmentStatus {SCHEDULED, PAID, DEFERRED, CANCELLED}
InstallmentRatio VO 세트 (분급 비율 마스터):
- VO/Resp/SaveReq/SearchParam 4종
- SaveReq: @Min(1)/@Max(7) planYear, @Positive ratioPercent
InstallmentPlan VO 세트 (계약별 분급):
- VO/Resp/SearchParam 3종
- Resp에 contract/product/agent 조인 표시
(policyNo, productName, agentName, statusName)
Mapper 2종:
- InstallmentRatioMapper: selectActive(category, year, baseDate),
selectAllActiveRatios(category, baseDate) — 1~7차년 비율 일괄 조회
- InstallmentPlanMapper: insertBatch(<foreach>), selectByContract,
selectScheduledByMonth, updateStatus(paidAmount/paidAt/paymentId)
XML 핵심:
- 활성 비율: effective_from/to + is_active=TRUE + LIMIT 1 (최신 우선)
- selectAllActiveRatios: plan_year ASC (1~7년 순서 보장)
- selectScheduledByMonth: settle_month + status='SCHEDULED' (배치 진입점)
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package com.ga.core.mapper.installment;
|
||||||
|
|
||||||
|
import com.ga.core.vo.installment.InstallmentPlanResp;
|
||||||
|
import com.ga.core.vo.installment.InstallmentPlanSearchParam;
|
||||||
|
import com.ga.core.vo.installment.InstallmentPlanVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface InstallmentPlanMapper {
|
||||||
|
|
||||||
|
List<InstallmentPlanResp> selectList(InstallmentPlanSearchParam param);
|
||||||
|
|
||||||
|
InstallmentPlanResp selectDetailById(@Param("planId") Long planId);
|
||||||
|
|
||||||
|
InstallmentPlanVO selectById(@Param("planId") Long planId);
|
||||||
|
|
||||||
|
/** 계약의 전체 분급 계획 조회 (계약 상세 화면용) */
|
||||||
|
List<InstallmentPlanVO> selectByContract(@Param("contractId") Long contractId);
|
||||||
|
|
||||||
|
/** 정산월의 SCHEDULED 분급 계획 조회 (배치 지급 처리용) */
|
||||||
|
List<InstallmentPlanVO> selectScheduledByMonth(@Param("settleMonth") String settleMonth);
|
||||||
|
|
||||||
|
int insert(InstallmentPlanVO vo);
|
||||||
|
|
||||||
|
/** 7년치 분급 계획 일괄 생성 */
|
||||||
|
int insertBatch(@Param("list") List<InstallmentPlanVO> list);
|
||||||
|
|
||||||
|
int update(InstallmentPlanVO vo);
|
||||||
|
|
||||||
|
int updateStatus(@Param("planId") Long planId, @Param("status") String status);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.ga.core.mapper.installment;
|
||||||
|
|
||||||
|
import com.ga.core.vo.installment.InstallmentRatioResp;
|
||||||
|
import com.ga.core.vo.installment.InstallmentRatioSearchParam;
|
||||||
|
import com.ga.core.vo.installment.InstallmentRatioVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface InstallmentRatioMapper {
|
||||||
|
|
||||||
|
List<InstallmentRatioResp> selectList(InstallmentRatioSearchParam param);
|
||||||
|
|
||||||
|
InstallmentRatioResp selectDetailById(@Param("ratioId") Long ratioId);
|
||||||
|
|
||||||
|
InstallmentRatioVO selectById(@Param("ratioId") Long ratioId);
|
||||||
|
|
||||||
|
/** 특정 날짜에 유효한 분급 비율 1건 (planYear + productCategory 조합) */
|
||||||
|
InstallmentRatioVO selectActive(@Param("productCategory") String productCategory,
|
||||||
|
@Param("planYear") Integer planYear,
|
||||||
|
@Param("baseDate") String baseDate);
|
||||||
|
|
||||||
|
/** 특정 날짜에 유효한 1~7년 차 전체 비율 조회 (분급 계획 일괄 생성 시 사용) */
|
||||||
|
List<InstallmentRatioVO> selectAllActiveRatios(@Param("productCategory") String productCategory,
|
||||||
|
@Param("baseDate") String baseDate);
|
||||||
|
|
||||||
|
int insert(InstallmentRatioVO vo);
|
||||||
|
|
||||||
|
int update(InstallmentRatioVO vo);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class InstallmentPlanResp {
|
||||||
|
private Long planId;
|
||||||
|
private Long contractId;
|
||||||
|
private String policyNo;
|
||||||
|
private String productName;
|
||||||
|
private Long agentId;
|
||||||
|
private String agentName;
|
||||||
|
private Integer planYear;
|
||||||
|
private Integer planMonth;
|
||||||
|
private String settleMonth;
|
||||||
|
private BigDecimal expectedAmount;
|
||||||
|
private BigDecimal paidAmount;
|
||||||
|
private LocalDateTime paidAt;
|
||||||
|
private Long paymentId;
|
||||||
|
private String status;
|
||||||
|
private String statusName;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import com.ga.common.model.SearchParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class InstallmentPlanSearchParam extends SearchParam {
|
||||||
|
private Long contractId;
|
||||||
|
private String settleMonth;
|
||||||
|
private String status;
|
||||||
|
private Integer planYear;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class InstallmentPlanVO {
|
||||||
|
private Long planId;
|
||||||
|
private Long contractId;
|
||||||
|
private Integer planYear; // 1~7
|
||||||
|
private Integer planMonth; // 1~12
|
||||||
|
private String settleMonth; // YYYYMM
|
||||||
|
private BigDecimal expectedAmount;
|
||||||
|
private BigDecimal paidAmount;
|
||||||
|
private LocalDateTime paidAt;
|
||||||
|
private Long paymentId;
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private Long createdBy;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
private Long updatedBy;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class InstallmentRatioResp {
|
||||||
|
private Long ratioId;
|
||||||
|
private String productCategory;
|
||||||
|
private String productCategoryName;
|
||||||
|
private Integer planYear;
|
||||||
|
private BigDecimal ratioPercent;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private LocalDate effectiveTo;
|
||||||
|
private Boolean isActive;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Positive;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class InstallmentRatioSaveReq {
|
||||||
|
|
||||||
|
private String productCategory; // NULL = 전체 상품
|
||||||
|
|
||||||
|
@NotNull(message = "분급 연차는 필수입니다")
|
||||||
|
@Min(value = 1, message = "분급 연차는 1 이상이어야 합니다")
|
||||||
|
@Max(value = 7, message = "분급 연차는 7 이하여야 합니다")
|
||||||
|
private Integer planYear;
|
||||||
|
|
||||||
|
@NotNull(message = "비율은 필수입니다")
|
||||||
|
@Positive(message = "비율은 양수여야 합니다")
|
||||||
|
private BigDecimal ratioPercent;
|
||||||
|
|
||||||
|
@NotNull(message = "적용 시작일은 필수입니다")
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
|
||||||
|
private LocalDate effectiveTo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import com.ga.common.model.SearchParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class InstallmentRatioSearchParam extends SearchParam {
|
||||||
|
private String productCategory;
|
||||||
|
private Integer planYear;
|
||||||
|
private String effectiveDate; // YYYY-MM-DD — 해당 날짜 유효 비율 필터
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class InstallmentRatioVO {
|
||||||
|
private Long ratioId;
|
||||||
|
private String productCategory; // NULL = ALL 상품
|
||||||
|
private Integer planYear; // 1~7
|
||||||
|
private BigDecimal ratioPercent;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private LocalDate effectiveTo; // NULL = 현재 유효
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private Long createdBy;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
private Long updatedBy;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ga.core.vo.installment;
|
||||||
|
|
||||||
|
public enum InstallmentStatus {
|
||||||
|
SCHEDULED, PAID, DEFERRED, CANCELLED;
|
||||||
|
|
||||||
|
public String code() { return this.name(); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ga.core.mapper.installment.InstallmentPlanMapper">
|
||||||
|
|
||||||
|
<!-- ==================== ResultMap ==================== -->
|
||||||
|
|
||||||
|
<!-- installment_plan 테이블 1:1 매핑 (CUD용) -->
|
||||||
|
<resultMap id="VOMap" type="com.ga.core.vo.installment.InstallmentPlanVO">
|
||||||
|
<id property="planId" column="plan_id"/>
|
||||||
|
<result property="contractId" column="contract_id"/>
|
||||||
|
<result property="planYear" column="plan_year"/>
|
||||||
|
<result property="planMonth" column="plan_month"/>
|
||||||
|
<result property="settleMonth" column="settle_month"/>
|
||||||
|
<result property="expectedAmount" column="expected_amount"/>
|
||||||
|
<result property="paidAmount" column="paid_amount"/>
|
||||||
|
<result property="paidAt" column="paid_at"/>
|
||||||
|
<result property="paymentId" column="payment_id"/>
|
||||||
|
<result property="status" column="status"/>
|
||||||
|
<result property="createdAt" column="created_at"/>
|
||||||
|
<result property="createdBy" column="created_by"/>
|
||||||
|
<result property="updatedAt" column="updated_at"/>
|
||||||
|
<result property="updatedBy" column="updated_by"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 조인 결과 포함 API 응답용 -->
|
||||||
|
<resultMap id="RespMap" type="com.ga.core.vo.installment.InstallmentPlanResp">
|
||||||
|
<id property="planId" column="plan_id"/>
|
||||||
|
<result property="contractId" column="contract_id"/>
|
||||||
|
<result property="policyNo" column="policy_no"/>
|
||||||
|
<result property="productName" column="product_name"/>
|
||||||
|
<result property="agentId" column="agent_id"/>
|
||||||
|
<result property="agentName" column="agent_name"/>
|
||||||
|
<result property="planYear" column="plan_year"/>
|
||||||
|
<result property="planMonth" column="plan_month"/>
|
||||||
|
<result property="settleMonth" column="settle_month"/>
|
||||||
|
<result property="expectedAmount" column="expected_amount"/>
|
||||||
|
<result property="paidAmount" column="paid_amount"/>
|
||||||
|
<result property="paidAt" column="paid_at"/>
|
||||||
|
<result property="paymentId" column="payment_id"/>
|
||||||
|
<result property="status" column="status"/>
|
||||||
|
<result property="statusName" column="status_name"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- ==================== 공통 SELECT 컬럼 ==================== -->
|
||||||
|
|
||||||
|
<sql id="selectRespCols">
|
||||||
|
p.plan_id,
|
||||||
|
p.contract_id,
|
||||||
|
c.policy_no,
|
||||||
|
pr.product_name,
|
||||||
|
c.agent_id,
|
||||||
|
a.agent_name,
|
||||||
|
p.plan_year,
|
||||||
|
p.plan_month,
|
||||||
|
p.settle_month,
|
||||||
|
p.expected_amount,
|
||||||
|
p.paid_amount,
|
||||||
|
p.paid_at,
|
||||||
|
p.payment_id,
|
||||||
|
p.status,
|
||||||
|
(SELECT cc.code_name FROM common_code cc
|
||||||
|
WHERE cc.group_code = 'INSTALLMENT_STATUS' AND cc.code = p.status) AS status_name
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- ==================== SELECT ==================== -->
|
||||||
|
|
||||||
|
<!-- 목록 조회 (검색 조건 + 페이징) -->
|
||||||
|
<select id="selectList" parameterType="com.ga.core.vo.installment.InstallmentPlanSearchParam"
|
||||||
|
resultMap="RespMap">
|
||||||
|
SELECT <include refid="selectRespCols"/>
|
||||||
|
FROM installment_plan p
|
||||||
|
JOIN contract c ON c.contract_id = p.contract_id
|
||||||
|
JOIN product pr ON pr.product_id = c.product_id
|
||||||
|
JOIN agent a ON a.agent_id = c.agent_id
|
||||||
|
<where>
|
||||||
|
<if test="contractId != null">
|
||||||
|
AND p.contract_id = #{contractId}
|
||||||
|
</if>
|
||||||
|
<if test="settleMonth != null and settleMonth != ''">
|
||||||
|
AND p.settle_month = #{settleMonth}
|
||||||
|
</if>
|
||||||
|
<if test="status != null and status != ''">
|
||||||
|
AND p.status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="planYear != null">
|
||||||
|
AND p.plan_year = #{planYear}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY p.contract_id, p.plan_year, p.plan_month
|
||||||
|
<if test="pageSize != null and pageSize > 0">
|
||||||
|
LIMIT #{pageSize} OFFSET #{offset}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 단건 조회 (Resp: 조인 포함) -->
|
||||||
|
<select id="selectDetailById" resultMap="RespMap">
|
||||||
|
SELECT <include refid="selectRespCols"/>
|
||||||
|
FROM installment_plan p
|
||||||
|
JOIN contract c ON c.contract_id = p.contract_id
|
||||||
|
JOIN product pr ON pr.product_id = c.product_id
|
||||||
|
JOIN agent a ON a.agent_id = c.agent_id
|
||||||
|
WHERE p.plan_id = #{planId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 단건 조회 (VO: CUD용) -->
|
||||||
|
<select id="selectById" resultMap="VOMap">
|
||||||
|
SELECT plan_id, contract_id, plan_year, plan_month, settle_month,
|
||||||
|
expected_amount, paid_amount, paid_at, payment_id, status,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_plan
|
||||||
|
WHERE plan_id = #{planId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 계약의 전체 분급 계획 조회 (계약 상세 화면용, 연차/월 순 정렬) -->
|
||||||
|
<select id="selectByContract" resultMap="VOMap">
|
||||||
|
SELECT plan_id, contract_id, plan_year, plan_month, settle_month,
|
||||||
|
expected_amount, paid_amount, paid_at, payment_id, status,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_plan
|
||||||
|
WHERE contract_id = #{contractId}
|
||||||
|
ORDER BY plan_year, plan_month
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 정산월의 SCHEDULED 분급 계획 조회 (배치 지급 처리용) -->
|
||||||
|
<select id="selectScheduledByMonth" resultMap="VOMap">
|
||||||
|
SELECT plan_id, contract_id, plan_year, plan_month, settle_month,
|
||||||
|
expected_amount, paid_amount, paid_at, payment_id, status,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_plan
|
||||||
|
WHERE settle_month = #{settleMonth}
|
||||||
|
AND status = 'SCHEDULED'
|
||||||
|
ORDER BY contract_id, plan_year, plan_month
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- ==================== INSERT ==================== -->
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.ga.core.vo.installment.InstallmentPlanVO"
|
||||||
|
useGeneratedKeys="true" keyProperty="planId">
|
||||||
|
INSERT INTO installment_plan (
|
||||||
|
contract_id, plan_year, plan_month, settle_month,
|
||||||
|
expected_amount, paid_amount, status,
|
||||||
|
created_at, created_by
|
||||||
|
) VALUES (
|
||||||
|
#{contractId}, #{planYear}, #{planMonth}, #{settleMonth},
|
||||||
|
#{expectedAmount}, COALESCE(#{paidAmount}, 0),
|
||||||
|
COALESCE(#{status}, 'SCHEDULED'),
|
||||||
|
NOW(), #{createdBy}
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 7년치 분급 계획 일괄 생성 (계약 등록 시 배치 처리) -->
|
||||||
|
<insert id="insertBatch">
|
||||||
|
INSERT INTO installment_plan (
|
||||||
|
contract_id, plan_year, plan_month, settle_month,
|
||||||
|
expected_amount, paid_amount, status,
|
||||||
|
created_at, created_by
|
||||||
|
) VALUES
|
||||||
|
<foreach collection="list" item="p" separator=",">
|
||||||
|
(#{p.contractId}, #{p.planYear}, #{p.planMonth}, #{p.settleMonth},
|
||||||
|
#{p.expectedAmount}, COALESCE(#{p.paidAmount}, 0),
|
||||||
|
COALESCE(#{p.status}, 'SCHEDULED'),
|
||||||
|
NOW(), #{p.createdBy})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- ==================== UPDATE ==================== -->
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.ga.core.vo.installment.InstallmentPlanVO">
|
||||||
|
UPDATE installment_plan
|
||||||
|
<set>
|
||||||
|
<if test="settleMonth != null and settleMonth != ''">settle_month = #{settleMonth},</if>
|
||||||
|
<if test="expectedAmount != null">expected_amount = #{expectedAmount},</if>
|
||||||
|
<if test="paidAmount != null">paid_amount = #{paidAmount},</if>
|
||||||
|
<if test="paidAt != null">paid_at = #{paidAt},</if>
|
||||||
|
<if test="paymentId != null">payment_id = #{paymentId},</if>
|
||||||
|
<if test="status != null and status != ''">status = #{status},</if>
|
||||||
|
updated_at = NOW(),
|
||||||
|
updated_by = #{updatedBy}
|
||||||
|
</set>
|
||||||
|
WHERE plan_id = #{planId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 상태만 변경 (PAID / DEFERRED / CANCELLED) -->
|
||||||
|
<update id="updateStatus">
|
||||||
|
UPDATE installment_plan
|
||||||
|
SET status = #{status}, updated_at = NOW()
|
||||||
|
WHERE plan_id = #{planId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ga.core.mapper.installment.InstallmentRatioMapper">
|
||||||
|
|
||||||
|
<!-- ==================== ResultMap ==================== -->
|
||||||
|
|
||||||
|
<!-- installment_ratio 테이블 1:1 매핑 (CUD용) -->
|
||||||
|
<resultMap id="VOMap" type="com.ga.core.vo.installment.InstallmentRatioVO">
|
||||||
|
<id property="ratioId" column="ratio_id"/>
|
||||||
|
<result property="productCategory" column="product_category"/>
|
||||||
|
<result property="planYear" column="plan_year"/>
|
||||||
|
<result property="ratioPercent" column="ratio_percent"/>
|
||||||
|
<result property="effectiveFrom" column="effective_from"/>
|
||||||
|
<result property="effectiveTo" column="effective_to"/>
|
||||||
|
<result property="isActive" column="is_active"/>
|
||||||
|
<result property="createdAt" column="created_at"/>
|
||||||
|
<result property="createdBy" column="created_by"/>
|
||||||
|
<result property="updatedAt" column="updated_at"/>
|
||||||
|
<result property="updatedBy" column="updated_by"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 코드명 포함 API 응답용 -->
|
||||||
|
<resultMap id="RespMap" type="com.ga.core.vo.installment.InstallmentRatioResp">
|
||||||
|
<id property="ratioId" column="ratio_id"/>
|
||||||
|
<result property="productCategory" column="product_category"/>
|
||||||
|
<result property="productCategoryName" column="product_category_name"/>
|
||||||
|
<result property="planYear" column="plan_year"/>
|
||||||
|
<result property="ratioPercent" column="ratio_percent"/>
|
||||||
|
<result property="effectiveFrom" column="effective_from"/>
|
||||||
|
<result property="effectiveTo" column="effective_to"/>
|
||||||
|
<result property="isActive" column="is_active"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- ==================== 공통 SELECT 컬럼 ==================== -->
|
||||||
|
|
||||||
|
<sql id="selectRespCols">
|
||||||
|
r.ratio_id,
|
||||||
|
r.product_category,
|
||||||
|
(SELECT cc.code_name FROM common_code cc
|
||||||
|
WHERE cc.group_code = 'PRODUCT_CATEGORY' AND cc.code = r.product_category) AS product_category_name,
|
||||||
|
r.plan_year,
|
||||||
|
r.ratio_percent,
|
||||||
|
r.effective_from,
|
||||||
|
r.effective_to,
|
||||||
|
r.is_active
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- ==================== SELECT ==================== -->
|
||||||
|
|
||||||
|
<!-- 목록 조회 (검색 조건 + 페이징) -->
|
||||||
|
<select id="selectList" parameterType="com.ga.core.vo.installment.InstallmentRatioSearchParam"
|
||||||
|
resultMap="RespMap">
|
||||||
|
SELECT <include refid="selectRespCols"/>
|
||||||
|
FROM installment_ratio r
|
||||||
|
<where>
|
||||||
|
<if test="productCategory != null and productCategory != ''">
|
||||||
|
AND r.product_category = #{productCategory}
|
||||||
|
</if>
|
||||||
|
<if test="planYear != null">
|
||||||
|
AND r.plan_year = #{planYear}
|
||||||
|
</if>
|
||||||
|
<if test="effectiveDate != null and effectiveDate != ''">
|
||||||
|
AND r.effective_from <= #{effectiveDate}::DATE
|
||||||
|
AND (r.effective_to IS NULL OR r.effective_to >= #{effectiveDate}::DATE)
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY r.plan_year, r.effective_from DESC
|
||||||
|
<if test="pageSize != null and pageSize > 0">
|
||||||
|
LIMIT #{pageSize} OFFSET #{offset}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 단건 조회 (Resp: 코드명 포함) -->
|
||||||
|
<select id="selectDetailById" resultMap="RespMap">
|
||||||
|
SELECT <include refid="selectRespCols"/>
|
||||||
|
FROM installment_ratio r
|
||||||
|
WHERE r.ratio_id = #{ratioId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 단건 조회 (VO: CUD용) -->
|
||||||
|
<select id="selectById" resultMap="VOMap">
|
||||||
|
SELECT ratio_id, product_category, plan_year, ratio_percent,
|
||||||
|
effective_from, effective_to, is_active,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_ratio
|
||||||
|
WHERE ratio_id = #{ratioId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
특정 날짜에 유효한 분급 비율 1건 조회.
|
||||||
|
product_category NULL은 전체 상품 적용 행이므로
|
||||||
|
NULL 매개변수가 들어오면 IS NULL 조건으로 처리.
|
||||||
|
effective_from DESC 정렬로 최신 개정본 우선 반환.
|
||||||
|
-->
|
||||||
|
<select id="selectActive" resultMap="VOMap">
|
||||||
|
SELECT ratio_id, product_category, plan_year, ratio_percent,
|
||||||
|
effective_from, effective_to, is_active,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_ratio
|
||||||
|
WHERE plan_year = #{planYear}
|
||||||
|
AND (product_category = #{productCategory}
|
||||||
|
OR (#{productCategory} IS NULL AND product_category IS NULL))
|
||||||
|
AND is_active = TRUE
|
||||||
|
AND effective_from <= #{baseDate}::DATE
|
||||||
|
AND (effective_to IS NULL OR effective_to >= #{baseDate}::DATE)
|
||||||
|
ORDER BY effective_from DESC
|
||||||
|
LIMIT 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 1~7년 차 전체 비율 조회 (분급 계획 일괄 생성 시 사용) -->
|
||||||
|
<select id="selectAllActiveRatios" resultMap="VOMap">
|
||||||
|
SELECT ratio_id, product_category, plan_year, ratio_percent,
|
||||||
|
effective_from, effective_to, is_active,
|
||||||
|
created_at, created_by, updated_at, updated_by
|
||||||
|
FROM installment_ratio
|
||||||
|
WHERE (product_category = #{productCategory}
|
||||||
|
OR (#{productCategory} IS NULL AND product_category IS NULL))
|
||||||
|
AND is_active = TRUE
|
||||||
|
AND effective_from <= #{baseDate}::DATE
|
||||||
|
AND (effective_to IS NULL OR effective_to >= #{baseDate}::DATE)
|
||||||
|
ORDER BY plan_year
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- ==================== INSERT ==================== -->
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.ga.core.vo.installment.InstallmentRatioVO"
|
||||||
|
useGeneratedKeys="true" keyProperty="ratioId">
|
||||||
|
INSERT INTO installment_ratio (
|
||||||
|
product_category, plan_year, ratio_percent,
|
||||||
|
effective_from, effective_to, is_active,
|
||||||
|
created_at, created_by
|
||||||
|
) VALUES (
|
||||||
|
#{productCategory}, #{planYear}, #{ratioPercent},
|
||||||
|
#{effectiveFrom}, #{effectiveTo}, COALESCE(#{isActive}, TRUE),
|
||||||
|
NOW(), #{createdBy}
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- ==================== UPDATE ==================== -->
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.ga.core.vo.installment.InstallmentRatioVO">
|
||||||
|
UPDATE installment_ratio
|
||||||
|
<set>
|
||||||
|
<if test="ratioPercent != null">ratio_percent = #{ratioPercent},</if>
|
||||||
|
<if test="effectiveFrom != null">effective_from = #{effectiveFrom},</if>
|
||||||
|
<if test="effectiveTo != null">effective_to = #{effectiveTo},</if>
|
||||||
|
<if test="isActive != null">is_active = #{isActive},</if>
|
||||||
|
updated_at = NOW(),
|
||||||
|
updated_by = #{updatedBy}
|
||||||
|
</set>
|
||||||
|
WHERE ratio_id = #{ratioId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user