Răsfoiți Sursa

fix 优化后台账号列表查询及导出

zoujiajian 3 ani în urmă
părinte
comite
6828a03196

+ 9 - 19
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelManageAccountData.java

@@ -20,9 +20,8 @@ import java.util.Date;
 @Setter
 @Setter
 @SearchBean(tables = "account a left join goods_don g on a.goods_id = g.id " +
 @SearchBean(tables = "account a left join goods_don g on a.goods_id = g.id " +
 		"left join groups_trips gt on gt.account_id = a.id " +
 		"left join groups_trips gt on gt.account_id = a.id " +
-		"left join groups_relation gr on gr.groups_id = gt.id " +
 		"left join goods_don_sku gdk on gdk.id = gt.sku_id",
 		"left join goods_don_sku gdk on gdk.id = gt.sku_id",
-		groupBy = "a.id,g.id,a.bank_card,g.title,a.account,a.password,a.api_key,a.verify_codes,a.start_time,a.expiry_time,a.amount,a.cn_account,a.us_account,gt.id,a.remark,gdk.id,gdk.spec_val")
+		where = ":extra_sql:")
 public class ExcelManageAccountData {
 public class ExcelManageAccountData {
 
 
 	@ExcelIgnore
 	@ExcelIgnore
@@ -77,26 +76,17 @@ public class ExcelManageAccountData {
 	@DbIgnore
 	@DbIgnore
 	private String activeCodeStatus;
 	private String activeCodeStatus;
 
 
-	@DbField("select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self'")
+	//@DbField("select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self'")
 	@ExcelIgnore
 	@ExcelIgnore
+	@DbIgnore
 	private Integer expiryCount;
 	private Integer expiryCount;
 
 
-	@DbField("if((select s.account_id from (select s.account_id, count(*) num" +
-			" from (select ur.account_id, ur.relation_id" +
-			" from user_ticket_cleared_record ur where ur.deleted is true and source = 'self'" +
-			" group by ur.account_id, ur.relation_id) s" +
-			"  group by s.account_id) s left join groups_trips gt on gt.account_id = s.account_id where s.account_id = a.id and s.num >= gt.num)is null,false,true)")
+//	@DbField("if((select s.account_id from (select s.account_id, count(*) num" +
+//			" from (select ur.account_id, ur.relation_id" +
+//			" from user_ticket_cleared_record ur where ur.deleted is true and source = 'self'" +
+//			" group by ur.account_id, ur.relation_id) s" +
+//			"  group by s.account_id) s left join groups_trips gt on gt.account_id = s.account_id where s.account_id = a.id and s.num >= gt.num)is null,false,true)")
+	@DbIgnore
 	@ExcelIgnore
 	@ExcelIgnore
 	private Boolean expiredAll;
 	private Boolean expiredAll;
-
-	@DbField("max(gr.expiry_time)")
-	@ExcelIgnore
-	private Date lastTicketTime;
-
-	/**
-	 * 今日有过期人员
-	 */
-	@DbField("min(gr.expiry_time)")
-	@ExcelIgnore
-	private Date firstTicketTime;
 }
 }

+ 7 - 13
netflix-dao/src/main/java/com/cyksj/model/manage/views/AccountView.java

@@ -17,9 +17,8 @@ import java.util.Date;
 @Setter
 @Setter
 @SearchBean(tables = "account a left join goods_don g on a.goods_id = g.id " +
 @SearchBean(tables = "account a left join goods_don g on a.goods_id = g.id " +
         "left join groups_trips gt on gt.account_id = a.id " +
         "left join groups_trips gt on gt.account_id = a.id " +
-        "left join groups_relation gr on gr.groups_id = gt.id " +
         "left join goods_don_sku gdk on gdk.id = gt.sku_id",
         "left join goods_don_sku gdk on gdk.id = gt.sku_id",
-        groupBy = "a.id,g.id,a.bank_card,g.title,a.account,a.password,a.api_key,a.verify_codes,a.start_time,a.expiry_time,a.amount,a.cn_account,a.us_account,gt.id,a.remark,gdk.id,gdk.spec_val,a.customer_service_id,a.secret,a.api_secret")
+        where = ":extra_sql:")
 public class AccountView {
 public class AccountView {
 
 
     @DbField("a.id")
     @DbField("a.id")
@@ -106,24 +105,19 @@ public class AccountView {
     @DbField("gdk.spec_val")
     @DbField("gdk.spec_val")
     private String specVal;
     private String specVal;
 
 
-    @DbField("select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self' :yesTime:")
+    //@DbField("select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self' :yesTime:")
+    @DbIgnore
     private Integer expiryCount;
     private Integer expiryCount;
 
 
-    @DbField("if((select s.account_id from (select s.account_id,count(*) num" +
-            " from (select ur.account_id, ur.relation_id" +
-            " from user_ticket_cleared_record ur where ur.deleted is true and source = 'self' :yesTime:" +
-            " group by ur.account_id, ur.relation_id) s" +
-            "  group by s.account_id) s left join groups_trips gt on gt.account_id = s.account_id where s.account_id = a.id and s.num >= 5)is null,false,true)")
+    //@DbField("if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self' :yesTime:)>=5,true,false)")
+    @DbIgnore
     private Boolean expiredAll;
     private Boolean expiredAll;
 
 
-    @DbField("max(gr.expiry_time)")
-    private Date lastTicketTime;
-
     /**
     /**
      * 今日有过期人员
      * 今日有过期人员
      */
      */
-    @DbField("min(gr.expiry_time)")
-    private Date firstTicketTime;
+    @DbIgnore
+    private Boolean hadExpiredToDay;
 
 
     @DbIgnore
     @DbIgnore
     private Integer updatePwdNum;
     private Integer updatePwdNum;

+ 3 - 2
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -309,10 +309,11 @@ public class Scheduler {
     @Scheduled(cron = "0 30 8 * * ?")
     @Scheduled(cron = "0 30 8 * * ?")
     public void assignNeedUpdateExpiredAccount() {
     public void assignNeedUpdateExpiredAccount() {
         DateTime beginOfDay = DateUtil.beginOfDay(DateTime.now());
         DateTime beginOfDay = DateUtil.beginOfDay(DateTime.now());
+	    String yesTimeSql = String.format("and ur.created_time < '%s'", beginOfDay);
+	    String extra_sql = String.format("(if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self' %s)>=5,true,false)) = 1", yesTimeSql);
         List<AccountView> accountViews = beanSearcher.searchAll(AccountView.class, MapUtils.builder()
         List<AccountView> accountViews = beanSearcher.searchAll(AccountView.class, MapUtils.builder()
-                .field(AccountView::getExpiredAll, 1)
+                .put("extra_sql", extra_sql)
                 .field(AccountView::getCustomerServiceId, 0)
                 .field(AccountView::getCustomerServiceId, 0)
-                .put("yesTime", String.format("and ur.created_time < '%s'", beginOfDay))
                 .build());
                 .build());
         if (accountViews.size() > 0) {
         if (accountViews.size() > 0) {
             int accountSize = accountViews.size();
             int accountSize = accountViews.size();

+ 103 - 58
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -56,7 +56,6 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 import java.util.Optional;
 import java.util.Optional;
 import java.util.Set;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
@@ -95,49 +94,74 @@ public class CmsAccountController {
 
 
 	private final AccountDoubleVerifyRecordMapper doubleVerifyRecordMapper;
 	private final AccountDoubleVerifyRecordMapper doubleVerifyRecordMapper;
 
 
-    @GetMapping("/get")
-    @SaCheckPermission("account:view")
-    public Result<SearchResult<AccountView>> get(Long userId ,String nickName ,String submitAccount ,String expiryStartTime, String expiryEndTime) {
-        MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
-        if (StrUtil.isNotEmpty(expiryStartTime) || StrUtil.isNotEmpty(expiryEndTime)) {
-            mapBuilder.field(AccountView::getExpiryTime, expiryStartTime, expiryEndTime)
-                    .op(Operator.Between);
-        }
+	@GetMapping("/get")
+	@SaCheckPermission("account:view")
+	public Result<SearchResult<AccountView>> get(Long userId, String nickName, String submitAccount, String expiryStartTime, String expiryEndTime, Boolean expiredAll, Boolean existsExpired, Boolean existsExpiredToday) {
+		MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
+		if (StrUtil.isNotEmpty(expiryStartTime) || StrUtil.isNotEmpty(expiryEndTime)) {
+			mapBuilder.field(AccountView::getExpiryTime, expiryStartTime, expiryEndTime)
+					.op(Operator.Between);
+		}
 
 
-        if(userId != null || StringUtils.isNotBlank(nickName) || StringUtils.isNotBlank(submitAccount)){
-            List<Long> accountIds = homeGroupMapper.getAccountIdsByUserIdOrNickNameOrSubmitAccount(userId, nickName ,submitAccount);
-            if(accountIds.isEmpty()){
-                return GatewayResponse.SUCCESS.newBuilder().toResult(new SearchResult<>());
-            }
+		if (userId != null || StringUtils.isNotBlank(nickName) || StringUtils.isNotBlank(submitAccount)) {
+			List<Long> accountIds = homeGroupMapper.getAccountIdsByUserIdOrNickNameOrSubmitAccount(userId, nickName, submitAccount);
+			if (accountIds.isEmpty()) {
+				return GatewayResponse.SUCCESS.newBuilder().toResult(new SearchResult<>());
+			}
 
 
-            mapBuilder.field(AccountView::getId, accountIds).op(Operator.InList);
-        }
+			mapBuilder.field(AccountView::getId, accountIds).op(Operator.InList);
+		}
+		String extra_sql = StrUtil.EMPTY;
+		if (expiredAll != null && expiredAll) {
+			extra_sql += "(if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self')>=5,true,false)) = 1";
+		}
 
 
-        SearchResult<AccountView> search = beanSearcher.search(AccountView.class, mapBuilder.build());
-        search.getDataList().forEach((accountView)->{
-            Integer invited = homeGroupMapper.selectCount(Wrappers.lambdaQuery(HomeGroup.class).eq(HomeGroup::getAccountId, accountView.getId()).eq(HomeGroup::getStatus, "invited"));
-            GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getAccountId, accountView.getId()).last(" limit 1"));
-            int total = groupsTrips == null ? 0 : groupsTrips.getNum() - groupsTrips.getAvailableNum();
-            Integer unInvited = Math.max(total - invited, 0);
-            accountView.setUnInvited(unInvited);
-            accountView.setInvited(invited);
-            accountView.setTotal(total);
-	        List<AccountUpdatePasswordRecord> recordList = beanSearcher.searchList(AccountUpdatePasswordRecord.class,
-			        MapUtils.builder().field(AccountUpdatePasswordRecord::getAccountId, accountView.getId())
-					        .onlySelect(AccountUpdatePasswordRecord::getCreatedTime)
-					        .orderBy(AccountUpdatePasswordRecord::getId)
-					        .build());
-	        accountView.setUpdatePwdNum(recordList.size());
-	        if (accountView.getCustomerServiceId() != 0) {
-		        CmsUser cmsUser = cmsUserMapper.selectById(accountView.getCustomerServiceId());
-		        Optional.ofNullable(cmsUser).ifPresent(customer -> accountView.setCustomerServiceName(cmsUser.getNickname()));
-	        }
-	        if (recordList.size() > 0) {
-		        accountView.setLastUpdatePwdDate(recordList.get(0).getCreatedTime());
-	        }
-        });
-        return GatewayResponse.SUCCESS.newBuilder().toResult(search);
-    }
+		if (existsExpired != null && existsExpired) {
+			if (StrUtil.isNotEmpty(extra_sql)) {
+				extra_sql += " and";
+			}
+			extra_sql += "(select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self') > 0";
+		}
+		if (existsExpiredToday != null) {
+			DateTime endOfDay = DateUtil.endOfDay(DateTime.now());
+			if (StrUtil.isNotEmpty(extra_sql)) {
+				extra_sql += " and";
+			}
+			if (existsExpiredToday) {
+				extra_sql += String.format(" (select min(expiry_time) from (select gt.id from groups_trips where account_id = a.id) gt inner join groups_relation gr on gr.groups_id = gt.id) <= '%s'", endOfDay);
+			} else {
+				extra_sql += String.format(" (select min(expiry_time) from (select gt.id from groups_trips where account_id = a.id) gt inner join groups_relation gr on gr.groups_id = gt.id) > '%s'", endOfDay);
+			}
+		}
+		if (StrUtil.isNotEmpty(extra_sql)) {
+			mapBuilder.put("extra_sql", extra_sql);
+		}
+
+		SearchResult<AccountView> search = beanSearcher.search(AccountView.class, mapBuilder.build());
+		search.getDataList().forEach((accountView) -> {
+			Integer invited = homeGroupMapper.selectCount(Wrappers.lambdaQuery(HomeGroup.class).eq(HomeGroup::getAccountId, accountView.getId()).eq(HomeGroup::getStatus, "invited"));
+			GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getAccountId, accountView.getId()).last(" limit 1"));
+			int total = groupsTrips == null ? 0 : groupsTrips.getNum() - groupsTrips.getAvailableNum();
+			Integer unInvited = Math.max(total - invited, 0);
+			accountView.setUnInvited(unInvited);
+			accountView.setInvited(invited);
+			accountView.setTotal(total);
+			List<AccountUpdatePasswordRecord> recordList = beanSearcher.searchList(AccountUpdatePasswordRecord.class,
+					MapUtils.builder().field(AccountUpdatePasswordRecord::getAccountId, accountView.getId())
+							.onlySelect(AccountUpdatePasswordRecord::getCreatedTime)
+							.orderBy(AccountUpdatePasswordRecord::getId)
+							.build());
+			accountView.setUpdatePwdNum(recordList.size());
+			if (accountView.getCustomerServiceId() != 0) {
+				CmsUser cmsUser = cmsUserMapper.selectById(accountView.getCustomerServiceId());
+				Optional.ofNullable(cmsUser).ifPresent(customer -> accountView.setCustomerServiceName(cmsUser.getNickname()));
+			}
+			if (recordList.size() > 0) {
+				accountView.setLastUpdatePwdDate(recordList.get(0).getCreatedTime());
+			}
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
 
 
     /**
     /**
      * 导出账号
      * 导出账号
@@ -145,7 +169,7 @@ public class CmsAccountController {
     @GetMapping("/export/account")
     @GetMapping("/export/account")
     @SaCheckPermission("account:export")
     @SaCheckPermission("account:export")
     @Log(module = "平台管理/导出账号", businessType = BusinessType.EXPORT, isSaveRequestData = true)
     @Log(module = "平台管理/导出账号", businessType = BusinessType.EXPORT, isSaveRequestData = true)
-    public void exportAccount(Long userId, String nickName, String submitAccount, String expiryStartTime, String expiryEndTime, HttpServletResponse response) {
+    public void exportAccount(Long userId, String nickName, String submitAccount, String expiryStartTime, String expiryEndTime, Boolean expiredAll, Boolean existsExpired, Boolean existsExpiredToday, HttpServletResponse response) {
         MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
         MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
         if (StrUtil.isNotEmpty(expiryStartTime) || StrUtil.isNotEmpty(expiryEndTime)) {
         if (StrUtil.isNotEmpty(expiryStartTime) || StrUtil.isNotEmpty(expiryEndTime)) {
             mapBuilder.field(ExcelManageAccountData::getExpiryTime, expiryStartTime, expiryEndTime)
             mapBuilder.field(ExcelManageAccountData::getExpiryTime, expiryStartTime, expiryEndTime)
@@ -160,9 +184,34 @@ public class CmsAccountController {
 
 
             mapBuilder.field(ExcelManageAccountData::getId, accountIds).op(Operator.InList);
             mapBuilder.field(ExcelManageAccountData::getId, accountIds).op(Operator.InList);
         }
         }
-        List<ExcelManageAccountData> list = beanSearcher.searchAll(ExcelManageAccountData.class, mapBuilder.build());
+	    String extra_sql = StrUtil.EMPTY;
+	    if (expiredAll != null && expiredAll) {
+		    extra_sql += "(if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self')>=5,true,false)) = 1";
+	    }
+
+	    if (existsExpired != null && existsExpired) {
+		    if (StrUtil.isNotEmpty(extra_sql)) {
+			    extra_sql += " and";
+		    }
+		    extra_sql += "(select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self') > 0";
+	    }
+	    if (existsExpiredToday != null) {
+		    DateTime endOfDay = DateUtil.endOfDay(DateTime.now());
+		    if (StrUtil.isNotEmpty(extra_sql)) {
+			    extra_sql += " and";
+		    }
+		    if (existsExpiredToday) {
+			    extra_sql += String.format(" (select min(expiry_time) from (select gt.id from groups_trips where account_id = a.id) gt inner join groups_relation gr on gr.groups_id = gt.id) <= '%s'", endOfDay);
+		    } else {
+			    extra_sql += String.format(" (select min(expiry_time) from (select gt.id from groups_trips where account_id = a.id) gt inner join groups_relation gr on gr.groups_id = gt.id) > '%s'", endOfDay);
+		    }
+	    }
+	    if (StrUtil.isNotEmpty(extra_sql)) {
+		    mapBuilder.put("extra_sql", extra_sql);
+	    }
+	    List<ExcelManageAccountData> list = beanSearcher.searchAll(ExcelManageAccountData.class, mapBuilder.build());
 
 
-        EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelManageAccountData.class, list, "账号列表", "账号列表", ExcelTypeEnum.XLSX, null);
+	    EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelManageAccountData.class, list, "账号列表", "账号列表", ExcelTypeEnum.XLSX, null);
     }
     }
 
 
     /**
     /**
@@ -591,22 +640,18 @@ public class CmsAccountController {
 		if (user != null && user.getRoleNames() != null && user.getRoleNames().contains("客服")) {
 		if (user != null && user.getRoleNames() != null && user.getRoleNames().contains("客服")) {
 			builder.field(AccountView::getCustomerServiceId, userId);
 			builder.field(AccountView::getCustomerServiceId, userId);
 		}
 		}
-		AtomicInteger numOfExpiredAccount = new AtomicInteger(0);
+		//需要修改密码
+		String extra_sql = "(if((select count(distinct relation_id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self')>=5,true,false)) = 1";
+		builder.put("extra_sql", extra_sql);
+		Number expireAll = beanSearcher.searchCount(AccountView.class, builder.build());
+		//存在过期
+		extra_sql = "(select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true and source = 'self') > 0";
+		builder.put("extra_sql", extra_sql);
+		Number existsExpired = beanSearcher.searchCount(AccountView.class, builder.build());
 
 
-		AtomicInteger numOfExpiredAllAccount = new AtomicInteger(0);
-
-		List<AccountView> accountViews = beanSearcher.searchAll(AccountView.class, builder.onlySelect(AccountView::getId, AccountView::getExpiryCount, AccountView::getExpiredAll).build());
-		accountViews.forEach(account -> {
-			if (account.getExpiryCount() > 0) {
-				numOfExpiredAccount.getAndAdd(1);
-			}
-			if (account.getExpiredAll()) {
-				numOfExpiredAllAccount.getAndAdd(1);
-			}
-		});
 		CustomerServiceUpdatePwdDetail updatePwdDetail = new CustomerServiceUpdatePwdDetail();
 		CustomerServiceUpdatePwdDetail updatePwdDetail = new CustomerServiceUpdatePwdDetail();
-		updatePwdDetail.setNumOfExpiredAccount(numOfExpiredAccount.get());
-		updatePwdDetail.setNumOfExpiredAllAccount(numOfExpiredAllAccount.get());
+		updatePwdDetail.setNumOfExpiredAllAccount(expireAll.intValue());
+		updatePwdDetail.setNumOfExpiredAccount(existsExpired.intValue());
 
 
 		return GatewayResponse.SUCCESS.newBuilder().toResult(updatePwdDetail);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(updatePwdDetail);
 	}
 	}