Explorar el Código

1.控制台人员优化1.0

wuhp hace 2 años
padre
commit
5202ac89ad

+ 13 - 0
src/main/java/com/ydtech/modules/admin/controller/personnelStatistics/PersonnelStatisticsController.java

@@ -95,6 +95,19 @@ public class PersonnelStatisticsController {
         return result;
     }
 
+    /**
+     * @version
+     * @author: whp
+     * @Date: 2024/8/07
+     * @Description: 人员统计-前线人员-渠道-详情
+     */
+    @PostMapping("queryChannelDetails")
+    @ApiOperation(value = "人员统计-前线人员-渠道明细")
+    public HttpResult<List<QxFrontlineAgentDto>> queryChannelDetails(@RequestBody QxFrontlineAgentVo qxFrontlineAgentVo) {
+        HttpResult<List<QxFrontlineAgentDto>> result = userReportService.queryChannelDetails(qxFrontlineAgentVo);
+        return result;
+    }
+
     /**
      * @version
      * @author: whp

+ 11 - 0
src/main/java/com/ydtech/modules/admin/model/dto/QxFrontlineAgentDto.java

@@ -75,5 +75,16 @@ public class QxFrontlineAgentDto implements Serializable {
     private String  orderManpowerCompliance;
 
 
+    @ApiModelProperty(value = "用户idList")
+    private List<String>  ids;
+
+
+    @ApiModelProperty(value = "开始时间")
+    private String createtimeEnd;
+
+    @ApiModelProperty(value = "结束时间")
+    private String createtimeStart;
+
+
 }
 

+ 9 - 0
src/main/java/com/ydtech/modules/admin/model/vo/QxFrontlineAgentVo.java

@@ -62,4 +62,13 @@ public class QxFrontlineAgentVo implements Serializable {
     private String deptId;
 
 
+    @ApiModelProperty(value = "开始时间")
+    private String createtimeEnd;
+
+    @ApiModelProperty(value = "结束时间")
+    private String createtimeStart;
+
+
+
+
 }

+ 8 - 0
src/main/java/com/ydtech/modules/admin/service/UserReportService.java

@@ -98,6 +98,14 @@ public interface UserReportService {
     QxFrontlineAgentDto getByUserId(String userId);
 
     List<EsmUserReferrerDTO> agentTreeStructure(QxFrontlineAgentVo qxFrontlineAgentVo);
+    /**
+     * @version
+     * @author: whp
+     * @Date: 2024/8/07
+     * @Description: 人员统计-前线人员-渠道-详情
+     */
+    HttpResult<List<QxFrontlineAgentDto>> queryChannelDetails(QxFrontlineAgentVo qxFrontlineAgentVo);
+
 }
 
 

+ 11 - 3
src/main/java/com/ydtech/modules/admin/service/impl/TaskStatisticsServiceImpl.java

