EsmUserReferrerMapper.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. package com.ydtech.modules.esm.dao;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.ydtech.modules.admin.model.SysUser;
  5. import com.ydtech.modules.admin.model.dto.*;
  6. import com.ydtech.modules.admin.model.vo.AppCustomerManagementQueryVo;
  7. import com.ydtech.modules.admin.model.vo.QxFrontlineAgentVo;
  8. import com.ydtech.modules.admin.model.vo.SysReferrerVo;
  9. import com.ydtech.modules.base.model.dto.PageDto;
  10. import com.ydtech.modules.esm.model.EsmUserReferrer;
  11. import com.ydtech.modules.esm.model.QueryChannel;
  12. import com.ydtech.modules.esm.model.vo.EsmTeamPolicyVO;
  13. import com.ydtech.modules.esm.model.vo.EsmUserPolicyForUserVO;
  14. import com.ydtech.modules.esm.model.vo.EsmUserPolicyVO;
  15. import org.apache.ibatis.annotations.Param;
  16. import org.apache.ibatis.annotations.Select;
  17. import org.springframework.stereotype.Repository;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. @Repository
  21. public interface EsmUserReferrerMapper extends BaseMapper<EsmUserReferrer> {
  22. String referrerFieldSql = "select " +
  23. " org.id as orgId" +
  24. ",org.name as orgName" +
  25. ",d.name as deptName" +
  26. ",d.id as deptId" +
  27. ",u.id as userId" +
  28. ",u.name as userName" +
  29. ",u.mobile as userMobile" +
  30. ",ui.sex as userSex" +
  31. ",t.level as level" +
  32. ",t.referrer_id as referrerId" +
  33. ",t.referrer_name as referrerName" +
  34. ",t.affiliation"
  35. ;
  36. String referrerFromSql =
  37. " from esm_user_referrer t " +
  38. " left join sys_user u on t.id = u.id" +
  39. " left join sys_user_info ui on u.id = ui.id" +
  40. " left join (select name,id from sys_dept where inSTR(id,'D')) d on d.id = u.dept_id" +
  41. " left join (select name,id from sys_dept where !inSTR(id,'D')) org on org.id = substring_index(u.dept_id,'D',1)" +
  42. " where 1=1 "
  43. ;
  44. String referrerWhereSql = "" +
  45. "<if test='page.dto !=null '> " +
  46. "<if test='page.dto.affiliation !=null and page.dto.affiliation!=\"\" '> " +
  47. " and t.affiliation = #{page.dto.affiliation}" +
  48. "</if> " +
  49. "<if test='page.dto.ids !=null '> " +
  50. "and t.id in "+
  51. "<foreach item='item' index='index' collection='page.dto.ids' open='(' separator=',' close=')'> " +
  52. " #{item}" +
  53. "</foreach > " +
  54. "</if> " +
  55. "</if> "
  56. ;
  57. String referrerOrderSql = "" +
  58. " ORDER BY t.level "
  59. ;
  60. // String referrerSql = "select org.id as orgId,org.name as orgName,d.name as deptName,d.id as deptId,u.id,u.name,u.mobile,ui.sex ,t.affiliation" +
  61. // " from esm_user_referrer t " +
  62. // " left join sys_user u on t.id = u.id" +
  63. // " left join sys_user_info ui on u.id = ui.id" +
  64. // " left join (select name,id from sys_dept where inSTR(id,'D')) d on d.id = u.dept_id" +
  65. // " left join (select name,id from sys_dept where !inSTR(id,'D')) org on org.id = substring_index(u.dept_id,'D',1)" +
  66. // " where t.affiliation=#{affiliation} "
  67. // ;
  68. @Select({"<script>",
  69. "select * from (",
  70. referrerFieldSql,
  71. referrerFromSql,
  72. referrerWhereSql,
  73. referrerOrderSql,
  74. // referrerOrderSql,
  75. " limit #{page.pageNum},#{page.pageSize} ) aaa",
  76. "</script>"})
  77. List<SysReferrerVo> selectReferrerByAffiliation(@Param("page") PageDto pageDto);
  78. /**
  79. * 向下三级
  80. * @param userId
  81. * @return
  82. */
  83. @Select("select a.id " +
  84. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  85. "where a.referrer_id=#{userId} and a.id!= #{userId} and b.status=1 " +
  86. "union " +
  87. "select a.id " +
  88. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  89. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId}) " +
  90. "and b.status=1 "
  91. /* +"union " +
  92. "select a.id " +
  93. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  94. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id in ( " +
  95. "select id from esm_user_referrer t2 where t2.referrer_id=#{userId} and t2.id!= #{userId})) " +
  96. "and b.status=1 "*/
  97. )
  98. List<String> getIdDown3(@Param("userId") String userId);
  99. /**
  100. * 向下三级--新注册人员(审批中)
  101. * @param userId
  102. * @return
  103. */
  104. @Select("select a.id " +
  105. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  106. "where a.referrer_id=#{userId} and a.id!= #{userId} and b.status=2 " +
  107. "union " +
  108. "select a.id " +
  109. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  110. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId}) " +
  111. "and b.status=2 " )
  112. List<String> getIdDown3_regist(@Param("userId") String userId);
  113. /**
  114. * 向下第1级
  115. * @param userId
  116. * @return
  117. */
  118. @Select("select a.id " +
  119. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  120. "where a.referrer_id=#{userId} and a.id!= #{userId} "+
  121. "and b.status in ('0','1') "
  122. )
  123. List<String> getIdDown_1(@Param("userId") String userId);
  124. /**
  125. * 向下第2级
  126. * @param userId
  127. * @return
  128. */
  129. @Select( "select a.id " +
  130. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  131. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId} ) "+
  132. "and b.status in ('0','1') "
  133. )
  134. List<String> getIdDown_2(@Param("userId") String userId);
  135. /**
  136. * 向下第3级
  137. * @param userId
  138. * @return
  139. */
  140. @Select( "select a.id " +
  141. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  142. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id in ( " +
  143. "select id from esm_user_referrer t2 where t2.referrer_id=#{userId} and t2.id!= #{userId} )) "+
  144. "and b.status in ('0','1') "
  145. )
  146. List<String> getIdDown_3(@Param("userId") String userId);
  147. @Select({"<script>", "select count(1) ", referrerFromSql,referrerWhereSql, "</script>"})
  148. int countReferrerByAffiliation(@Param("page") PageDto pageDto);
  149. @Select("select id,referrer_id,referrer_name,`level`,affiliation from esm_user_referrer t where t.affiliation=#{affiliation}")
  150. List<EsmUserReferrer> queryList(@Param("affiliation") String affiliation);
  151. // @Select({"<script>","select a.userid,a.username,sum(a.ordernum) ordernum,sum(a.policynum) policynum,sum(a.sumpremium) sumpremium from v_user_order2 a " +
  152. // "where DATE_FORMAT(orderdate, '%Y-%m-%d') " +
  153. // "between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')" +
  154. // "and userid in " +
  155. // "<foreach item='item' index='index' collection='userList' open='(' separator=',' close=')'> " +
  156. // " #{item}" +
  157. // "</foreach > " +
  158. // "group by a.userid,a.username"
  159. // , "</script>"})
  160. List<EsmUserPolicyVO> queryOrderCount(List<String> userList, String startDate, String endDate);
  161. // @Select({"<script>","select sum(sumpremium) sumpremium " +
  162. // "from v_user_order2 a " +
  163. // "where DATE_FORMAT(orderdate, '%Y-%m-%d') " +
  164. // "between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')" +
  165. // "and userid in " +
  166. // "<foreach item='item' index='index' collection='userList' open='(' separator=',' close=')'> " +
  167. // " #{item}" +
  168. // "</foreach > "
  169. // , "</script>"})
  170. // EsmTeamPolicyVO queryOrderCountHz(List<String> userList, String startDate, String endDate);
  171. EsmTeamPolicyVO queryOrderCountHz(List<String> userList, String startDate, String endDate);
  172. Page<SysUser> getUserPage(Page page, SysUserDto dto);
  173. Page<QueryChannel> getQueryChannelPage(Page page, QueryChannel queryChannel);
  174. List<SysUserTeamDto> getByTeam(@Param("managementQueryVo") AppCustomerManagementQueryVo managementQueryVo, @Param("userId") String userId, @Param("level") int level);
  175. /**
  176. * @version
  177. * @author: hxl
  178. * @Date: 2024/6/5 18:10
  179. * @Description: 查询年分数据
  180. */
  181. List<EmployeeIncreaseReportDto> employeeIncreaseReportYear(HashMap<String,Object> map);
  182. /**
  183. * @version
  184. * @author: hxl
  185. * @Date: 2024/6/5 18:15
  186. * @Description: 查询月分数据
  187. */
  188. List<EmployeeIncreaseReportDto> employeeIncreaseReportMonth(HashMap<String,Object> map);
  189. /**
  190. * @version
  191. * @author: hxl
  192. * @Date: 2024/6/5 18:16
  193. * @Description: 查询天数数据
  194. */
  195. List<EmployeeIncreaseReportDto> employeeIncreaseReportDay(HashMap<String,Object> map);
  196. /**
  197. * 团队业绩统计
  198. * @param userId 用户id
  199. * @param startDate 开始时间
  200. * @param endDate 结束时间
  201. * @return
  202. */
  203. List<EsmUserPolicyForUserVO> queryOrderCountForUser(String userId,String startDate, String endDate);
  204. List<EsmUserReferrerDTO> getbyUserNextLevel(String userId);
  205. /**
  206. *
  207. * @param ids 下级ids
  208. * @return 返回 用户id 和用户级别
  209. */
  210. List<EsmUserReferrerDTO> getUserLevel(@Param("vo") QxFrontlineAgentVo qxFrontlineAgentVo);
  211. EsmTeamPolicyVO queryOrderCountHzNew(List<String> userList, String startDate, String endDate);
  212. /**
  213. * @version
  214. * @author: hxl
  215. * @Date: 2024/8/29 19:22
  216. * @Description: 通过代理人查询下级的所有代理人信息
  217. */
  218. List<SysUserTeamDto> getUserIdsByUserId(@Param("userId") String userId);
  219. /**
  220. * @version
  221. * @author: hxl
  222. * @Date: 2024/8/29 19:22
  223. * @Description: 通过代理人 层级、认证和未认证 信息查询 查询下级的所有代理人信息
  224. */
  225. List<SysUserTeamDto> getByTeamByLevel(@Param("userId") String userId,@Param("level") String level,@Param("status") String status);
  226. /**
  227. * 个代当天认证统计
  228. * @param userId
  229. * @param level
  230. * @param startDate
  231. * @param endDate
  232. * @return
  233. */
  234. List<SysUserTeamStaticDto> authNowStatics(@Param("userId")String userId, @Param("level")int level, @Param("startDate")String startDate, @Param("endDate")String endDate);
  235. /**
  236. * 个代七天认证统计
  237. *
  238. * @param userId
  239. * @param level
  240. * @param startDate
  241. * @param endDate
  242. * @return
  243. */
  244. List<SysUserTeamStaticDto> authSevenStatics(@Param("userId")String userId, @Param("level")int level, @Param("startDate")String startDate, @Param("endDate")String endDate);
  245. /**
  246. * 个代三十天认证统计
  247. * @param userId
  248. * @param level
  249. * @param startDate
  250. * @param endDate
  251. * @return
  252. */
  253. List<SysUserTeamStaticDto> authThreeStatics(@Param("userId")String userId, @Param("level")int level, @Param("startDate")String startDate, @Param("endDate")String endDate);
  254. /**
  255. * 个代总数统计
  256. * @param userId
  257. * @param level
  258. * @return
  259. */
  260. List<SysUserTeamStaticDto> authStatics(@Param("userId")String userId, @Param("level")int level);
  261. }