Sfoglia il codice sorgente

1. 订单回收站修改

785834757 9 mesi fa
parent
commit
1e4d79f7f6

+ 2 - 4
src/main/java/com/ydtech/modules/order/dao/InsOrdersMapper.java

@@ -27,14 +27,12 @@ public interface InsOrdersMapper extends BaseMapper<InsOrders> {
     Long queryPageOrderCount(@Param("orderQueryVo") OrderQueryVo orderQueryVo,
     Long queryPageOrderCount(@Param("orderQueryVo") OrderQueryVo orderQueryVo,
                              @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
                              @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
 
 
-    Long queryPageDeleteOrderCount(@Param("orderQueryVo") OrderQueryVo orderQueryVo,
-                             @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
+    Long queryPageDeleteOrderCount(@Param("orderQueryVo") OrderQueryVo orderQueryVo, @Param("agentUserIds") List<String> agentUserIds, @Param("agreeIds") List<String> agreeIds, @Param("deptIds") List<String> deptIds, @Param("flag") Boolean flag, @Param("type") int type);
 
 
     Page<InsOrders> queryPageOrder(@Param("page") Page page, @Param("orderQueryVo") OrderQueryVo orderQueryVo,
     Page<InsOrders> queryPageOrder(@Param("page") Page page, @Param("orderQueryVo") OrderQueryVo orderQueryVo,
                                    @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
                                    @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
 
 
-    Page<InsOrders> queryPageDeleteOrder(@Param("page") Page page, @Param("orderQueryVo") OrderQueryVo orderQueryVo,
-                                   @Param("isTeamLeader") Boolean isTeamLeader, @Param("isCdy") Boolean isCdy, @Param("deptId") String deptId, @Param("isDxFlag") Boolean isDxFlag);
+    Page<InsOrders> queryPageDeleteOrder(@Param("page") Page<InsOrders> page, @Param("orderQueryVo") OrderQueryVo orderQueryVo, @Param("agentUserIds") List<String> agentUserIds, @Param("agreeIds") List<String> agreeIds, @Param("deptIds") List<String> deptIds, @Param("flag") Boolean flag, @Param("type") int type);
 
 
 
 
     /**
     /**

+ 2 - 0
src/main/java/com/ydtech/modules/order/entity/vo/OrderQueryVo.java

@@ -205,6 +205,8 @@ public class OrderQueryVo {
     @ApiModelProperty("审核时间结束时间")
     @ApiModelProperty("审核时间结束时间")
     private String auditTimeEnd;
     private String auditTimeEnd;
 
 
+    @ApiModelProperty("人员类型")
+    private Integer personType;
 
 
 
 
     public LocalDate getEndDatePlusOneDay() {
     public LocalDate getEndDatePlusOneDay() {

+ 57 - 61
src/main/java/com/ydtech/modules/order/service/impl/InsOrdersServiceImpl.java

@@ -860,72 +860,68 @@ public class InsOrdersServiceImpl extends ServiceImpl<InsOrdersMapper, InsOrders
 
 
     @Override
     @Override
     public BasePageResult<InsOrders> newQueryPageDeleteOrder(OrderQueryVo orderQueryVo) {
     public BasePageResult<InsOrders> newQueryPageDeleteOrder(OrderQueryVo orderQueryVo) {
-        Page<InsOrders> page = new Page<>(orderQueryVo.getPageNum(), orderQueryVo.getPageSize());
-        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
-        boolean adminFalg = false;
-        //修改逻辑   add by  hxl   修改查询当前登陆人的订单   admin 可以查看所有
-        String userId = BaseController.getUserId();
-        if ("admin".equals(userId)) {
-            adminFalg = true;
+        //添加收回按钮的操作
+        //优化查询效率   add by hxl  2025-01-25
+        if(StringUtils.isNotBlank(orderQueryVo.getQuoteStartDateStr()) && StringUtils.isNotBlank(orderQueryVo.getQuoteEndDateStr())){
+            if(orderQueryVo.getQuoteStartDateStr().length()==10){
+                orderQueryVo.setQuoteStartDateStr(orderQueryVo.getQuoteStartDateStr()+" 00:00:00");
+            }
+            if(orderQueryVo.getQuoteEndDateStr().length()==10){
+                orderQueryVo.setQuoteEndDateStr(orderQueryVo.getQuoteEndDateStr()+" 23:59:59");
+            }
         }
         }
-        /**
-         // 领导标志
-         boolean isTeamLeader = false;
-         //是否出单员标志
-         boolean isCdy = false;
-         if (StringUtils.isNotEmpty(orderQueryVo.getUserId())) {
-         SysUserRole userRole = sysUserRoleService.selectByUserId(orderQueryVo.getUserId());
-         if (Arrays.asList(SystemConstant.getSysRoleTeamLeader()).contains(userRole.getRoleId().toString())) {
-         //团队长可查询下面所有人员订单
-         isTeamLeader = true;
-         }
-         if (19 == userRole.getRoleId()) {
-         isCdy = true;
-         }
-         }
-         orderQueryVo.setEndDate(orderQueryVo.getEndDatePlusOneDay());
-         **/
-        //添加渠道团队长可以查看下级  add by hxl   2024-07-12
-        SysUserRole userRole = sysUserRoleService.selectByUserId(orderQueryVo.getUserId());
-        SysUser user = sysUserService.getById(orderQueryVo.getUserId());
-        SysDept dept = sysDeptService.getById(user.getDeptId());
-        String deptId = "";
-        boolean isCdy = false;
-        boolean isDxFlag = false;
-        //机构类型为1  角色id=21是渠道团队长
-        if (dept != null && "1".equals(dept.getManagementSource()) && userRole != null && userRole.getRoleId() == 21) {
-            deptId = dept.getId();
-            isCdy = true;
+        if(StringUtils.isNotBlank(orderQueryVo.getSignStartDateStr()) && StringUtils.isNotBlank(orderQueryVo.getSignEndDateStr())){
+            if(orderQueryVo.getSignStartDateStr().length()==10){
+                orderQueryVo.setSignStartDateStr(orderQueryVo.getSignStartDateStr()+" 00:00:00");
+            }
+            if(orderQueryVo.getSignEndDateStr().length()==10){
+                orderQueryVo.setSignEndDateStr(orderQueryVo.getSignEndDateStr()+" 23:59:59");
+            }
         }
         }
-        //车险查询添加电销组长可以查询电销下的数据   电销组长 72
-        if (dept != null && "3".equals(dept.getManagementSource()) && userRole != null && userRole.getRoleId() == 72) {
-            //  add  by hxl  去除机构查询
-            //deptId = dept.getId();
-            orderQueryVo.setDeptId(null);
-            isDxFlag = true;
+        Boolean flag = false;
+        Page<InsOrders> page = new Page<>(orderQueryVo.getPageNum(), orderQueryVo.getPageSize());
+        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
+        List<String> agentUserIds = new ArrayList<>();
+        List<String> agreeIds = new ArrayList<>();
+        List<String> deptIds = new ArrayList<>();
+        //角色为需要查询下级的用户
+        if (orderQueryVo.getPersonType() == 1) {
+            //渠道
+            //查询用户表中的信息为领带id为用户id的数据
+            agentUserIds = sysUserService.getUserIdsByLeaderId(orderQueryVo.getUserId());
+            //查询下级
+        } else if (orderQueryVo.getPersonType() == 3) {
+            //查询所有的代理人
+            //查询绑定的区域的代理人信息
+            List<String> areaCodes = sysUserLinkAreaMapper.findAreaCodeByUserId(orderQueryVo.getUserId());
+            if (areaCodes != null && !areaCodes.isEmpty()) {
+                agentUserIds = sysUserLinkAreaMapper.findAreaIdsByAgentUserId(orderQueryVo.getUserId(), areaCodes);
+            }
+        } else if (orderQueryVo.getPersonType() == 2) {
+            //查询用户关联的协议
+            /**
+             List<SysUserLinkPtlAgreementDto> ptlAgreementListByUserIds =
+             sysUserLinkPtlAgreementMapper.findPtlAgreementListByUserId(orderQueryVo.getUserId());
+             if (ptlAgreementListByUserIds != null && !ptlAgreementListByUserIds.isEmpty()) {
+             for (SysUserLinkPtlAgreementDto sysUserLinkPtlAgreementDto : ptlAgreementListByUserIds) {
+             agreeIds.add(sysUserLinkPtlAgreementDto.getPtlAgreement().getId());
+             }
+             }
+             **/
+            //  add by  hxl 2025-01-08  注释关联的协议维护太频繁改为关联保险公司
+            agreeIds = sysUserLinkCompanyMapper.findCompanyListByUserId(orderQueryVo.getUserId());
+        } else if (orderQueryVo.getPersonType() == 4) {
+            agentUserIds = sysUserService.getTelemarketingPersonnelData();
         }
         }
-        Page<InsOrders> orderVoPage = baseMapper.queryPageDeleteOrder(page, orderQueryVo, adminFalg, isCdy, deptId, isDxFlag);
-        Long total = baseMapper.queryPageDeleteOrderCount(orderQueryVo, adminFalg, isCdy, deptId, isDxFlag);
-        orderVoPage.setTotal(total);
 
 
-        List<InsOrders> records = orderVoPage.getRecords();
-        if (!records.isEmpty()) {
-            List<String> collect = records.stream().map(InsOrders::getOrderno).collect(Collectors.toList());
-            Map<String, String> subOrderCountDTO = insAreaCompanyService.getSubOrderCountDTO(collect);
-
-            records.forEach(x -> {
-
-                if (!InsOrderStatusEnum.ACCEPT_INSURANCE.getCode().equals(x.getOrderstatus())) {
-                    JSONArray risk = x.getRisk();
-                    List<RiskInfoVo> javaList = risk.toJavaList(RiskInfoVo.class);
-                    javaList.forEach(RiskInfoVo::expirationTime);
-                    JSONArray objects = JSON.parseArray(JSON.toJSONString(javaList));
-                    x.setRisk(objects);
-                }
-
-                x.setSubOrderStatus(subOrderCountDTO);
-            });
+        Long total = 0L;
+        Page<InsOrders> orderVoPage = new Page<>();
+        //注释逻辑给前台返回数据
+        if (agentUserIds != null && !agentUserIds.isEmpty() || !agreeIds.isEmpty()) {
+            orderVoPage = baseMapper.queryPageDeleteOrder(page, orderQueryVo, agentUserIds, agreeIds, deptIds, flag, orderQueryVo.getPersonType());
+            total = baseMapper.queryPageDeleteOrderCount(orderQueryVo, agentUserIds, agreeIds, deptIds, flag, orderQueryVo.getPersonType());
         }
         }
+        orderVoPage.setTotal(total);
         return new BasePageResult<>(orderQueryVo.getPageNum(), orderQueryVo.getPageSize(), orderVoPage.getTotal(),
         return new BasePageResult<>(orderQueryVo.getPageNum(), orderQueryVo.getPageSize(), orderVoPage.getTotal(),
                 orderVoPage.getPages()
                 orderVoPage.getPages()
                 , orderVoPage.getRecords());
                 , orderVoPage.getRecords());

+ 339 - 82
src/main/resources/mapper/modules/order/InsOrdersMapper.xml

@@ -376,24 +376,60 @@
         count(1)
         count(1)
         from (
         from (
         select
         select
-        io.orderno
+        (0)
         from
         from
-        ins_orders io
-        <!--如果存在 公司查询则进行连表 -->
-        <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
-            left JOIN
-            ins_area_company iac on iac.orderno = io.orderno
-        </if>
-        where
-            io.del_flag = 1
-            <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
-                and io.orderno = #{orderQueryVo.orderNo}
+        ins_area_company iac
+        left JOIN
+        ins_orders io  on iac.orderno = io.orderno
+        LEFT JOIN
+        sys_dept dept ON dept.id = io.deptid
+        LEFT JOIN
+        sys_user u on io.userid = u.id
+        left join
+        ptl_agreement   agree  on  iac.agreement_id= agree.id
+        left join
+        esm_ins_company   company  on  agree.partner_companies_id= company.id
+        <where>
+            <if test="agentUserIds != null and agentUserIds.size>0" >
+                AND (
+                (io.userid in
+                <foreach collection="agentUserIds" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+                AND ( iac.new_operator_id IS NULL  OR iac.new_operator_id = #{orderQueryVo.userId} )
+                <if test="deptIds != null and deptIds.size>0" >
+                    AND (
+                    <foreach collection="deptIds" item="item" open="(" separator="OR" close=")">
+                        io.deptid like CONCAT('', #{item}, '%')
+                    </foreach>
+                    )
+                </if>
+                )
+                <if test="flag" >
+                    OR iac.operator_id = #{orderQueryVo.userId}
+                </if>
+                )
             </if>
             </if>
-            <if test="orderQueryVo.deptId != null and orderQueryVo.deptId != ''">
-                and io.deptid like "${orderQueryVo.deptId}%"
+            <if test="agreeIds != null and agreeIds.size>0">
+                AND (
+                (iac.company_id in
+                <foreach collection="agreeIds" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+                AND ( iac.new_operator_id IS NULL  OR iac.new_operator_id = #{orderQueryVo.userId} ) )
+                <if test="flag" >
+                    OR iac.operator_id = #{orderQueryVo.userId}
+                </if>
+                )
             </if>
             </if>
-            <if test="orderQueryVo.orderStatus != null and orderQueryVo.orderStatus != ''">
-                and io.orderstatus = #{orderQueryVo.orderStatus}
+            <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
+                and iac.id = #{orderQueryVo.orderNo}
+            </if>
+            <if test="orderQueryVo.managementSource != null and orderQueryVo.managementSource.size > 0">
+                and dept.management_source in
+                <foreach item="source" collection="orderQueryVo.managementSource" open="(" separator="," close=")">
+                    #{source}
+                </foreach>
             </if>
             </if>
             <if test="orderQueryVo.frameNo != null and orderQueryVo.frameNo != ''">
             <if test="orderQueryVo.frameNo != null and orderQueryVo.frameNo != ''">
                 and io.frameno = #{orderQueryVo.frameNo}
                 and io.frameno = #{orderQueryVo.frameNo}
@@ -402,38 +438,99 @@
                 and io.licenseno = #{orderQueryVo.licenseNo}
                 and io.licenseno = #{orderQueryVo.licenseNo}
             </if>
             </if>
             <if test="orderQueryVo.insuredName != null and orderQueryVo.insuredName != ''">
             <if test="orderQueryVo.insuredName != null and orderQueryVo.insuredName != ''">
-                and io.insuredname = #{orderQueryVo.insuredName}
+                and REPLACE(JSON_EXTRACT(io.applyinfo, '$.name'),'"','') = #{orderQueryVo.insuredName}
             </if>
             </if>
-            <if test="orderQueryVo.startDate != null and orderQueryVo.endDate != null">
-                and DATE_FORMAT(io.createtime, '%Y-%m-%d') between #{orderQueryVo.startDate} AND #{orderQueryVo.endDate}
+            <if test="orderQueryVo.quoteStartDateStr != null and orderQueryVo.quoteEndDateStr != null">
+                and iac.createtime >= #{orderQueryVo.quoteStartDateStr} AND iac.createtime  <![CDATA[ <= ]]> #{orderQueryVo.quoteEndDateStr}
             </if>
             </if>
             <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
             <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
                 and iac.company_id = #{orderQueryVo.companyId}
                 and iac.company_id = #{orderQueryVo.companyId}
             </if>
             </if>
-            <!--
-           <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and isCdy">
-                and io.operatorid = #{orderQueryVo.userId}
-          </if>
-           -->
+            <if test="orderQueryVo.engineNo != null and orderQueryVo.engineNo != ''">
+                and JSON_EXTRACT( io.carinfo, '$.engineNo' )  = #{orderQueryVo.engineNo}
+            </if>
+            <if test="orderQueryVo.provinceId != null and orderQueryVo.provinceId != ''">
+                and io.deptid like "${orderQueryVo.provinceId}%"
+            </if>
+            <if test="orderQueryVo.cityId != null and orderQueryVo.cityId != ''">
+                and io.deptid like "${orderQueryVo.cityId}%"
+            </if>
+            <if test="orderQueryVo.countyId != null and orderQueryVo.countyId != ''">
+                and io.deptid like "${orderQueryVo.countyId}%"
+            </if>
+            <if test="orderQueryVo.houseId != null and orderQueryVo.houseId != ''">
+                and io.deptid like "${orderQueryVo.houseId}%"
+            </if>
+            <if test="orderQueryVo.agreeId != null and orderQueryVo.agreeId != ''">
+                and iac.agreement_id = #{orderQueryVo.agreeId}
+            </if>
+            <if test="orderQueryVo.taskNo != null and orderQueryVo.taskNo != ''">
+                and io.orderno = #{orderQueryVo.taskNo}
+            </if>
+            <if test="orderQueryVo.riskCode != null and orderQueryVo.riskCode != ''">
+                and iac.product = #{orderQueryVo.riskCode}
+            </if>
+
+            <if test="orderQueryVo.leaderId != null and orderQueryVo.leaderId != ''">
+                and u.leader_id = #{orderQueryVo.leaderId}
+            </if>
+            <if test="orderQueryVo.leaderName != null and orderQueryVo.leaderName != ''">
+                and u.leader_name = #{orderQueryVo.leaderName}
+            </if>
+
+            <if test="orderQueryVo.attachStartDateStr != null and orderQueryVo.attachEndDateStr != ''">
+                and  ((
+                DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{orderQueryVo.attachStartDateStr}
+                AND #{orderQueryVo.attachEndDateStr}
+                )
+                OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d')  BETWEEN #{orderQueryVo.attachStartDateStr} AND #{orderQueryVo.attachEndDateStr} )
+                )
+            </if>
             <choose>
             <choose>
-                <when test="isCdy">
-                    <if test="deptId != null and deptId != '' ">
-                        and io.deptid like "${deptId}%"
-                    </if>
+                <when test="type==1">
+                    and dept.management_source=1
                 </when>
                 </when>
-                <when test="isDxFlag">
-                    <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' ">
-                        and io.userid in ( select id from sys_user where manager_id = #{orderQueryVo.userId} or id =
-                        #{orderQueryVo.userId} )
-                    </if>
+                <when test="type==2">
+                    and dept.management_source=2
                 </when>
                 </when>
-                <otherwise>
-                    <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and !isTeamLeader">
-                        and io.userid = #{orderQueryVo.userId}
-                    </if>
-                </otherwise>
             </choose>
             </choose>
-        group by io.orderno
+            <if test="orderQueryVo.signStartDateStr != null and orderQueryVo.signEndDateStr != null">
+                and  iac.signing_time >= #{orderQueryVo.signStartDateStr} AND   iac.signing_time <![CDATA[ <= ]]> #{orderQueryVo.signEndDateStr}
+            </if>
+            <if test="orderQueryVo.entryStatus != null and orderQueryVo.entryStatus != ''">
+                and io.entry_status = #{orderQueryVo.entryStatus }
+            </if>
+            <if test="orderQueryVo.payStartDateStr != null and orderQueryVo.payEndDateStr != null">
+                and  DATE_FORMAT(iac.pay_date, '%Y-%m-%d') between #{orderQueryVo.payStartDateStr} AND #{orderQueryVo.payEndDateStr}
+            </if>
+
+            <if test="orderQueryVo.auditStartDateStr != null and orderQueryVo.auditEndDateStr != null">
+                and  DATE_FORMAT(iac.underwriting_time, '%Y-%m-%d') between #{orderQueryVo.auditStartDateStr} AND #{orderQueryVo.auditEndDateStr}
+            </if>
+            <if test="orderQueryVo.updateStartDateStr != null and orderQueryVo.updateEndDateStr != null">
+                and  DATE_FORMAT( iac.update_status_time, '%Y-%m-%d') between #{orderQueryVo.updateStartDateStr} AND #{orderQueryVo.updateEndDateStr}
+            </if>
+            <if test="orderQueryVo.updateStatus != null and orderQueryVo.updateStatus != null">
+                and  iac.update_status =  #{orderQueryVo.updateStatus}
+            </if>
+            <if test="orderQueryVo.partnerCompaniesId != null and orderQueryVo.partnerCompaniesId != null">
+                and  agree.partner_companies_id =  #{orderQueryVo.partnerCompaniesId}
+            </if>
+            and (io.del_flag = 0)
+        </where>
+        group by io.orderno,
+        iac.orderstatus,
+        iac.productid,
+        iac.product,
+        iac.jq_start_date,
+        iac.jq_end_date,
+        iac.sy_start_date,
+        iac.sy_end_date,
+        iac.jqpremium,
+        iac.sypremium,
+        iac.jypremium,
+        iac.taxamount,
+        iac.id
         ) as s
         ) as s
     </select>
     </select>
 
 
@@ -510,28 +607,130 @@
         order by io.createtime desc
         order by io.createtime desc
     </select>
     </select>
 
 
-
     <select id="queryPageDeleteOrder" resultMap="BaseResultMap">
     <select id="queryPageDeleteOrder" resultMap="BaseResultMap">
         select
         select
-        io.*
+        io.orderno as orderno,
+        io.quoteno as  quoteno,
+        iac.orderstatus as orderstatus,
+        io.carinfo as  carinfo,
+        io.userid as userid,
+        io.username as username,
+        io.deptid as deptid,
+        io.deptname as deptname,
+        io.ownerinfo as ownerinfo,
+        io.applyinfo as applyinfo,
+        io.insureinfo as insureinfo,
+        io.agreeid as agreeid,
+        iac.productid as productid,
+        iac.product as product,
+        MAX(iac.createtime) as createtime,
+        io.frameno as frameno,
+        io.licenseno as licenseno,
+        REPLACE(JSON_EXTRACT(io.applyinfo, '$.name'),'"','')  as insuredname,
+        iac.jq_start_date as jqstartdate,
+        iac.jq_end_date as jqenddate,
+        iac.sy_start_date as systartdate,
+        iac.sy_end_date as syenddate,
+        iac.jqpremium as jqpremium,
+        iac.sypremium as sypremium,
+        iac.jypremium as jypremium,
+        iac.taxamount as taxamount,
+        io.risk as risk,
+        io.king as king,
+        io.vehicle_and_vessel_tax as vehicleAndVesselTax,
+        iac.id as subOrderId,
+        iac.underwriting_status as underwritingStatus,
+        iac.company_id as company_id,
+        iac.inscompany as ins_company,
+        agree.agreement_code as agreementCode,
+        agree.agreement_name as agreementName,
+        company.namesimple as partnerCompaniesName,
+        dept.province,
+        dept.city,
+        dept.area,
+        d1.area_cname as province_name,
+        d2.area_cname as city_name,
+        d3.area_cname as area_name,
+        concat(d1.area_cname,d2.area_cname,d3.area_cname) as area_info,
+        iac.api_type,
+        io.is_external,
+        u.leader_name,
+        u.leader_id,
+        CASE dept.management_source
+        WHEN '1' THEN '渠道'
+        WHEN '2' THEN '个代'
+        WHEN '3' THEN '电销'
+        ELSE '' END
+        AS managementSource,
+        io.entry_status  as entryStatus,
+        iac.underwriting_time as underwritingTime,
+        iac.pay_date  as payDate,
+        iac.update_status AS updateStatus,
+        iac.update_status_time AS updateStatusTime,
+        iac.signing_time as signingTime,
+        oou.NAME as operatorName
         from
         from
-        ins_orders io
-        <!--如果存在 公司查询则进行连表 -->
-        <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
-            left JOIN
-            ins_area_company iac on iac.orderno = io.orderno
-        </if>
-        where
-            io.del_flag = 1
-            <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
-                and io.orderno = #{orderQueryVo.orderNo}
+        ins_area_company iac
+        left JOIN
+        ins_orders io  on iac.orderno = io.orderno
+        left join
+        ptl_agreement   agree  on  iac.agreement_id= agree.id
+        left join
+        esm_ins_company   company  on  agree.partner_companies_id= company.id
+        LEFT JOIN
+        sys_dept dept ON dept.id = io.deptid
+        LEFT JOIN sys_dept pdept on dept.parent_id = pdept.id
+        LEFT JOIN sys_area d1 ON d1.area_code = pdept.province
+        LEFT JOIN sys_area d2 ON d2.area_code = pdept.city
+        LEFT JOIN sys_area d3 ON d3.area_code = pdept.area
+        LEFT JOIN
+        sys_user u on io.userid = u.id
+        LEFT JOIN sys_user oou ON io.operatorid = oou.id
+        <where>
+            <if test="agentUserIds != null and agentUserIds.size>0" >
+                AND (
+                (io.userid in
+                <foreach collection="agentUserIds" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+                AND ( iac.new_operator_id IS NULL  OR iac.new_operator_id = #{orderQueryVo.userId} )
+                <if test="deptIds != null and deptIds.size>0" >
+                    AND (
+                    <foreach collection="deptIds" item="item" open="(" separator="OR" close=")">
+                        io.deptid like CONCAT('', #{item}, '%')
+                    </foreach>
+                    )
+                </if>
+                )
+                <if test="flag" >
+                    OR iac.operator_id = #{orderQueryVo.userId}
+                </if>
+                )
             </if>
             </if>
-            <if test="orderQueryVo.deptId != null and orderQueryVo.deptId != ''">
-                and io.deptid like "${orderQueryVo.deptId}%"
+            <if test="agreeIds != null and agreeIds.size>0">
+                AND (
+                (iac.company_id in
+                <foreach collection="agreeIds" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+                AND ( iac.new_operator_id IS NULL  OR iac.new_operator_id = #{orderQueryVo.userId} ) )
+                <if test="flag" >
+                    OR iac.operator_id = #{orderQueryVo.userId}
+                </if>
+                )
             </if>
             </if>
-            <if test="orderQueryVo.orderStatus != null and orderQueryVo.orderStatus != ''">
-                and io.orderstatus = #{orderQueryVo.orderStatus}
+            <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
+                and iac.id = #{orderQueryVo.orderNo}
+            </if>
+
+            <if test="orderQueryVo.managementSource != null and orderQueryVo.managementSource.size > 0">
+                and dept.management_source in
+                <foreach item="source" collection="orderQueryVo.managementSource" open="(" separator="," close=")">
+                    #{source}
+                </foreach>
             </if>
             </if>
+
+
             <if test="orderQueryVo.frameNo != null and orderQueryVo.frameNo != ''">
             <if test="orderQueryVo.frameNo != null and orderQueryVo.frameNo != ''">
                 and io.frameno = #{orderQueryVo.frameNo}
                 and io.frameno = #{orderQueryVo.frameNo}
             </if>
             </if>
@@ -539,47 +738,105 @@
                 and io.licenseno = #{orderQueryVo.licenseNo}
                 and io.licenseno = #{orderQueryVo.licenseNo}
             </if>
             </if>
             <if test="orderQueryVo.insuredName != null and orderQueryVo.insuredName != ''">
             <if test="orderQueryVo.insuredName != null and orderQueryVo.insuredName != ''">
-                and io.insuredname = #{orderQueryVo.insuredName}
+                and REPLACE(JSON_EXTRACT(io.applyinfo, '$.name'),'"','') = #{orderQueryVo.insuredName}
             </if>
             </if>
-            <if test="orderQueryVo.startDate != null and orderQueryVo.endDate != null">
-                and DATE_FORMAT(io.createtime, '%Y-%m-%d') between #{orderQueryVo.startDate} AND #{orderQueryVo.endDate}
+            <if test="orderQueryVo.quoteStartDateStr != null and orderQueryVo.quoteEndDateStr != null">
+                and  iac.createtime >= #{orderQueryVo.quoteStartDateStr} AND  iac.createtime <![CDATA[ <= ]]> #{orderQueryVo.quoteEndDateStr}
             </if>
             </if>
             <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
             <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
                 and iac.company_id = #{orderQueryVo.companyId}
                 and iac.company_id = #{orderQueryVo.companyId}
             </if>
             </if>
-            <if test="orderQueryVo.product != null and orderQueryVo.product != ''">
-                and io.product = #{orderQueryVo.product}
+            <if test="orderQueryVo.engineNo != null and orderQueryVo.engineNo != ''">
+                and JSON_EXTRACT( io.carinfo, '$.engineNo' )  = #{orderQueryVo.engineNo}
             </if>
             </if>
-            <if test="orderQueryVo.productid != null and orderQueryVo.productid != ''">
-                and io.productid = #{orderQueryVo.productid}
+            <if test="orderQueryVo.provinceId != null and orderQueryVo.provinceId != ''">
+                and io.deptid like "${orderQueryVo.provinceId}%"
+            </if>
+            <if test="orderQueryVo.cityId != null and orderQueryVo.cityId != ''">
+                and io.deptid like "${orderQueryVo.cityId}%"
+            </if>
+            <if test="orderQueryVo.countyId != null and orderQueryVo.countyId != ''">
+                and io.deptid like "${orderQueryVo.countyId}%"
+            </if>
+            <if test="orderQueryVo.houseId != null and orderQueryVo.houseId != ''">
+                and io.deptid like "${orderQueryVo.houseId}%"
+            </if>
+            <if test="orderQueryVo.agreeId != null and orderQueryVo.agreeId != ''">
+                and iac.agreement_id = #{orderQueryVo.agreeId}
+            </if>
+            <if test="orderQueryVo.taskNo != null and orderQueryVo.taskNo != ''">
+                and io.orderno = #{orderQueryVo.taskNo}
+            </if>
+            <if test="orderQueryVo.riskCode != null and orderQueryVo.riskCode != ''">
+                and iac.product = #{orderQueryVo.riskCode}
             </if>
             </if>
 
 
-            <!--
-           <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and isCdy">
-               and io.operatorid = #{orderQueryVo.userId}
-           </if>
-            -->
+            <if test="orderQueryVo.leaderId != null and orderQueryVo.leaderId != ''">
+                and u.leader_id = #{orderQueryVo.leaderId}
+            </if>
+            <if test="orderQueryVo.leaderName != null and orderQueryVo.leaderName != ''">
+                and u.leader_name = #{orderQueryVo.leaderName}
+            </if>
+
+            <if test="orderQueryVo.attachStartDateStr != null and orderQueryVo.attachEndDateStr != ''">
+                and  ((
+                DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{orderQueryVo.attachStartDateStr}
+                AND #{orderQueryVo.attachEndDateStr}
+                )
+                OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d')  BETWEEN #{orderQueryVo.attachStartDateStr} AND #{orderQueryVo.attachEndDateStr} )
+                )
+            </if>
             <choose>
             <choose>
-                <when test="isCdy">
-                    <if test="deptId != null and deptId != '' ">
-                        and io.deptid like "${deptId}%"
-                    </if>
+                <when test="type==1">
+                    and dept.management_source=1
                 </when>
                 </when>
-                <when test="isDxFlag">
-                    <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' ">
-                        and io.userid in ( select id from sys_user where manager_id = #{orderQueryVo.userId} or id =
-                        #{orderQueryVo.userId} )
-                    </if>
+                <when test="type==2">
+                    and dept.management_source=2
                 </when>
                 </when>
-                <otherwise>
-                    <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and !isTeamLeader">
-                        and io.userid = #{orderQueryVo.userId}
-                    </if>
-                </otherwise>
             </choose>
             </choose>
-        group by
-        orderno, io.createtime
+            <if test="orderQueryVo.signStartDateStr != null and orderQueryVo.signEndDateStr != null">
+                and  iac.signing_time >= #{orderQueryVo.signStartDateStr} AND  iac.signing_time <![CDATA[ <= ]]> #{orderQueryVo.signEndDateStr}
+            </if>
+            <if test="orderQueryVo.entryStatus != null and orderQueryVo.entryStatus != ''">
+                and io.entry_status = #{orderQueryVo.entryStatus }
+            </if>
+            <if test="orderQueryVo.payStartDateStr != null and orderQueryVo.payEndDateStr != null">
+                and  DATE_FORMAT(iac.pay_date, '%Y-%m-%d') between #{orderQueryVo.payStartDateStr} AND #{orderQueryVo.payEndDateStr}
+            </if>
+
+            <if test="orderQueryVo.auditStartDateStr != null and orderQueryVo.auditEndDateStr != null">
+                and  DATE_FORMAT(iac.underwriting_time, '%Y-%m-%d') between #{orderQueryVo.auditStartDateStr} AND #{orderQueryVo.auditEndDateStr}
+            </if>
+            <if test="orderQueryVo.updateStartDateStr != null and orderQueryVo.updateEndDateStr != null">
+                and  DATE_FORMAT( iac.update_status_time, '%Y-%m-%d') between #{orderQueryVo.updateStartDateStr} AND #{orderQueryVo.updateEndDateStr}
+            </if>
+            <if test="orderQueryVo.updateStatus != null and orderQueryVo.updateStatus != null">
+                and  iac.update_status =  #{orderQueryVo.updateStatus}
+            </if>
+            <if test="orderQueryVo.partnerCompaniesId != null and orderQueryVo.partnerCompaniesId != null">
+                and  agree.partner_companies_id =  #{orderQueryVo.partnerCompaniesId}
+            </if>
+
+            and (io.del_flag = 0)
+        </where>
+        group by io.orderno,
+        iac.orderstatus,
+        iac.productid,
+        iac.product,
+        iac.jq_start_date,
+        iac.jq_end_date,
+        iac.sy_start_date,
+        iac.sy_end_date,
+        iac.jqpremium,
+        iac.sypremium,
+        iac.jypremium,
+        iac.taxamount,
+        iac.id,
+        d1.area_cname,
+        d2.area_cname,
+        d3.area_cname
         order by io.createtime desc
         order by io.createtime desc
+
     </select>
     </select>