@@ -16,6 +16,7 @@ import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
 import com.ydtech.modules.order.dao.InsOrdersMapper;
 import com.ydtech.modules.order.entity.BasePageResult;
 import com.ydtech.modules.order.entity.InsAreaCompany;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -49,9 +50,12 @@ public class TaskStatisticsServiceImpl  implements TaskStatisticsService {
     public IPage<TaskStatisticsDto> queryPage(TaskStatisticsVo taskStatisticsVo) {
         PageVo<TaskStatisticsVo> pageVo = new PageVo<>();
         Page page = new Page(taskStatisticsVo.getPageNum(), taskStatisticsVo.getPageSize());
+        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
         pageVo.setPageNum(taskStatisticsVo.getPageNum());
         pageVo.setPageSize(taskStatisticsVo.getPageSize());
         IPage<TaskStatisticsDto> list = this.insAreaCompanyMapper.queryPageTaskStatistics(page,taskStatisticsVo);
+        Long  total  = this.insAreaCompanyMapper.queryPageTaskStatisticsTotal(taskStatisticsVo);
+        list.setTotal(total);
         return list;
     }
     /**
@@ -63,9 +67,12 @@ public class TaskStatisticsServiceImpl  implements TaskStatisticsService {
     public IPage<TaskStatisticsDto> insuranceCompanyQueryPage(TaskStatisticsVo taskStatisticsVo) {
         PageVo<TaskStatisticsVo> pageVo = new PageVo<>();
         Page page = new Page(taskStatisticsVo.getPageNum(), taskStatisticsVo.getPageSize());
+        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
         pageVo.setPageNum(taskStatisticsVo.getPageNum());
         pageVo.setPageSize(taskStatisticsVo.getPageSize());
         IPage<TaskStatisticsDto> list = this.insAreaCompanyMapper.insuranceCompanyQueryPage(page,taskStatisticsVo);
+        Long  total = this.insAreaCompanyMapper.insuranceCompanyQueryTotal(taskStatisticsVo);
+        list.setTotal(total);
         return list;
     }
     /**
@@ -136,11 +143,12 @@ public class TaskStatisticsServiceImpl  implements TaskStatisticsService {
         for (int i = 0; i < 5; i++) {
             taskStatisticsVo.setQuotationStatus(i+"");
             TaskStatisticsDto taskStatisticsDtoItem = insAreaCompanyMapper.getDistribution(taskStatisticsVo);
-            taskStatisticsDtoItem.setQuotationStatus(i+"");
-            result.add(taskStatisticsDtoItem);
+            if(ObjectUtils.isNotEmpty(taskStatisticsDtoItem)){
+                taskStatisticsDtoItem.setQuotationStatus(i+"");
+                result.add(taskStatisticsDtoItem);
+            }
         }
         return result;
     }
 
-
 }

+ 123 - 37
src/main/java/com/ydtech/modules/admin/service/impl/UserReportServiceImpl.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.admin.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.constants.enums.dict.DictionaryManagement;
@@ -9,8 +10,11 @@ import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.dao.SysDeptMapper;
 import com.ydtech.modules.admin.dao.SysUserMapper;
+import com.ydtech.modules.admin.dao.SysUserRoleMapper;
 import com.ydtech.modules.admin.model.SysDept;
 import com.ydtech.modules.admin.model.SysUser;
+import com.ydtech.modules.admin.model.SysUserRole;
+import com.ydtech.modules.admin.model.SysUserRoleKzt;
 import com.ydtech.modules.admin.model.dto.*;
 import com.ydtech.modules.admin.model.report.user.*;
 import com.ydtech.modules.admin.model.vo.HouLinePersonnelReportVo;
@@ -30,6 +34,7 @@ import com.ydtech.utils.StringUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.web.config.QuerydslWebConfiguration;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -62,6 +67,9 @@ public class UserReportServiceImpl implements UserReportService {
     @Autowired
     private InsAreaCompanyMapper insAreaCompanyMapper;
 
+    @Autowired
+    private SysUserRoleMapper  sysUserRoleMapper;
+
     /**
      *  @version
      *  @author: hxl
@@ -189,46 +197,14 @@ public class UserReportServiceImpl implements UserReportService {
         try {
             PageVo<SettlementDocumentaryFeesSumEntity> pageVo = new PageVo<>();
             Page page = new Page(qxFrontlineAgentVo.getPageNum(), qxFrontlineAgentVo.getPageSize());
-
             pageVo.setPageNum(qxFrontlineAgentVo.getPageNum());
             pageVo.setPageSize(qxFrontlineAgentVo.getPageSize());
-
-
             IPage<QxFrontlineAgentDto> sysUserListPage = sysUserMapper.queryQxFrontlineAgent(page, qxFrontlineAgentVo);
             List<QxFrontlineAgentDto> sysUserList = sysUserListPage.getRecords();
-
-            HashMap<String, Integer> humanResources = new HashMap<>();
-            HashMap<String, List<String>> humanResourcesIdList = new HashMap<>();
-
-//         关系表
-            List<EsmUserReferrerDTO> employeeIncreaseReportDtos = esmUserReferrerMapper.getbyUserNextLevel(null);
-            Map<String, EsmUserReferrerDTO> collect = employeeIncreaseReportDtos.stream().collect(Collectors.toMap(EsmUserReferrerDTO::getId, Function.identity()));
-            Set<String> visited = new HashSet<>();
-            for (EsmUserReferrerDTO item : employeeIncreaseReportDtos) {
-                Integer count = this.nextLevelUser(item.getId(), collect, visited);
-                humanResources.put(item.getId(), count);
-                List<String> ids = new ArrayList<>();
-                humanResourcesIdList.put(item.getId(), this.nextLevelUserList(item.getId(), collect, visited, ids));
-
-            }
-            for (QxFrontlineAgentDto userItem : sysUserList) {
-                String userId = userItem.getUserId();
-//            总人力
-                if (humanResources.containsKey(userId)) {
-                    if (ObjectUtils.isNotEmpty(humanResources.get(userId))) {
-                        userItem.setTotalManpower(humanResources.get(userId).toString());
-                    }
-                }
-                //出单人力 +  总保费  +单均保费
-                if (humanResourcesIdList.containsKey(userId)) {
-                        //出单人力
-                        List<String> ids = humanResourcesIdList.get(userId);
-                        ids.add(userId);
-                        QxFrontlineAgentDto orderManpower = insAreaCompanyService.getOrderManpower(ids);
-                        userItem.setOrderManpower(orderManpower.getOrderManpower());
-                        userItem.setTotalPremium(orderManpower.getTotalPremium());
-                        userItem.setAveragePremium(orderManpower.getAveragePremium());
-                }
+            if(qxFrontlineAgentVo.getManagementSource().equals("1")){// 渠道
+                this.channelPerson(sysUserList,qxFrontlineAgentVo);
+            }else if (qxFrontlineAgentVo.getManagementSource().equals("2")){// 代理人
+                this.agentPerson(sysUserList,qxFrontlineAgentVo);
             }
             return HttpResult.ok(sysUserListPage);
         } catch (Exception e) {
@@ -236,6 +212,75 @@ public class UserReportServiceImpl implements UserReportService {
             return HttpResult.error("查询异常");
         }
     }
+
+    private void agentPerson(List<QxFrontlineAgentDto> sysUserList,QxFrontlineAgentVo qxFrontlineAgentVo) {
+        HashMap<String, Integer> humanResources = new HashMap<>();
+        HashMap<String, List<String>> humanResourcesIdList = new HashMap<>();
+//              关系表
+        List<EsmUserReferrerDTO> employeeIncreaseReportDtos = esmUserReferrerMapper.getbyUserNextLevel(null);
+        Map<String, EsmUserReferrerDTO> collect = employeeIncreaseReportDtos.stream().collect(Collectors.toMap(EsmUserReferrerDTO::getId, Function.identity()));
+        Set<String> visited = new HashSet<>();
+        for (EsmUserReferrerDTO item : employeeIncreaseReportDtos) {
+            Integer count = this.nextLevelUser(item.getId(), collect, visited);
+            humanResources.put(item.getId(), count);
+            List<String> ids = new ArrayList<>();
+            humanResourcesIdList.put(item.getId(), this.nextLevelUserList(item.getId(), collect, visited, ids));
+        }
+        for (QxFrontlineAgentDto userItem : sysUserList) {
+            String userId = userItem.getUserId();
+//                  总人力
+            if (humanResources.containsKey(userId)) {
+                if (ObjectUtils.isNotEmpty(humanResources.get(userId))) {
+                    userItem.setTotalManpower(humanResources.get(userId).toString());
+                }
+            }
+            List<String> ids = new ArrayList<>();
+            //出单人力 +  总保费  +单均保费
+            if (humanResourcesIdList.containsKey(userId)) {
+                //出单人力
+                ids = humanResourcesIdList.get(userId);
+            }
+            ids.add(userId);
+            QxFrontlineAgentDto qxFrontlineAgentDto = new QxFrontlineAgentDto();
+            qxFrontlineAgentDto.setIds(ids);
+            qxFrontlineAgentDto.setCreatetimeStart(qxFrontlineAgentVo.getCreatetimeStart());
+            qxFrontlineAgentDto.setCreatetimeEnd(qxFrontlineAgentVo.getCreatetimeEnd());
+            QxFrontlineAgentDto orderManpower = insAreaCompanyService.getOrderManpowerNew(qxFrontlineAgentDto);
+            userItem.setOrderManpower(orderManpower.getOrderManpower());
+            userItem.setTotalPremium(orderManpower.getTotalPremium());
+            userItem.setAveragePremium(orderManpower.getAveragePremium());
+        }
+    }
+
+    /**
+     *   渠道统计
+     * @param sysUserList  渠道userIdS
+     */
+    private void channelPerson(List<QxFrontlineAgentDto> sysUserList,QxFrontlineAgentVo qxFrontlineAgentVo) {
+        for (QxFrontlineAgentDto  item  : sysUserList){
+//            是否是团队长
+            String userId = item.getUserId();
+            QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("user_id",userId);
+            SysUserRole sysUserRole = sysUserRoleMapper.selectOne(queryWrapper);
+            if(ObjectUtils.isNotEmpty(sysUserRole) && StringUtils.isNotEmpty(sysUserRole.getRoleId().toString()) && "21".equals(sysUserRole.getRoleId().toString())){//团队长
+                QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
+                wrapper.eq("operatorCode", userId);
+                wrapper.eq("status", "1");
+                List<SysUser> sysUsers = sysUserMapper.selectList(wrapper);
+                if (!sysUsers.isEmpty()) {
+                    List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
+                    QxFrontlineAgentDto qxFrontlineAgentDto = new QxFrontlineAgentDto();
+                    qxFrontlineAgentDto.setCreatetimeEnd(qxFrontlineAgentVo.getCreatetimeEnd());
+                    qxFrontlineAgentDto.setCreatetimeStart(qxFrontlineAgentVo.getCreatetimeStart());
+                    qxFrontlineAgentDto.getIds().addAll(collect);
+                    QxFrontlineAgentDto taskStatisticsDto = insAreaCompanyMapper.getOrderManpowerNew(qxFrontlineAgentDto);
+                    item.setTotalPremium(taskStatisticsDto.getTotalPremium());
+                }
+            }
+        }
+    }
+
     /**
      *  @version
      *  @author: whp
@@ -670,11 +715,52 @@ public class UserReportServiceImpl implements UserReportService {
         List<EsmUserReferrerDTO> esmUserReferrerDTOList = this.buildUserTree(employeeIncreaseReportDtos);
         return esmUserReferrerDTOList;
     }
+    /**
+     * @version
+     * @author: whp
+     * @Date: 2024/8/07
+     * @Description: 人员统计-前线人员-渠道-详情
+     */
+    @Override
+    public HttpResult<List<QxFrontlineAgentDto>> queryChannelDetails(QxFrontlineAgentVo qxFrontlineAgentVo) {
+        List<QxFrontlineAgentDto> resultList = new ArrayList<>();
+        String userId = qxFrontlineAgentVo.getUserId();
+//        SysUser sysUserItem = sysUserMapper.getByUserId(userId);
+//        if(sysUserItem.getManagementSource().equals("2")){  //2为代理人
+//            return HttpResult.error("该用户不是渠道");
+//        }
+//      判断是否是团队长
+        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", userId);
+        SysUserRole sysUserRole = sysUserRoleMapper.selectOne(queryWrapper);
+        if (ObjectUtils.isNotEmpty(sysUserRole) && StringUtils.isNotEmpty(sysUserRole.getRoleId().toString()) && "21".equals(sysUserRole.getRoleId().toString())) { //负责人
+            QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
+            wrapper.eq("operatorCode", userId);
+            wrapper.eq("status", "1");
+            List<SysUser> sysUsers = sysUserMapper.selectList(wrapper);
+            if (!sysUsers.isEmpty()) {
+                for (SysUser  itemUser  :sysUsers){
+                    QxFrontlineAgentDto qxFrontlineAgentDto = new QxFrontlineAgentDto();
+                    qxFrontlineAgentDto.setCreatetimeEnd(qxFrontlineAgentVo.getCreatetimeEnd());
+                    qxFrontlineAgentDto.setCreatetimeStart(qxFrontlineAgentVo.getCreatetimeStart());
+                    qxFrontlineAgentDto.getIds().add(itemUser.getId());
+                    QxFrontlineAgentDto taskStatisticsDto = insAreaCompanyMapper.getOrderManpowerNew(qxFrontlineAgentDto);
+                    resultList.add(taskStatisticsDto);
+                }
+            }
+        }
+        QxFrontlineAgentDto qxFrontlineAgentDto = new QxFrontlineAgentDto();
+        qxFrontlineAgentDto.setCreatetimeEnd(qxFrontlineAgentVo.getCreatetimeEnd());
+        qxFrontlineAgentDto.setCreatetimeStart(qxFrontlineAgentVo.getCreatetimeStart());
+        qxFrontlineAgentDto.getIds().add(userId);
+        QxFrontlineAgentDto taskStatisticsDto = insAreaCompanyMapper.getOrderManpowerNew(qxFrontlineAgentDto);
+        resultList.add(taskStatisticsDto);
+        return HttpResult.ok(resultList);
+    }
 
     /**
      * 递归构建树形结构
      * @param employeeIncreaseReportDtos 所有的用户数据list
-     * @param rootUser 用户对象
      * @return
      */
     private List<EsmUserReferrerDTO> buildUserTree(List<EsmUserReferrerDTO> employeeIncreaseReportDtos) {

+ 7 - 0
src/main/java/com/ydtech/modules/order/dao/InsAreaCompanyMapper.java

@@ -233,6 +233,13 @@ public interface InsAreaCompanyMapper extends BaseMapper<InsAreaCompany> {
     TaskStatisticsDto getDistribution(@Param("vo")  TaskStatisticsVo taskStatisticsVo);
 
 
+    Long insuranceCompanyQueryTotal(@Param("taskStatisticsVo") TaskStatisticsVo taskStatisticsVo);
+
+    Long queryPageTaskStatisticsTotal(@Param("taskStatisticsVo") TaskStatisticsVo taskStatisticsVo);
+
+    QxFrontlineAgentDto getOrderManpowerNew( @Param("vo") QxFrontlineAgentDto qxFrontlineAgentDto);
+
+
 }
 
 

+ 4 - 0
src/main/java/com/ydtech/modules/order/service/InsAreaCompanyService.java

@@ -11,6 +11,7 @@ import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.entity.dto.InsAreaCompanyQueryDto;
 import com.ydtech.modules.order.entity.vo.*;
 import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
+import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -180,4 +181,7 @@ public interface InsAreaCompanyService extends IService<InsAreaCompany> {
     QxFrontlineAgentDto getOrderManpower(List<String> ids);
 
     QxFrontlineAgentDto getOrderManpowerByUserId(String id);
+
+    QxFrontlineAgentDto getOrderManpowerNew(@Param("vo") QxFrontlineAgentDto qxFrontlineAgentDto);
+
 }

+ 6 - 0
src/main/java/com/ydtech/modules/order/service/impl/InsAreaCompanyServiceImpl.java

@@ -965,6 +965,12 @@ public class InsAreaCompanyServiceImpl extends ServiceImpl<InsAreaCompanyMapper,
         return  baseMapper.getOrderManpowerByUserId(id);
     }
 
+    @Override
+    public QxFrontlineAgentDto getOrderManpowerNew(QxFrontlineAgentDto qxFrontlineAgentDto) {
+        return baseMapper.getOrderManpowerNew(qxFrontlineAgentDto);
+
+    }
+
 }
 
 

