EsmUserReferrerMapper.java 9.3 KB

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