Procházet zdrojové kódy

任务调度添加是否添加第三者,投被是否一致,新车购置价的规则調度

hxl13994548489 před 1 rokem
rodič
revize
c7576f35dc

+ 4 - 0
src/main/java/com/ydtech/modules/order/entity/vo/BaseQuoteInfoVo.java

@@ -33,6 +33,10 @@ public class BaseQuoteInfoVo extends YaQuoteInfoVo {
     @ApiModelProperty("订单来源")
     private String orderSource;
 
+
+    @ApiModelProperty("保险公司id")
+    private String orderCompanyId;
+
     public BaseQuoteInfoVo() {
     }
 

+ 6 - 2
src/main/java/com/ydtech/modules/protocol/constants/DispatchTypeConstants.java

@@ -26,7 +26,11 @@ public enum DispatchTypeConstants {
     DISPATCH_TYPE_CONSTANTS_6(6, "yqInsureFlag","交强投保"),
     DISPATCH_TYPE_CONSTANTS_7(7, "cxInsureFlag","车损投保"),
     DISPATCH_TYPE_CONSTANTS_8(8, "ThirdPartyLiabilityInsurance","第三者责任险"),
-    DISPATCH_TYPE_CONSTANTS_9(9,"NewEnergy","新能源");
+    DISPATCH_TYPE_CONSTANTS_12(12, "ThirdPartyLiabilityInsuranceFlag","三者投保"),
+    DISPATCH_TYPE_CONSTANTS_9(9,"NewEnergy","新能源"),
+    DISPATCH_TYPE_CONSTANTS_10(10,"Price","新车购置价"),
+    DISPATCH_TYPE_CONSTANTS_11(11,"Customers","投被信息");
+
 
     private final Integer num;
 
@@ -58,6 +62,6 @@ public enum DispatchTypeConstants {
      *  @Description:  排除的非空判断
      */
     public static List<String> removalOfCode() {
-        return Arrays.asList(DISPATCH_TYPE_CONSTANTS_6.getCode(), DISPATCH_TYPE_CONSTANTS_7.getCode(), DISPATCH_TYPE_CONSTANTS_8.getCode());
+        return Arrays.asList(DISPATCH_TYPE_CONSTANTS_6.getCode(), DISPATCH_TYPE_CONSTANTS_7.getCode());
     }
 }

+ 16 - 0
src/main/java/com/ydtech/modules/protocol/controller/PtlTaxSourceNewController.java

@@ -3,6 +3,7 @@ package com.ydtech.modules.protocol.controller;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.order.entity.BasePageResult;
+import com.ydtech.modules.order.entity.vo.BaseQuoteInfoVo;
 import com.ydtech.modules.protocol.entity.dto.PtlTaxSourceNewDto;
 import com.ydtech.modules.protocol.entity.vo.*;
 import com.ydtech.modules.protocol.service.PtlTaxSourceNewService;
@@ -132,4 +133,19 @@ public class PtlTaxSourceNewController extends BaseController {
         PtlTaxSourceNewSaveVo ptlTaxSourceNewSaveVo = ptlTaxSourceNewService.rulesGet(id, dispatchRulesAttrList);
         return HttpResult.ok(ptlTaxSourceNewSaveVo);
     }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/30 18:15
+     *  @Description: 验证保险公司规则是否匹配
+     */
+    @ApiOperation(value = "验证调度规则匹配")
+    @PostMapping("/checkData")
+    public HttpResult checkData(@RequestBody BaseQuoteInfoVo quoteVo){
+        if(quoteVo.getOrderCompanyId()==null || "".equals(quoteVo.getOrderCompanyId())){
+            return HttpResult.error("保险公司id不能为空orderCompanyId");
+        }
+        String taxAgreementId = ptlTaxSourceNewService.getAgreementId(null, null, quoteVo.getOrderCompanyId(), quoteVo, null,"test");
+        return HttpResult.ok(taxAgreementId);
+    }
 }

+ 1 - 2
src/main/java/com/ydtech/modules/protocol/dao/PtlAgreementGroupLinkDeptMapper.java

@@ -5,7 +5,6 @@ import com.ydtech.modules.protocol.entity.dto.PtlAgreementInsCompanyDto;
 import com.ydtech.modules.protocol.entity.po.PtlAgreementGroupLinkDept;
 import org.apache.ibatis.annotations.Param;
 
-import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -22,7 +21,7 @@ public interface PtlAgreementGroupLinkDeptMapper extends BaseMapper<PtlAgreement
      *  @Date: 2024/10/25 11:35
      *  @Description:  查询授权的协议
      */
-    List<PtlAgreementInsCompanyDto> getAgreementCompany(@Param("localDate") LocalDate localDate, @Param("deptId") String deptId);
+    List<PtlAgreementInsCompanyDto> getAgreementCompany(@Param("localDate") String localDate, @Param("deptId") String deptId);
     /**
      *  @version
      *  @author: hxl

+ 3 - 1
src/main/java/com/ydtech/modules/protocol/service/impl/PtlAgreementServiceImpl.java

@@ -144,7 +144,9 @@ public class PtlAgreementServiceImpl extends ServiceImpl<PtlAgreementMapper, Ptl
         if(flag){
             //新逻辑从协议组授权获取
             if(StringUtils.isNotBlank(deptId)){
-                agreementCompany =ptlAgreementGroupLinkDeptMapper.getAgreementCompany(localDate, deptId);
+                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                String dateNow = localDate.format(df);
+                agreementCompany =ptlAgreementGroupLinkDeptMapper.getAgreementCompany(dateNow, deptId);
             }
         }else{
             //原先逻辑

+ 118 - 12
src/main/java/com/ydtech/modules/protocol/service/impl/PtlTaxSourceServiceImpl.java

@@ -8,10 +8,10 @@ import com.ydtech.constants.enums.dict.insurance.EnergyType;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.model.dto.SysUserLinkPtlAgreementDto;
 import com.ydtech.modules.base.controller.BaseController;
+import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
 import com.ydtech.modules.ins.model.vo.KindInfoVo;
 import com.ydtech.modules.ins.model.vo.RiskInfoVo;
 import com.ydtech.modules.order.entity.BasePageResult;
-import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.entity.vo.BaseQuoteInfoVo;
 import com.ydtech.modules.order.service.InsOrdersService;
 import com.ydtech.modules.protocol.constants.DispatchTypeConstants;
@@ -294,11 +294,18 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
         PtlTaxSourceNew ptlTaxSourceNew = ptlTaxSourceNewMapper.selectById(ptlTaxSourceNewAddVo.getId());
         ptlTaxSourceNew =ptlTaxSourceNew.getNewEntity(ptlTaxSourceNewAddVo,ptlTaxSourceNew);
         if(ptlTaxSourceNewDefault!=null){
-            //当前数据为默认的话,将之前的数据设置为非默认
-            if("1".equals(ptlTaxSourceNew.getDefaultFlag()) ){
-                //将旧数据设置数据为非默认
-                ptlTaxSourceNewDefault.setDefaultFlag("0");
-                ptlTaxSourceNewMapper.updateById(ptlTaxSourceNewDefault);
+            List<PtlTaxSourceNew> list = this.list(new LambdaQueryWrapper<PtlTaxSourceNew>().eq(PtlTaxSourceNew::getInsCompanyId,ptlTaxSourceNewAddVo.getInsCompanyId()));
+            if("0".equals(ptlTaxSourceNewAddVo.getDefaultFlag())  && ptlTaxSourceNewDefault.getId().compareTo(Long.valueOf(ptlTaxSourceNewAddVo.getId())) ==0 ){
+                if(list ==null || list.size()==0 || list.size()==1){
+                    throw new SystemException("只存在一条数据,不允许修改为非默认");
+                }
+            }else{
+                //当前数据为默认的话,将之前的数据设置为非默认
+                if("1".equals(ptlTaxSourceNew.getDefaultFlag()) ){
+                    //将旧数据设置数据为非默认
+                    ptlTaxSourceNewDefault.setDefaultFlag("0");
+                    ptlTaxSourceNewMapper.updateById(ptlTaxSourceNewDefault);
+                }
             }
         }
         ptlTaxSourceNew.setDispatchContent(content);
@@ -591,8 +598,16 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
         String thirdPartyLiabilityInsurance =InsuranceRisk.getStringByB(kinds);
         //9.能源类型
         String energyType = EnergyType.isNewEnergy(quoteInfo.getCarInfo().getEnergyType()) ? "1" : "0";
+        //10.新车购置价
+        String price = quoteInfo.getCarInfo().getPurchasePrice();
+        //11. 投被信息
+        // 投保人信息
+        CustomerInfoVo policyHolderInfo = quoteInfo.getPolicyHolderInfo();
+        // 被保人信息
+        CustomerInfoVo insuredPersonInfo = quoteInfo.getInsuredPersonInfo();
         //报价信息
-        msg = getString(msg, licenseNo,seats,exhaustScale,cimodelclassVal,vehicleUseVal,yqInsureFlag,cxInsureFlag,thirdPartyLiabilityInsurance);
+        msg = getString(msg, licenseNo,seats,exhaustScale,cimodelclassVal,vehicleUseVal,yqInsureFlag,cxInsureFlag,thirdPartyLiabilityInsurance,energyType,price,policyHolderInfo,insuredPersonInfo);
+
         //通过调度id查询调度规则是否包含车牌、排量
         boolean isExcludeLicense = false;
         boolean isExcludeSeats = false;
@@ -603,6 +618,13 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
         boolean isExcludeCxInsureFlag= false;
         boolean isExcludeThirdPartyLiabilityInsurance= false;
         boolean isEnergyType = false;
+        //三者险是否投保
+        boolean isExcludeThirdPartyLiabilityInsuranceFlag= false;
+        //行车购置价
+        boolean priceFlag= false;
+        //投被是否一致
+        boolean custemerFlag= false;
+
         //通过默认公司id查询所有的协议按优先级排序
         Long ptlTaxSourceNewId = ptlTaxSourceNew.getId();
         List<PtlAgreementDispatchRulesAttrLink> list = ptlAgreementDispatchRulesAttrLinkService.list(new LambdaQueryWrapper<PtlAgreementDispatchRulesAttrLink>()
@@ -645,13 +667,30 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
             if(!isExcludeThirdPartyLiabilityInsurance){
                 quoteInfoErorMsg+= DispatchTypeConstants.matchKey(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode())+"的值为"+(thirdPartyLiabilityInsurance==null?"不投保":thirdPartyLiabilityInsurance)+"未匹配"+"\n";
             }
+            isExcludeThirdPartyLiabilityInsuranceFlag = judgeIsExcludeFlag(thirdPartyLiabilityInsurance, list, dispatchRulesAttrList,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_12.getCode());
+            if(!isExcludeThirdPartyLiabilityInsuranceFlag){
+                quoteInfoErorMsg+= DispatchTypeConstants.matchKey(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_12.getCode())+"的值为"+(thirdPartyLiabilityInsurance==null?"不投保":thirdPartyLiabilityInsurance)+"未匹配"+"\n";
+            }
+            //验证新车购置价
+            priceFlag = judgeIsExcludeFlag(price, list, dispatchRulesAttrList,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode());
+            if(!priceFlag){
+                quoteInfoErorMsg+= DispatchTypeConstants.matchKey(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode())+"的值为"+(price==null?"":price)+"未匹配"+"\n";
+            }
+            String custimers = getCustomersFlag(policyHolderInfo, insuredPersonInfo)?"0":"1";
+            String custimersMsg = getCustomersAllMsg(policyHolderInfo, insuredPersonInfo);
+            //验证投被是否一致
+            custemerFlag = judgeIsExcludeFlag(custimers, list, dispatchRulesAttrList,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_11.getCode());
+            if(!custemerFlag){
+                quoteInfoErorMsg+= DispatchTypeConstants.matchKey(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_11.getCode())+"的值为"+(custimersMsg==null?"":custimersMsg)+"未匹配"+"\n";
+            }
         }
         logger.info("==============================="+ptlTaxSourceNew.getAgreementId()+"协议调度规则对象为:"+ptlTaxSourceNew.toString()+"=====================================");
         logger.info("==============================="+ptlTaxSourceNew.getAgreementId()+"协议调度规则内容为:"+ptlTaxSourceNew.getDispatchContent()+"===============================");
         logger.info("==============================="+ptlTaxSourceNew.getAgreementId()+"报价参数信息为:"+msg+"===============================");
         logger.info("==============================="+ptlTaxSourceNew.getAgreementId()+"未匹配信息为:"+quoteInfoErorMsg+"===============================");
         //if (isExclude && isExcludeLicense && isExcludeSeats && isExcludeVolume && isExcludeCimodelclass && isExcludeVehicleUse  && isExcludeYqInsureFlag  && isExcludeCxInsureFlag && isExcludeThirdPartyLiabilityInsurance ) {
-        if (isExcludeLicense && isExcludeSeats && isExcludeVolume && isExcludeCimodelclass && isExcludeVehicleUse  && isExcludeYqInsureFlag  && isExcludeCxInsureFlag && isExcludeThirdPartyLiabilityInsurance && isEnergyType) {
+        if (isExcludeLicense && isExcludeSeats && isExcludeVolume && isExcludeCimodelclass && isExcludeVehicleUse  && isExcludeYqInsureFlag  && isExcludeCxInsureFlag && isExcludeThirdPartyLiabilityInsurance && isEnergyType
+        && isExcludeThirdPartyLiabilityInsuranceFlag && priceFlag && custemerFlag) {
             agreementId = ptlTaxSourceNew.getAgreementId();
         }
         PtlTaxSourceNewRecord  ptlTaxSourceNewRecord=new PtlTaxSourceNewRecord(orderno, ptlTaxSourceNew.toString(), ptlTaxSourceNew.getDispatchContent(), msg, quoteInfoErorMsg,new Date(), userId);
@@ -686,7 +725,7 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
      *  @Date: 2024/5/28 9:12
      *  @Description: 前台信息拼接
      */
-    private static String getString(String allMag, String val1,String val2,String val3,String val4,String val5,String val6,String val7,String val8) {
+    private static String getString(String allMag, String val1,String val2,String val3,String val4,String val5,String val6,String val7,String val8,String energyType,String price,CustomerInfoVo tbrMsg,CustomerInfoVo bbrMsg) {
         String msg="";
         allMag += getAllString(msg, val1,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_1.getCode());
         allMag +=getAllString(msg, val2,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_2.getCode());
@@ -696,6 +735,12 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
         allMag +=getAllString(msg, "1".equals(val6)?"是":"否",DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_6.getCode());
         allMag +=getAllString(msg, "1".equals(val7)?"是":"否",DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_7.getCode());
         allMag +=getAllString(msg, val8,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode());
+        //能源类型
+        allMag +=getAllString(msg, energyType,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_9.getCode());
+        //新车购置价
+        allMag +=getAllString(msg, price,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode());
+        //投被信息
+        allMag +=getAllTBmsgString(msg, tbrMsg,bbrMsg,DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode());
         return allMag;
     }
 
@@ -715,6 +760,60 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
         return msg;
     }
 
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/30 17:00
+     *  @Description:  获取投保人和被保人信息
+     */
+    private static String getAllTBmsgString(String msg, CustomerInfoVo tbr,CustomerInfoVo bbr,String code) {
+        msg +=DispatchTypeConstants.matchKey(code)+"的值为" +getCustomersAllMsg(tbr,bbr)+"\n";
+        return msg;
+    }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/30 17:38
+     *  @Description:  获取投被信息
+     */
+    private static String getCustomersAllMsg(CustomerInfoVo tbr,CustomerInfoVo bbr) {
+        String tbrMsg ="";
+        String bbrMsg ="";
+        if(tbr!=null){
+            String name = tbr.getName()==null?"": tbr.getName();
+            String idCard= tbr.getIdentifyNumber()==null?"": tbr.getIdentifyNumber();
+            tbrMsg+="投保人姓名为:"+name+";";
+            tbrMsg+="投保人身份证为:"+idCard+";";
+        }
+        if(bbr!=null){
+            String name = bbr.getName()==null?"": bbr.getName();
+            String idCard= bbr.getIdentifyNumber()==null?"": bbr.getIdentifyNumber();
+            bbrMsg+="被保人姓名为:"+name+";";
+            bbrMsg+="被保人身份证为:"+idCard+";";
+        }
+        return tbrMsg+bbrMsg;
+    }
+
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/30 17:00
+     *  @Description:  判断投被是否一致
+     */
+    private static boolean getCustomersFlag(CustomerInfoVo tbr,CustomerInfoVo bbr) {
+        if(tbr!=null  &&  bbr!=null){
+            String tbr_name = tbr.getName()==null?"": tbr.getName();
+            String tbr_idCard= tbr.getIdentifyNumber()==null?"": tbr.getIdentifyNumber();
+            String bbr_name = bbr.getName()==null?"": tbr.getName();
+            String bbr_idCard= bbr.getIdentifyNumber()==null?"": tbr.getIdentifyNumber();
+            if(tbr_name.equals(bbr_name) && tbr_idCard.equals(bbr_idCard) ){
+                return true;
+            }
+        }
+        return false;
+    }
+
+
     /**
      *  @version
      *  @author: hxl
@@ -723,9 +822,16 @@ public class PtlTaxSourceServiceImpl extends ServiceImpl<PtlTaxSourceNewMapper,
      */
     private static boolean judgeIsExcludeFlag(String val, List<PtlAgreementDispatchRulesAttrLink> list, List<PtlAgreementDispatchRulesAttr> dispatchRulesAttrList,String code) {
         boolean isExcludeFlag;
-        if(StringUtils.isBlank(val)){
-            if(!DispatchTypeConstants.removalOfCode().contains(code)){
-                throw new SystemException(DispatchTypeConstants.matchKey(code)+"不能为空");
+        //if(StringUtils.isBlank(val)){
+        //    if(!DispatchTypeConstants.removalOfCode().contains(code)){
+       //         throw new SystemException(DispatchTypeConstants.matchKey(code)+"不能为空");
+       //     }
+       // }
+        if(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_12.getCode().equals(code)){
+            if(StringUtils.isNotBlank(val)){
+                val = "不投保".equals(val)?"0":"1";
+            }else{
+                val = "0";
             }
         }
         isExcludeFlag = RulesMergeStrUtils.judgeVal(list, (DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_1.getCode().equals(code))?val.substring(0, 2):val, code, dispatchRulesAttrList);

+ 2 - 2
src/main/java/com/ydtech/modules/protocol/utils/RulesMergeStrUtils.java

@@ -100,8 +100,8 @@ public class RulesMergeStrUtils {
         Boolean resultFlag=false;
         if ("inputNumber".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
             if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin()) || StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMax()) ) {
-                //三者险为null为不投保情况直接返回false
-                if(DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode().equals(code) &&  val==null){
+                //三者险为null为不投保情况 或者新车购置价为空   直接返回false
+                if((DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode().equals(code) || DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode().equals(code)) &&  val==null){
                     resultFlag=false;
                 }else{
                     //取符号做判断

+ 17 - 7
src/main/resources/mapper/modules/protocol/PtlAgreementGroupLinkAgreementMapper.xml

@@ -30,6 +30,7 @@
         WHERE
             agreement.valid_status = 1
             AND agreement.is_external = 0
+            AND agreement.deleted = 0
             AND date(
             now()) BETWEEN date( agreement.start_date )
             AND date( agreement.end_date )
@@ -57,10 +58,11 @@
     </select>
     <select id="findByGroupId" resultType="java.lang.Long">
        select
-           ptl_agreement_id
+           link.ptl_agreement_id
        from
-        ptl_agreement_group_link_agreement
-        where   ptl_agreement_group_id = #{agreementGroupId}
+        ptl_agreement_group_link_agreement  link  left  join   ptl_agreement agreement
+        on  link.ptl_agreement_id  =  agreement.id
+        where   agreement.deleted = 0 and   ptl_agreement_group_id = #{agreementGroupId}
     </select>
     <select id="findLinkAgreementList"
             resultType="com.ydtech.modules.protocol.entity.dto.PtlAgreementGroupLinkAgreementDto">
@@ -88,18 +90,26 @@
                 LEFT JOIN ptl_agreement agreement ON pagla.ptl_agreement_id = agreement.id
                 LEFT JOIN esm_ins_company eic ON agreement.insurance_company_id = eic.id
                 where
-                    pagla.ptl_agreement_group_id =#{vo.agreementGroupId}
+                    agreement.deleted = 0
+                    and pagla.ptl_agreement_group_id =#{vo.agreementGroupId}
                 <if test="vo.companyId != null and vo.companyId != ''">
                     AND agreement.insurance_company_id = #{vo.companyId}
                 </if>
     </select>
     <select id="findByIds" resultType="com.ydtech.modules.protocol.entity.po.PtlAgreementGroupLinkAgreement">
         select
-            <include refid="Base_Column_List"/>
+            link.id,
+            link.ptl_agreement_id,
+            link.ptl_agreement_group_id,
+            link.create_time,
+            link.create_user
         from
-            ptl_agreement_group_link_agreement
+            ptl_agreement_group_link_agreement   link  left  join   ptl_agreement agreement
+             on  link.ptl_agreement_id  =  agreement.id
        <where>
-            id IN
+            agreement.deleted = 0
+            and
+            link.id IN
            <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
                #{item}
            </foreach>

+ 3 - 2
src/main/resources/mapper/modules/protocol/PtlAgreementGroupLinkDeptMapper.xml

@@ -47,9 +47,10 @@
         from esm_ins_company as eic
         left join ptl_agreement as pa on pa.insurance_company_id = eic.id
         left join ptl_agreement_attribution as paa on paa.id = pa.id
-        where (#{localDate} between start_date and DATE_SUB(end_date, INTERVAL 1 DAY))
-        and (paa.template_id is not null)
+        where
+            (#{localDate} between pa.start_date and DATE_SUB(pa.end_date, INTERVAL 1 DAY))
         and pa.valid_status = 1
+        and pa.deleted = 0
         and pa.id in (
             SELECT
                 pagla.ptl_agreement_id