+ 5 - 5
src/main/resources/mapper/modules/admin/SysUserMapper.xml

@@ -1311,8 +1311,7 @@
                 LEFT JOIN sys_user_info info ON info.id = su.id
         <where>
             info.id is not  null
-            and su.id  LIKE '%M%'
-            and su.status = '1'
+            and su.id   NOT LIKE '%M%'
             <if test="vo.provinceId != null and vo.provinceId != ''">
                 and sd.id like  concat('%',#{vo.provinceId},'%')
             </if>
@@ -1390,9 +1389,10 @@
     </select>
 
     <select id="getByUserId" resultType="com.ydtech.modules.admin.model.SysUser">
-        select t.id id,t.name name,t.mobile mobile,t2.management_source managementSource
-        from sys_user t left join sys_dept t2 on t.dept_id=t2.id
-        where t.id=#{id}
+        select t.id id, t.name name, t.mobile mobile, t2.management_source managementSource,t.operatorCode
+        from sys_user t
+                 left join sys_dept t2 on t.dept_id = t2.id
+        where t.id = #{id}
     </select>
 
     <select id="findByReferrerId" resultType="com.ydtech.modules.admin.model.vo.SysUserVO">

+ 240 - 100
src/main/resources/mapper/modules/order/InsAreaCompanyMapper.xml

@@ -918,69 +918,126 @@
     </select>
 
     <select id="queryPageTaskStatistics"  resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
+        select a.*,(select name  from sys_user  where id =a.userId) as "userName"
+        from (
         SELECT
-            sd.name as "deptName",
-            su.name as "userName",
-            io.userid as "userId",
-            COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
-            COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
-            COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
-            COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
-            COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END )  /  COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "passingRate",
-            COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )  /  COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )  as "closeRate",
-            COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )   /  COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END )  as  "contributionRate",
-            COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )  /  COUNT(iac.orderstatus)  as "quotationRate",
-            COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END  )   as  "auditOrder"
-            FROM
-            ins_area_company iac
-            left  join   ins_orders  io  on  io.orderno  = iac.orderno
-            left  join   sys_dept sd  on sd.id=io.deptid
-            left  join   sys_user su  on su.id=io.userid
-            left  join   ins_fee_audit   ifa   on ifa .ins_order_no  =iac.id
-            <where>
-                sd.management_source = '1'
-                <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
-                    and io.deptid like "${taskStatisticsVo.provinceId}%"
-                </if>
-                <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
-                    and io.deptid like "${taskStatisticsVo.cityId}%"
-                </if>
-                <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
-                    and io.deptid like "${taskStatisticsVo.countyId}%"
-                </if>
-                <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
-                    and io.deptid like "${taskStatisticsVo.houseId}%"
-                </if>
-
-                <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
-                    AND   DATE_FORMAT( io.createtime, '%Y-%m-%d')   BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
-                </if>
-
-                <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
-                    <choose>
-                        <when test="taskStatisticsVo.days =='1'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
-                        </when>
-
-                        <when test="taskStatisticsVo.days =='7'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
-                        </when>
-
-                        <when test="taskStatisticsVo.days =='30'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
-                        </when>
-                    </choose>
-                </if>
-            </where>
-            GROUP BY io.userid , su.name, sd.id , sd.name
+        sd.NAME AS "deptName",
+        io.userid AS "userId",
+        COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
+        COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
+        COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
+        COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
+        COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
+        COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
+        COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS "contributionRate",
+        COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
+        COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) AS "auditOrder"
+        FROM
+        ins_area_company iac
+        LEFT JOIN ins_orders io ON io.orderno = iac.orderno
+        LEFT JOIN sys_dept sd ON sd.id = io.deptid
+        LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
+        <where>
+            sd.management_source = '1'
+            <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
+                and io.deptid like "${taskStatisticsVo.provinceId}%"
+            </if>
+            <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
+                and io.deptid like "${taskStatisticsVo.cityId}%"
+            </if>
+            <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
+                and io.deptid like "${taskStatisticsVo.countyId}%"
+            </if>
+            <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
+                and io.deptid like "${taskStatisticsVo.houseId}%"
+            </if>
+
+            <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
+                AND   DATE_FORMAT( io.createtime, '%Y-%m-%d')   BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
+            </if>
+
+            <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
+                <choose>
+                    <when test="taskStatisticsVo.days =='1'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='7'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='30'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
+                    </when>
+                </choose>
+            </if>
+        </where>
+        GROUP BY
+        io.userid,
+        sd.NAME
+        ) a
     </select>
