EsmUserReferrerMapper.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.EmployeeIncreaseReportDto;
  6. import com.ydtech.modules.admin.model.dto.EsmUserReferrerDTO;
  7. import com.ydtech.modules.admin.model.dto.SysUserDto;
  8. import com.ydtech.modules.admin.model.dto.SysUserTeamDto;
  9. import com.ydtech.modules.admin.model.vo.AppCustomerManagementQueryVo;
  10. import com.ydtech.modules.admin.model.vo.QxFrontlineAgentVo;
  11. import com.ydtech.modules.admin.model.vo.SysReferrerVo;
  12. import com.ydtech.modules.base.model.dto.PageDto;
  13. import com.ydtech.modules.esm.model.EsmUserReferrer;
  14. import com.ydtech.modules.esm.model.QueryChannel;
  15. import com.ydtech.modules.esm.model.vo.EsmTeamPolicyVO;
  16. import com.ydtech.modules.esm.model.vo.EsmUserPolicyForUserVO;
  17. import com.ydtech.modules.esm.model.vo.EsmUserPolicyVO;
  18. import org.apache.ibatis.annotations.Param;
  19. import org.apache.ibatis.annotations.Select;
  20. import org.springframework.stereotype.Repository;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. @Repository
  24. public interface EsmUserReferrerMapper extends BaseMapper<EsmUserReferrer> {
  25. String referrerFieldSql = "select " +
  26. " org.id as orgId" +
  27. ",org.name as orgName" +
  28. ",d.name as deptName" +
  29. ",d.id as deptId" +
  30. ",u.id as userId" +
  31. ",u.name as userName" +
  32. ",u.mobile as userMobile" +
  33. ",ui.sex as userSex" +
  34. ",t.level as level" +
  35. ",t.referrer_id as referrerId" +
  36. ",t.referrer_name as referrerName" +
  37. ",t.affiliation"
  38. ;
  39. String referrerFromSql =
  40. " from esm_user_referrer t " +
  41. " left join sys_user u on t.id = u.id" +
  42. " left join sys_user_info ui on u.id = ui.id" +
  43. " left join (select name,id from sys_dept where inSTR(id,'D')) d on d.id = u.dept_id" +
  44. " left join (select name,id from sys_dept where !inSTR(id,'D')) org on org.id = substring_index(u.dept_id,'D',1)" +
  45. " where 1=1 "
  46. ;
  47. String referrerWhereSql = "" +
  48. "<if test='page.dto !=null '> " +
  49. "<if test='page.dto.affiliation !=null and page.dto.affiliation!=\"\" '> " +
  50. " and t.affiliation = #{page.dto.affiliation}" +
  51. "</if> " +
  52. "<if test='page.dto.ids !=null '> " +
  53. "and t.id in "+
  54. "<foreach item='item' index='index' collection='page.dto.ids' open='(' separator=',' close=')'> " +
  55. " #{item}" +
  56. "</foreach > " +
  57. "</if> " +
  58. "</if> "
  59. ;
  60. String referrerOrderSql = "" +
  61. " ORDER BY t.level "
  62. ;
  63. // 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" +
  64. // " from esm_user_referrer t " +
  65. // " left join sys_user u on t.id = u.id" +
  66. // " left join sys_user_info ui on u.id = ui.id" +
  67. // " left join (select name,id from sys_dept where inSTR(id,'D')) d on d.id = u.dept_id" +
  68. // " left join (select name,id from sys_dept where !inSTR(id,'D')) org on org.id = substring_index(u.dept_id,'D',1)" +
  69. // " where t.affiliation=#{affiliation} "
  70. // ;
  71. @Select({"<script>",
  72. "select * from (",
  73. referrerFieldSql,
  74. referrerFromSql,
  75. referrerWhereSql,
  76. referrerOrderSql,
  77. // referrerOrderSql,
  78. " limit #{page.pageNum},#{page.pageSize} ) aaa",
  79. "</script>"})
  80. List<SysReferrerVo> selectReferrerByAffiliation(@Param("page") PageDto pageDto);
  81. /**
  82. * 向下三级
  83. * @param userId
  84. * @return
  85. */
  86. @Select("select a.id " +
  87. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  88. "where a.referrer_id=#{userId} and a.id!= #{userId} and b.status=1 " +
  89. "union " +
  90. "select a.id " +
  91. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  92. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId}) " +
  93. "and b.status=1 "
  94. /* +"union " +
  95. "select a.id " +
  96. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  97. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id in ( " +
  98. "select id from esm_user_referrer t2 where t2.referrer_id=#{userId} and t2.id!= #{userId})) " +
  99. "and b.status=1 "*/
  100. )
  101. List<String> getIdDown3(@Param("userId") String userId);
  102. /**
  103. * 向下三级--新注册人员(审批中)
  104. * @param userId
  105. * @return
  106. */
  107. @Select("select a.id " +
  108. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  109. "where a.referrer_id=#{userId} and a.id!= #{userId} and b.status=2 " +
  110. "union " +
  111. "select a.id " +
  112. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  113. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId}) " +
  114. "and b.status=2 " )
  115. List<String> getIdDown3_regist(@Param("userId") String userId);
  116. /**
  117. * 向下第1级
  118. * @param userId
  119. * @return
  120. */
  121. @Select("select a.id " +
  122. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  123. "where a.referrer_id=#{userId} and a.id!= #{userId} "+
  124. "and b.status in ('0','1') "
  125. )
  126. List<String> getIdDown_1(@Param("userId") String userId);
  127. /**
  128. * 向下第2级
  129. * @param userId
  130. * @return
  131. */
  132. @Select( "select a.id " +
  133. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  134. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id=#{userId} and t.id!= #{userId} ) "+
  135. "and b.status in ('0','1') "
  136. )
  137. List<String> getIdDown_2(@Param("userId") String userId);
  138. /**
  139. * 向下第3级
  140. * @param userId
  141. * @return
  142. */
  143. @Select( "select a.id " +
  144. "from esm_user_referrer a left join sys_user b on a.id=b.id " +
  145. "where a.referrer_id in (select id from esm_user_referrer t where t.referrer_id in ( " +
  146. "select id from esm_user_referrer t2 where t2.referrer_id=#{userId} and t2.id!= #{userId} )) "+
  147. "and b.status in ('0','1') "
  148. )
  149. List<String> getIdDown_3(@Param("userId") String userId);
  150. @Select({"<script>", "select count(1) ", referrerFromSql,referrerWhereSql, "</script>"})
  151. int countReferrerByAffiliation(@Param("page") PageDto pageDto);
  152. @Select("select id,referrer_id,referrer_name,`level`,affiliation from esm_user_referrer t where t.affiliation=#{affiliation}")
  153. List<EsmUserReferrer> queryList(@Param("affiliation") String affiliation);
  154. // @Select({"<script>","select a.userid,a.username,sum(a.ordernum) ordernum,sum(a.policynum) policynum,sum(a.sumpremium) sumpremium from v_user_order2 a " +
  155. // "where DATE_FORMAT(orderdate, '%Y-%m-%d') " +
  156. // "between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')" +
  157. // "and userid in " +
  158. // "<foreach item='item' index='index' collection='userList' open='(' separator=',' close=')'> " +
  159. // " #{item}" +
  160. // "</foreach > " +
  161. // "group by a.userid,a.username"
  162. // , "</script>"})
  163. List<EsmUserPolicyVO> queryOrderCount(List<String> userList, String startDate, String endDate);
  164. // @Select({"<script>","select sum(sumpremium) sumpremium " +
  165. // "from v_user_order2 a " +
  166. // "where DATE_FORMAT(orderdate, '%Y-%m-%d') " +
  167. // "between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')" +
  168. // "and userid in " +
  169. // "<foreach item='item' index='index' collection='userList' open='(' separator=',' close=')'> " +
  170. // " #{item}" +
  171. // "</foreach > "
  172. // , "</script>"})
  173. // EsmTeamPolicyVO queryOrderCountHz(List<String> userList, String startDate, String endDate);
  174. EsmTeamPolicyVO queryOrderCountHz(List<String> userList, String startDate, String endDate);
  175. Page<SysUser> getUserPage(Page page, SysUserDto dto);
  176. Page<QueryChannel> getQueryChannelPage(Page page, QueryChannel queryChannel);
  177. List<SysUserTeamDto> getByTeam(@Param("managementQueryVo") AppCustomerManagementQueryVo managementQueryVo, @Param("userId") String userId, @Param("level") int level);
  178. /**
  179. * @version
  180. * @author: hxl
  181. * @Date: 2024/6/5 18:10
  182. * @Description: 查询年分数据
  183. */
  184. List<EmployeeIncreaseReportDto> employeeIncreaseReportYear(HashMap<String,Object> map);
  185. /**
  186. * @version
  187. * @author: hxl
  188. * @Date: 2024/6/5 18:15
  189. * @Description: 查询月分数据
  190. */
  191. List<EmployeeIncreaseReportDto> employeeIncreaseReportMonth(HashMap<String,Object> map);
  192. /**
  193. * @version
  194. * @author: hxl
  195. * @Date: 2024/6/5 18:16
  196. * @Description: 查询天数数据
  197. */
  198. List<EmployeeIncreaseReportDto> employeeIncreaseReportDay(HashMap<String,Object> map);
  199. List<EsmUserPolicyForUserVO> queryOrderCountForUser(String userId,String startDate, String endDate);
  200. List<EsmUserReferrerDTO> getbyUserNextLevel(String userId);
  201. /**
  202. *
  203. * @param ids 下级ids
  204. * @return 返回 用户id 和用户级别
  205. */
  206. List<EsmUserReferrerDTO> getUserLevel(@Param("vo") QxFrontlineAgentVo qxFrontlineAgentVo);
  207. }