CmsUserController.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. package com.cyksj.web.controller.manage;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.collection.CollUtil;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import com.alipay.api.AlipayApiException;
  9. import com.baomidou.mybatisplus.core.toolkit.Assert;
  10. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  11. import com.cyksj.common.annotation.Log;
  12. import com.cyksj.common.constant.Constant;
  13. import com.cyksj.common.exception.BusinessRuntimeException;
  14. import com.cyksj.dto.Result;
  15. import com.cyksj.enums.BusinessType;
  16. import com.cyksj.enums.GatewayResponse;
  17. import com.cyksj.mapper.*;
  18. import com.cyksj.mapper.corp.CorpUserFollowRelationMapper;
  19. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  20. import com.cyksj.mapper.market.task.UserBindDetailMapper;
  21. import com.cyksj.model.entity.*;
  22. import com.cyksj.model.manage.views.MaliceUserView;
  23. import com.cyksj.model.manage.views.UserView;
  24. import com.cyksj.model.request.UserBalanceReq;
  25. import com.cyksj.model.request.UserFuncPropertyReq;
  26. import com.cyksj.model.views.*;
  27. import com.cyksj.service.relation.GroupRelationClearService;
  28. import com.cyksj.service.user.UserBenefitsService;
  29. import com.cyksj.service.user.UserBindRelationService;
  30. import com.cyksj.service.user.UserPayOrderBlockService;
  31. import com.ejlchina.searcher.BeanSearcher;
  32. import com.ejlchina.searcher.SearchResult;
  33. import com.ejlchina.searcher.param.Operator;
  34. import com.ejlchina.searcher.util.MapBuilder;
  35. import com.ejlchina.searcher.util.MapUtils;
  36. import lombok.RequiredArgsConstructor;
  37. import lombok.extern.slf4j.Slf4j;
  38. import org.springframework.dao.DuplicateKeyException;
  39. import org.springframework.transaction.annotation.Transactional;
  40. import org.springframework.validation.annotation.Validated;
  41. import org.springframework.web.bind.annotation.*;
  42. import javax.servlet.http.HttpServletRequest;
  43. import java.math.BigDecimal;
  44. import java.math.RoundingMode;
  45. import java.util.List;
  46. import java.util.Optional;
  47. /**
  48. * @author chan
  49. * @date 2022/9/27 4:42 PM
  50. */
  51. @Slf4j
  52. @RequiredArgsConstructor
  53. @RestController
  54. @RequestMapping("/manage/user")
  55. public class CmsUserController{
  56. private final HttpServletRequest request;
  57. private final BeanSearcher beanSearcher;
  58. private final UserFuncPropertyMapper userFuncPropertyMapper;
  59. private final UserMapper userMapper;
  60. private final UserBindDetailMapper userBindDetailMapper;
  61. private final GroupRelationClearService groupRelationClearService;
  62. private final GroupsRelationMapper groupsRelationMapper;
  63. private final UserBindRelationService userBindRelationService;
  64. private final CorpUserFollowRelationMapper cmsUserFollowRelationMapper;
  65. private final OrderDonMapper orderDonMapper;
  66. private final UserBenefitsService userBenefitsService;
  67. private final UserPayOrderBlockService userPayOrderBlockService;
  68. private final CmsUserMapper cmsUserMapper;
  69. private final UserCertRecordMapper userCertRecordMapper;
  70. private final UserDoubleVerifyCodeChangeRecordMapper userDoubleVerifyCodeChangeRecordMapper;
  71. private final List<Long> no_blacks_userIds = List.of(375274l, 545599l, 523937l, 507498l, 604146l, 613437l, 651728l, 614100l, 604148l);
  72. @GetMapping("/get")
  73. public Result<SearchResult<UserView>> get(Long id, String otherPhone, Long sharedId, String userid, Long businessId, String sort, String order, Boolean isCert, Boolean isAbroad) {
  74. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  75. String otherSql = StrUtil.EMPTY;
  76. if (StrUtil.isNotBlank(otherPhone)) {
  77. otherSql += String.format("(u.id in (select user_id from user_bind_detail where phone like '%s%%') or u.login_phone like '%s%%')", otherPhone, otherPhone);
  78. }
  79. if (businessId != null) {
  80. if (StrUtil.isNotBlank(otherSql)) {
  81. otherSql += " and ";
  82. }
  83. otherSql += String.format("us.shared_id in (select user_id from user_distribute where business_id = %s)", businessId);
  84. }
  85. if (id != null) {
  86. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(id, null);
  87. if (CollUtil.isNotEmpty(relationUserIdList)) {
  88. builder.field(UserView::getId, relationUserIdList).op(Operator.InList);
  89. }
  90. }
  91. if (isCert != null) {
  92. if (StrUtil.isNotBlank(otherSql)) {
  93. otherSql += " and ";
  94. }
  95. otherSql += "exists (select 1 from user_cert_record where user_id = u.id)";
  96. }
  97. if (isAbroad != null) {
  98. if (StrUtil.isNotBlank(otherSql)) {
  99. otherSql += " and ";
  100. }
  101. otherSql += String.format(" %s (select 1 from phone_code pc where pc.phone = u.login_phone and cid is not null and cid != 86)", isAbroad ? "exists" : "not exists");
  102. }
  103. if (StrUtil.isNotBlank(otherSql)) {
  104. builder.put("otherConditionSql", otherSql);
  105. }
  106. SearchResult<UserView> search = beanSearcher.search(UserView.class, builder.build());
  107. search.getDataList().forEach(data -> {
  108. Long userId = data.getId();
  109. UserBindDetail userBindDetail = beanSearcher.searchFirst(UserBindDetail.class, MapUtils.builder().field(UserBindDetail::getUserId, userId).onlySelect(UserBindDetail::getPhone, UserBindDetail::getEmail).build());
  110. Optional.ofNullable(userBindDetail).ifPresent(bind -> {
  111. data.setBindEmail(bind.getEmail());
  112. data.setBindPhone(bind.getPhone());
  113. });
  114. if (data.getSharedId() != null) {
  115. UserDistributeBusinessInfoView userDistributeBusinessInfoView = beanSearcher.searchFirst(UserDistributeBusinessInfoView.class, MapUtils.builder().field(UserDistributeBusinessInfoView::getUserId, data.getSharedId()).build());
  116. Optional.ofNullable(userDistributeBusinessInfoView).ifPresent(info -> {
  117. data.setDistributeName(info.getDistributeName());
  118. data.setBusinessName(info.getBusinessName());
  119. });
  120. }
  121. Integer selectCount = userCertRecordMapper.selectCount(Wrappers.lambdaQuery(UserCertRecord.class)
  122. .eq(UserCertRecord::getUserId, userId));
  123. data.setIsCert(selectCount > 0 ? true : false);
  124. });
  125. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  126. }
  127. /**
  128. * 查看排除绑定重复用户数 真实用户数
  129. */
  130. @GetMapping("/get/real/userNum")
  131. public Result<Integer> getRealUserNum() {
  132. Integer unBindUserNum = userMapper.selectUnBindUserNum();
  133. Integer bindUserNum = userBindDetailMapper.selectCount(null);
  134. return GatewayResponse.SUCCESS.newBuilder().toResult(unBindUserNum + bindUserNum);
  135. }
  136. /**
  137. * 修改用户的拉黑状态
  138. */
  139. @PutMapping("/put/black/status/{id}")
  140. @SaCheckPermission("user:black")
  141. public Result<String> putBlackStatus(@PathVariable Long id) {
  142. if (no_blacks_userIds.contains(id)) {
  143. throw BusinessRuntimeException.getInstance("张凯已处理");
  144. }
  145. User user = userMapper.selectById(id);
  146. Optional.ofNullable(user).ifPresent(u -> {
  147. u.setIsBlack(!u.getIsBlack());
  148. if (u.getIsBlack()) {
  149. List<Long> userIds = userBindRelationService.getRelationUserIdList(id, user);
  150. List<RenewalView> groupsRelations = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
  151. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  152. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  153. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  154. .orderBy(RenewalView::getExpiryTime).asc()
  155. .build());
  156. groupsRelations.forEach(ticket -> {
  157. GroupsRelation relation = groupsRelationMapper.selectById(ticket.getRelationId());
  158. groupRelationClearService.clearTicket(relation, UserTicketClearedRecord.Source.black);
  159. });
  160. }
  161. userMapper.updateById(u);
  162. });
  163. return GatewayResponse.SUCCESS.newBuilder().toResult();
  164. }
  165. /**
  166. * 修改用户查看验证码次数
  167. */
  168. @PutMapping("/put/verifyCheck/num")
  169. public Result<String> updateCheckCodeNum(@RequestBody UserFuncPropertyReq req) {
  170. if (req.getUserId() == null) throw BusinessRuntimeException.getInstance("用户id为空");
  171. if (req.getVerifyCheckNum() == null || req.getVerifyCheckNum() < 0) {
  172. throw BusinessRuntimeException.getInstance("请输入正确的查看验证码次数");
  173. }
  174. UserFuncProperty userFuncProperty = userFuncPropertyMapper.selectOne(Wrappers.lambdaQuery(UserFuncProperty.class)
  175. .eq(UserFuncProperty::getUserId, req.getUserId()).last("limit 1"));
  176. Boolean isFirst = false;
  177. if (userFuncProperty == null) {
  178. try {
  179. userFuncProperty = new UserFuncProperty();
  180. userFuncProperty.setUserId(req.getUserId());
  181. userFuncProperty.setVerifyCheckNum(req.getVerifyCheckNum());
  182. userFuncPropertyMapper.insert(userFuncProperty);
  183. isFirst = true;
  184. } catch (DuplicateKeyException e) {
  185. }
  186. }
  187. if (isFirst || (userFuncProperty.getVerifyCheckNum() != req.getVerifyCheckNum())) {
  188. long adminId = StpUtil.getLoginIdAsLong();
  189. UserDoubleVerifyCodeChangeRecord userDoubleVerifyCodeChangeRecord = new UserDoubleVerifyCodeChangeRecord();
  190. userDoubleVerifyCodeChangeRecord.setUserId(req.getUserId());
  191. Optional.ofNullable(cmsUserMapper.selectById(adminId))
  192. .ifPresent(cu -> userDoubleVerifyCodeChangeRecord.setOperator(cu.getNickname()));
  193. userDoubleVerifyCodeChangeRecord.setOldVerifyCheckNum(isFirst ? 1 : userFuncProperty.getVerifyCheckNum());
  194. userDoubleVerifyCodeChangeRecord.setVerifyCheckNum(req.getVerifyCheckNum());
  195. userDoubleVerifyCodeChangeRecordMapper.insert(userDoubleVerifyCodeChangeRecord);
  196. }
  197. userFuncProperty.setVerifyCheckNum(req.getVerifyCheckNum());
  198. userFuncPropertyMapper.updateById(userFuncProperty);
  199. return GatewayResponse.SUCCESS.newBuilder().toResult();
  200. }
  201. /**
  202. * 查看用户验证码次数
  203. */
  204. @GetMapping("/get/verifyCheck/num")
  205. public Result<Integer> getVerifyCheckNum(Long userId) {
  206. if (userId==null) throw BusinessRuntimeException.getInstance("用户id为空");
  207. UserFuncProperty userFuncProperty = userFuncPropertyMapper.selectOne(Wrappers.lambdaQuery(UserFuncProperty.class)
  208. .eq(UserFuncProperty::getUserId, userId).last("limit 1"));
  209. //默认0次
  210. Integer verifyCheckNum = 0;
  211. if (userFuncProperty != null) verifyCheckNum = userFuncProperty.getVerifyCheckNum();
  212. return GatewayResponse.SUCCESS.newBuilder().toResult(verifyCheckNum);
  213. }
  214. /**
  215. * 用户验证码更变记录列表展示
  216. */
  217. @GetMapping("/get/verifyCode/change/list/{userId}")
  218. public Result<SearchResult<UserDoubleVerifyCodeChangeRecord>> getUserDoubleVerifyCodeChangeRecordByUserId(@PathVariable Long userId) {
  219. SearchResult<UserDoubleVerifyCodeChangeRecord> search = beanSearcher.search(UserDoubleVerifyCodeChangeRecord.class, MapUtils.flatBuilder(request.getParameterMap())
  220. .field(UserDoubleVerifyCodeChangeRecord::getUserId, userId)
  221. .orderBy(UserDoubleVerifyCodeChangeRecord::getId).desc()
  222. .build());
  223. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  224. }
  225. /**
  226. * 用户加入企业微信客服详情
  227. */
  228. @GetMapping("/get/corpFollow/detail/{userId}")
  229. public Result<String> getCorpFollowDetailById(@PathVariable Long userId) {
  230. User user = userMapper.selectById(userId);
  231. if (user == null || StrUtil.isEmpty(user.getUnionid())) {
  232. return GatewayResponse.SUCCESS.newBuilder().toResult();
  233. }
  234. Long wxCorpId = 2l;
  235. String corpCustomers = cmsUserFollowRelationMapper.selectCorpCustomers(user.getUnionid(), wxCorpId);
  236. return GatewayResponse.SUCCESS.newBuilder().toResult(corpCustomers);
  237. }
  238. /**
  239. * 企业微信客服列表
  240. */
  241. @GetMapping("/get/corpFollow")
  242. public Result<List<CorpFollow>> getCorpFollow() {
  243. List<CorpFollow> corpFollows = beanSearcher.searchAll(CorpFollow.class, MapUtils.flatBuilder(request.getParameterMap())
  244. .field(CorpFollow::getWxCorpId, 2)
  245. .build());
  246. return GatewayResponse.SUCCESS.newBuilder().toResult(corpFollows);
  247. }
  248. /**
  249. * 用户订单详情title
  250. */
  251. @GetMapping("/get/order/title")
  252. public Result<UserView> getUserOrderDetailTitle(Long userId) {
  253. UserView userView = new UserView();
  254. List<OrderDon> orderDons = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
  255. .eq(OrderDon::getUserId, userId)
  256. .notIn(OrderDon::getStatus, Constant.noOrderStatus)
  257. .orderByAsc(OrderDon::getId));
  258. //首单产品
  259. Optional<OrderDon> firstOrder = orderDons.stream().filter(don -> don.getStatus() != OrderDon.Status.refund).findFirst();
  260. if (firstOrder.isPresent()) {
  261. OrderDon orderDon = firstOrder.get();
  262. BigDecimal money = orderDon.getMoney().divide(BigDecimal.valueOf(100));
  263. Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, orderDon.getSkuId()).onlySelect(GoodsDonSkuView::getGoodsTitle, GoodsDonSkuView::getSpecVal).build()))
  264. .ifPresent(goodsDonSkuView -> {
  265. String msg = String.format("%s%s %s元", goodsDonSkuView.getGoodsTitle(), goodsDonSkuView.getSpecVal(), money);
  266. if (orderDon.getCouponUserId() != 0) {
  267. BigDecimal subMoney = orderDon.getCouponMoney().divide(BigDecimal.valueOf(100));
  268. msg = String.format("%s(减免%s元)", msg, subMoney);
  269. }
  270. userView.setFirstOrderDetail(msg);
  271. });
  272. }
  273. //有无路由器订单
  274. Optional<OrderDon> routeOrder = orderDons.stream().filter(don -> don.getGoodsId() == 15).findFirst();
  275. userView.setIsHadRouteOrder(routeOrder.isPresent() ? true : false);
  276. Integer noRefundOrders = 0;
  277. Integer refundOrders = 0;
  278. //除去退款 下单金额
  279. BigDecimal orderMoney = BigDecimal.ZERO;
  280. BigDecimal refundMoney = BigDecimal.ZERO;
  281. for (OrderDon orderDon : orderDons) {
  282. if (orderDon.getStatus() == OrderDon.Status.refund) {
  283. refundOrders++;
  284. if (orderDon.getRefundMoney() != null) {
  285. refundMoney = refundMoney.add(orderDon.getRefundMoney());
  286. }
  287. }else {
  288. noRefundOrders++;
  289. orderMoney = orderMoney.add(orderDon.getMoney());
  290. }
  291. }
  292. BigDecimal refundRate = BigDecimal.ZERO;
  293. if (!orderDons.isEmpty()) {
  294. //退款率
  295. refundRate = BigDecimal.valueOf(refundOrders).divide(BigDecimal.valueOf(orderDons.size()), 2, RoundingMode.HALF_UP);
  296. }
  297. userView.setOrderMoney(orderMoney);
  298. userView.setNumOfOrder(noRefundOrders);
  299. userView.setRefundMoney(refundMoney);
  300. userView.setRefundRate(refundRate);
  301. return GatewayResponse.SUCCESS.newBuilder().toResult(userView);
  302. }
  303. /**
  304. * 用户下单详情
  305. */
  306. @GetMapping("/get/order/list")
  307. public Result<SearchResult<UserOrderDonDetail>> getUserOrderDetails() {
  308. SearchResult<UserOrderDonDetail> search = beanSearcher.search(UserOrderDonDetail.class, MapUtils.flatBuilder(request.getParameterMap())
  309. .field(UserOrderDonDetail::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
  310. .build());
  311. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  312. }
  313. /**
  314. * 问卷回答列表
  315. */
  316. @GetMapping("/get/question/response/list")
  317. public Result<List<QuestionResponseRecordView>> getQuestionResponseList(String first, String end) {
  318. String timeSql = StrUtil.EMPTY;
  319. if (StrUtil.isNotBlank(first)) {
  320. timeSql += String.format(" and created_time >= '%s'", first);
  321. }
  322. if (StrUtil.isNotBlank(end)) {
  323. timeSql += String.format(" and created_time < '%s'", end);
  324. }
  325. MapBuilder builder = MapUtils.builder();
  326. if (StrUtil.isNotBlank(timeSql)) {
  327. builder.put("time", timeSql);
  328. }
  329. List<QuestionResponseRecordView> views = beanSearcher.searchAll(QuestionResponseRecordView.class, builder.build());
  330. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  331. }
  332. /**
  333. * 余额扣除
  334. */
  335. @PutMapping("/sub/balance")
  336. @Transactional(rollbackFor = Throwable.class)
  337. @Log(module = "用户管理/扣除用户余额", businessType = BusinessType.PUT, isSaveRequestData = true)
  338. public Result<String> subBalance(@RequestBody @Validated UserBalanceReq balanceReq) {
  339. BigDecimal deductBalance = balanceReq.getDeductBalance();
  340. if (deductBalance.compareTo(BigDecimal.ZERO) <= 0) {
  341. throw BusinessRuntimeException.getInstance("请扣除正确的余额数值");
  342. }
  343. Long userId = balanceReq.getUserId();
  344. User user = userMapper.selectById(userId);
  345. Assert.notNull(user, "用户不存在");
  346. if (user.getBalance().compareTo(deductBalance) < 0) {
  347. throw BusinessRuntimeException.getInstance("用户余额不足");
  348. }
  349. int update = userMapper.update(null, Wrappers.lambdaUpdate(User.class)
  350. .set(User::getBalance, user.getBalance().subtract(deductBalance))
  351. .eq(User::getId, userId)
  352. .eq(User::getBalance, user.getBalance()));
  353. if (update == 0) {
  354. throw BusinessRuntimeException.getInstance("扣除用户余额失败,请重试...");
  355. }
  356. userBenefitsService.recordBalanceBySource(userId, deductBalance.negate(), UserBalanceSourceRecord.Source.manual, null, UserBalanceSourceRecord.Source.manual.getDesc());
  357. return GatewayResponse.SUCCESS.newBuilder().toResult();
  358. }
  359. /**
  360. * 新增用户下单拉黑记录
  361. */
  362. @PostMapping("/userOrder/block")
  363. public Result<String> blockUserOrder(@RequestBody UserPayOrderBlock payOrderBlock) throws AlipayApiException {
  364. String orderNo = payOrderBlock.getOrderNo();
  365. Assert.notEmpty(orderNo, "请输入订单号");
  366. userPayOrderBlockService.blockUserOrder(payOrderBlock);
  367. return GatewayResponse.SUCCESS.newBuilder().toResult();
  368. }
  369. /**
  370. * 删除用户下单拉黑记录
  371. */
  372. @DeleteMapping("/userOrder/{id}")
  373. public Result<String> delBlockUserOrder(@PathVariable Long id) {
  374. userPayOrderBlockService.removeById(id);
  375. return GatewayResponse.SUCCESS.newBuilder().toResult();
  376. }
  377. /**
  378. * 用户下单拉黑 列表
  379. */
  380. @GetMapping("/userOrder")
  381. public Result<SearchResult<UserPayOrderBlock>> getBlockUserOrder() {
  382. SearchResult<UserPayOrderBlock> search = beanSearcher.search(UserPayOrderBlock.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  383. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  384. }
  385. /**
  386. * 用户每日活跃登录记录
  387. */
  388. @GetMapping("/get/user/login/record/{userId}")
  389. public Result<SearchResult<UserLoginRecord>> getUserLoginRecord(@PathVariable Long userId) {
  390. SearchResult<UserLoginRecord> search = beanSearcher.search(UserLoginRecord.class, MapUtils.flatBuilder(request.getParameterMap()).field(UserLoginRecord::getUserId, userId)
  391. .orderBy(UserLoginRecord::getCreatedTime).desc()
  392. .build());
  393. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  394. }
  395. /**
  396. * 大额度用户 列表
  397. */
  398. @GetMapping("/get/consume/large/user")
  399. public Result<SearchResult<UserView>> getLargeConsumer() {
  400. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  401. String largeLimit = "200000";
  402. String fu = String.format("(select distinct user_id from order_don o where o.relation_id != 0 and o.status not in ('close','noPayment','refund') group by user_id, date_format(o.created_time,'%%Y-%%m-%%d')" +
  403. "having sum(money) > %s) ln inner join", largeLimit);
  404. String fuOn = " on ln.user_id = u.id";
  405. builder.put("fu", fu);
  406. builder.put("fu_on", fuOn);
  407. SearchResult<UserView> search = beanSearcher.search(UserView.class, builder.build());
  408. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  409. }
  410. /**
  411. * 是否有最新的用户产生
  412. */
  413. @GetMapping("/get/consume/large/newUser")
  414. public Result<Boolean> getLargeNewConsumer() {
  415. String largeLimit = "200000";
  416. DateTime beginOfDay = DateUtil.beginOfDay(DateTime.now());
  417. Integer newConsumerCount = userMapper.getLargeNewConsumer(beginOfDay, largeLimit);
  418. return GatewayResponse.SUCCESS.newBuilder().toResult(newConsumerCount > 0 ? true : false);
  419. }
  420. /**
  421. * 超过恶意用户列表
  422. * 使用五个以上得支付宝
  423. */
  424. @GetMapping("/get/malice/user")
  425. public Result<SearchResult<MaliceUserView>> getMaliceUser() {
  426. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  427. SearchResult<MaliceUserView> search = beanSearcher.search(MaliceUserView.class, builder
  428. .orderBy(MaliceUserView::getId).asc()
  429. .build());
  430. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  431. }
  432. /**
  433. * 是否有最新恶意用户
  434. */
  435. @GetMapping("get/malice/user/newUser")
  436. public Result<Boolean> getNewMaliceUser() {
  437. DateTime beginOfDay = DateUtil.beginOfDay(DateTime.now());
  438. Integer newConsumerCount = userMapper.getNewMaliceUser(beginOfDay);
  439. return GatewayResponse.SUCCESS.newBuilder().toResult(newConsumerCount > 0 ? true : false);
  440. }
  441. /**
  442. * 用户ip列表
  443. */
  444. @GetMapping("/get/ip/list")
  445. public Result<SearchResult<OrderDonLocationRelateView>> orderDonLocationRelateResult(Long userId) {
  446. if (userId == null) {
  447. return GatewayResponse.SUCCESS.newBuilder().toResult();
  448. }
  449. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  450. SearchResult<OrderDonLocationRelateView> search = beanSearcher.search(OrderDonLocationRelateView.class, MapUtils.flatBuilder(request.getParameterMap()).put("userId", String.format("where user_id in (%s)", userIdList.toString().replaceAll("\\[", "").replaceAll("]", ""))).build());
  451. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  452. }
  453. /**
  454. * 用户支付宝列表
  455. */
  456. @GetMapping("/get/zfb/list")
  457. public Result<List<OrderDonBuyerView>> getZfbBuyers(Long userId) {
  458. if (userId == null) {
  459. return GatewayResponse.SUCCESS.newBuilder().toResult();
  460. }
  461. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  462. List<OrderDonBuyerView> orderDonBuyerViews = beanSearcher.searchAll(OrderDonBuyerView.class, MapUtils.flatBuilder(request.getParameterMap()).field(OrderDonBuyerView::getUserId, userIdList).op(Operator.InList).build());
  463. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonBuyerViews);
  464. }
  465. /**
  466. * 每月买过两单奈飞账号用户列表
  467. */
  468. @GetMapping("/get/more/netflix/user")
  469. public Result<SearchResult<UserNfView>> getMoreNetflixUser() {
  470. SearchResult<UserNfView> search = beanSearcher.search(UserNfView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  471. search.getDataList().forEach(data -> {
  472. Long userId = data.getId();
  473. UserBindDetail userBindDetail = beanSearcher.searchFirst(UserBindDetail.class, MapUtils.builder().field(UserBindDetail::getUserId, userId).onlySelect(UserBindDetail::getPhone, UserBindDetail::getEmail).build());
  474. Optional.ofNullable(userBindDetail).ifPresent(bind -> {
  475. data.setBindEmail(bind.getEmail());
  476. data.setBindPhone(bind.getPhone());
  477. });
  478. });
  479. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  480. }
  481. }