+    <select id="queryPageTaskStatisticsTotal"  resultType="java.lang.Long">
+        select count(0) from (
+        SELECT
+        io.userid
+        FROM
+        ins_area_company iac
+        LEFT JOIN ins_orders io ON io.orderno = iac.orderno
+        LEFT JOIN sys_dept sd ON sd.id = io.deptid
+        <where>
+            sd.management_source = '1'
+            <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
+                and io.deptid like "${taskStatisticsVo.provinceId}%"
+            </if>
+            <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
+                and io.deptid like "${taskStatisticsVo.cityId}%"
+            </if>
+            <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
+                and io.deptid like "${taskStatisticsVo.countyId}%"
+            </if>
+            <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
+                and io.deptid like "${taskStatisticsVo.houseId}%"
+            </if>
+
+            <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
+                AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND
+                #{taskStatisticsVo.createtimeEnd}
+            </if>
+
+            <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
+                <choose>
+                    <when test="taskStatisticsVo.days =='1'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='7'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='30'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
+                    </when>
+                </choose>
+            </if>
+        </where>
+        GROUP BY
+        io.userid
+        ) a
+    </select>
+
 
 
     <select id="insuranceCompanyQueryPage"  resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
+        SELECT
+        a.*,
+        ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "namesimple"
+        FROM
+        (
         SELECT
         pa.insurance_company_id,
-        pa.insurance_company as "insuranceCompanyName",
-        eic.namesimple as "partnerCompaniesName",
+        pa.partner_companies_id,
+        pa.insurance_company AS "insuranceCompanyName",
         COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
         COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
         COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
@@ -992,50 +1049,99 @@
         COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) AS "auditOrder"
         FROM
         ins_area_company iac
-        LEFT JOIN ins_orders io ON io.orderno = iac.orderno
-        LEFT JOIN sys_dept sd ON sd.id = io.deptid
         LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
         LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
-        LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
-            <where>
-                pa.insurance_company_id IS NOT NULL
-                <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
-                    and io.deptid like "${taskStatisticsVo.provinceId}%"
-                </if>
-                <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
-                    and io.deptid like "${taskStatisticsVo.cityId}%"
-                </if>
-                <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
-                    and io.deptid like "${taskStatisticsVo.countyId}%"
-                </if>
-                <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
-                    and io.deptid like "${taskStatisticsVo.houseId}%"
-                </if>
-                <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
-                    AND   DATE_FORMAT( io.createtime, '%Y-%m-%d')   BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
-                </if>
-
-                <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
-                    <choose>
-                        <when test="taskStatisticsVo.days =='1'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
-                        </when>
-
-                        <when test="taskStatisticsVo.days =='7'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
-                        </when>
-
-                        <when test="taskStatisticsVo.days =='30'">
-                            and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
-                        </when>
-                    </choose>
-                </if>
-            </where>
-            GROUP BY
-            pa.insurance_company_id,
-            pa.insurance_company,
-            eic.namesimple,
-            pa.insurance_company
+        <where>
+            pa.insurance_company_id IS NOT NULL
+            <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
+                and io.deptid like "${taskStatisticsVo.provinceId}%"
+            </if>
+            <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
+                and io.deptid like "${taskStatisticsVo.cityId}%"
+            </if>
+            <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
+                and io.deptid like "${taskStatisticsVo.countyId}%"
+            </if>
+            <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
+                and io.deptid like "${taskStatisticsVo.houseId}%"
+            </if>
+            <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
+                AND   DATE_FORMAT( io.createtime, '%Y-%m-%d')   BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
+            </if>
+
+            <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
+                <choose>
+                    <when test="taskStatisticsVo.days =='1'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='7'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='30'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
+                    </when>
+                </choose>
+            </if>
+        </where>
+        GROUP BY
+        pa.insurance_company_id,
+        pa.partner_companies_id,
+        pa.insurance_company
+        ) a
+    </select>
+
+    <select id="insuranceCompanyQueryTotal"  resultType="java.lang.Long">
+        SELECT
+        COUNT(0)
+        FROM
+        (
+        SELECT
+        pa.insurance_company_id,
+        pa.partner_companies_id
+        FROM
+        ins_area_company iac
+        LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
+        LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
+        <where>
+            pa.insurance_company_id IS NOT NULL
+            <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
+                and io.deptid like "${taskStatisticsVo.provinceId}%"
+            </if>
+            <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
+                and io.deptid like "${taskStatisticsVo.cityId}%"
+            </if>
+            <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
+                and io.deptid like "${taskStatisticsVo.countyId}%"
+            </if>
+            <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
+                and io.deptid like "${taskStatisticsVo.houseId}%"
+            </if>
+            <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
+                AND   DATE_FORMAT( io.createtime, '%Y-%m-%d')   BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
+            </if>
+
+            <if test="taskStatisticsVo.days !=null  and taskStatisticsVo.days !='' ">
+                <choose>
+                    <when test="taskStatisticsVo.days =='1'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='7'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+                    </when>
+
+                    <when test="taskStatisticsVo.days =='30'">
+                        and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
+                    </when>
+                </choose>
+            </if>
+        </where>
+        GROUP BY
+        pa.insurance_company_id,
+        pa.partner_companies_id
+        ) total
     </select>
 
     <select id="agentStatisticsQueryPage"  resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
@@ -1151,7 +1257,9 @@
         (
         SELECT
         count( io.userid ) AS "numberUserId",
-        sum( iac.sumpremium ) AS "orderAmount"
+        SUM(IFNULL(iac.jqpremium, 0)) +
+        SUM(IFNULL(iac.sypremium, 0)) +
+        SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
         FROM
         `ins_area_company` iac
         LEFT JOIN ins_orders io ON io.orderno = iac.orderno
@@ -1169,6 +1277,38 @@
         ) a
     </select>
 
+    <select id="getOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
+        SELECT
+        count( a.numberUserId ) as "orderManpower",
+        sum( a.orderAmount ) as "totalPremium",
+        sum( a.orderAmount )/  count( a.numberUserId ) as "averagePremium"
+        FROM
+        (
+        SELECT
+        count( io.userid ) AS "numberUserId",
+        SUM(IFNULL(iac.jqpremium, 0)) +
+        SUM(IFNULL(iac.sypremium, 0)) +
+        SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
+        FROM
+        `ins_area_company` iac
+        LEFT JOIN ins_orders io ON io.orderno = iac.orderno
+        <where>
+            iac.orderstatus = '3'
+            <if test="vo.ids  != null  and  vo.ids.size()>0 ">
+                AND io.userid IN
+                <foreach item="item"  collection="vo.ids" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="vo.createtimeStart  != null  and  vo.createtimeStart!=''  and vo.createtimeEnd  != null  and  vo.createtimeEnd!=''">
+                AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
+            </if>
+        </where>
+        GROUP BY
+        io.userid
+        ) a
+    </select>
+
 
     <select id="NumberQuotations"  resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
         SELECT
@@ -1189,6 +1329,7 @@
             </if>
         </where>
     </select>
+
     <select id="totalQuotation" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
         SELECT
         agree.insurance_company_id AS companyId,
@@ -1365,5 +1506,4 @@
         agree.partner_companies_id,
         ins.namesimple
     </select>
-
 </mapper>