Jelajahi Sumber

Midjourney平台封禁账号导入以及候补

zoujiajian 2 tahun lalu
induk
melakukan
f25db23fde

+ 17 - 0
netflix-dao/src/main/java/com/cyksj/mapper/AccountBlockedReplaceRecordMapper.java

@@ -0,0 +1,17 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.AccountBlockedReplaceRecord;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 项目名: netflix-job
+ * 文件名: AccountBlockedReplaceRecordMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/1/16 16:39
+ */
+public interface AccountBlockedReplaceRecordMapper extends BaseMapper<AccountBlockedReplaceRecord> {
+	void batchInsert(@Param("list") List<AccountBlockedReplaceRecord> list);
+}

+ 50 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/AccountBlockedReplaceRecord.java

@@ -0,0 +1,50 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * 项目名: netflix-job
+ * 文件名: AccountBlockedReplaceRecord
+ * 创建者: JavaZou
+ * 创建时间:2024/1/16 16:37
+ */
+@Getter
+@Setter
+@SearchBean(tables = "account_blocked_replace_record ar left join goods_don g on g.id = ar.goods_id")
+public class AccountBlockedReplaceRecord {
+
+
+	@DbField("ar.id")
+	private Long id;
+
+	@DbField("ar.account")
+	private String account;
+
+	@DbField("ar.goods_id")
+	private Long goodsId;
+
+	@DbField("a.title")
+	@TableField(exist = false)
+	private String title;
+
+	/**
+	 * 创建时间
+	 */
+	@TableField(fill = FieldFill.INSERT)
+	@DbField("ar.created_time")
+	private Date createdTime;
+
+	/**
+	 * 修改时间
+	 */
+	@TableField(fill = FieldFill.INSERT_UPDATE)
+	@DbField("ar.update_time")
+	private Date updateTime;
+}

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/response/GptStandbyResp.java

@@ -1,9 +1,12 @@
 package com.cyksj.model.response;
 
 
+import com.cyksj.model.views.RenewalView;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 @Getter
 @Setter
 public class GptStandbyResp {
@@ -13,6 +16,13 @@ public class GptStandbyResp {
      */
     private Boolean isHasAccount;
 
+    /**
+     * 候补车票账号
+     */
+    private List<RenewalView> overTen;
+
+    private List<RenewalView> underTen;
+
     /**
      * 是否申请候补
      */

+ 13 - 0
netflix-dao/src/main/resources/mapper/AccountBlockedReplaceRecordMapper.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.cyksj.mapper.AccountBlockedReplaceRecordMapper">
+
+    <insert id="batchInsert">
+        insert ignore into
+        account_blocked_replace_record(`account`,`goods_id`,`created_time`,`update_time`)
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.account},#{item.goodsId},now(),now())
+        </foreach>
+    </insert>
+</mapper>

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/mange/CmsAccountService.java

@@ -51,4 +51,6 @@ public interface CmsAccountService extends IService<Account> {
 	void analysisAmericaAppidAccount(Long goodsId, Long skuId, List<Object> accountList);
 
 	void readFileAndImportEmail(MultipartFile file) throws Exception;
+
+	void batchImportBlockedAccount(Long goodsId, List<Object> accountBlockedList);
 }

+ 34 - 1
netflix-service/src/main/java/com/cyksj/service/mange/account/CmsAccountServiceImpl.java

@@ -1,9 +1,11 @@
 package com.cyksj.service.mange.account;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -11,11 +13,13 @@ import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
+import com.cyksj.mapper.AccountBlockedReplaceRecordMapper;
 import com.cyksj.mapper.AccountMapper;
 import com.cyksj.mapper.AccountUpdatePasswordRecordMapper;
-import com.cyksj.mapper.sys.SysEmailMapper;
+import com.cyksj.mapper.GoodsDonMapper;
 import com.cyksj.mapper.manage.AutoUpdateAccountPwdLogMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
+import com.cyksj.mapper.sys.SysEmailMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.excel.ExcelAccountData;
 import com.cyksj.model.manage.views.AccountView;
@@ -69,6 +73,10 @@ public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> i
 
 	private final SysEmailMapper sysEmailMapper;
 
+	private final GoodsDonMapper goodsDonMapper;
+
+	private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
+
 	@Override
 	public IPage<ExpiredAccountDataView> getExpiredAccountView(Boolean isCorpWx, String customerService, Long goodsId, Long skuId, String account, Boolean renewStatus, Boolean handleStatus, String cnAccount, String usAccount, Integer userId, String startTime, String endTime, String now, Long offset, Long limit) {
 		return accountMapper.getExpiredAccountView(isCorpWx, customerService, goodsId, skuId, account, renewStatus, handleStatus, cnAccount, usAccount, userId, startTime, endTime, now, new Page<>(offset, limit));
@@ -379,4 +387,29 @@ public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> i
 		groupsTrips.setAccountId(accountId);
 		cmsGroupService.issuance(groupsTrips, null);
 	}
+
+	@Override
+	public void batchImportBlockedAccount(Long goodsId, List<Object> accountBlockedList) {
+		GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
+		Assert.notNull(goodsDon, "平台不存在");
+		List<AccountBlockedReplaceRecord> list = new ArrayList<>();
+		accountBlockedList.forEach(accountBlocked->{
+			Map<String, Object> map = Jsons.toMap(accountBlocked);
+			String blockedAccount = map.get("0").toString();
+			if (!Validator.isEmail(blockedAccount)) {
+				return;
+			}
+			AccountBlockedReplaceRecord accountBlockedReplaceRecord = new AccountBlockedReplaceRecord();
+			accountBlockedReplaceRecord.setGoodsId(goodsId);
+			accountBlockedReplaceRecord.setAccount(blockedAccount);
+			list.add(accountBlockedReplaceRecord);
+			if (list.size() == 400) {
+				accountBlockedReplaceRecordMapper.batchInsert(list);
+				list.clear();
+			}
+		});
+		if (list.size() > 0) {
+			accountBlockedReplaceRecordMapper.batchInsert(list);
+		}
+	}
 }

+ 56 - 16
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -56,10 +56,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * @author chan
@@ -117,6 +116,8 @@ public class GroupRelationController {
 
     private final GoodsDonSkuMapper goodsDonSkuMapper;
 
+    private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
+
     private final static Sequence SEQUENCE = new Sequence(0);
 
     @RequestMapping("/get/renewal")
@@ -599,19 +600,46 @@ public class GroupRelationController {
     public Result<GptStandbyResp> getGptStandby() {
         long userId = StpUserUtil.getLoginIdAsLong();
         List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
-        Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
+        String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
+        List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
                 .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
                 .field(RenewalView::getGoodsId, 26)
-                .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
-                .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
+                .put("condition", condition)
+                .field(RenewalView::getExpiryTime).op(Operator.NotNull)
+                .onlySelect(RenewalView::getAccount, RenewalView::getExpiryTime)
                 .build());
         GptStandbyResp gptStandbyResp = new GptStandbyResp();
-        gptStandbyResp.setIsHasAccount(number.intValue() > 0 ? true : false);
-        if (gptStandbyResp.getIsHasAccount()) {
-            Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
-                    .in(GptTicketStandby::getUserId, relationUserIdList));
-            gptStandbyResp.setIsApply(count > 0 ? true : false);
+        if (renewalViewList.isEmpty()) {
+            gptStandbyResp.setIsHasAccount(false);
+            return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
+        }
+
+        List<RenewalView> overTen = new ArrayList<>();
+        List<RenewalView> underTen = new ArrayList<>();
+        DateTime now = DateTime.now();
+        renewalViewList.forEach(e -> {
+            if (e.getExpiryTime().compareTo(DateUtil.offsetDay(now, 10)) > 0) {
+                overTen.add(e);
+            } else underTen.add(e);
+        });
+
+        Integer accountBlockedCount = 1;
+        if (overTen.size() > 1) {
+            List<String> accountList = overTen.stream().map(RenewalView::getAccount).distinct().collect(Collectors.toList());
+            accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
+                    .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
+                    .in(AccountBlockedReplaceRecord::getAccount, accountList));
+        }
+        if (accountBlockedCount > 1) {
+            gptStandbyResp.setIsHasAccount(false);
+            return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
         }
+        gptStandbyResp.setIsHasAccount(true);
+        gptStandbyResp.setOverTen(overTen);
+        gptStandbyResp.setUnderTen(underTen);
+        Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
+                .in(GptTicketStandby::getUserId, relationUserIdList));
+        gptStandbyResp.setIsApply(count > 0 ? true : false);
         return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
     }
 
@@ -623,13 +651,15 @@ public class GroupRelationController {
     public Result<Boolean> applyGptStandby() {
         long userId = StpUserUtil.getLoginIdAsLong();
         List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
-        Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
+        String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
+        List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
                 .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
                 .field(RenewalView::getGoodsId, 26)
-                .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
+                .put("condition", condition)
                 .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
+                .onlySelect(RenewalView::getAccount)
                 .build());
-        if (number.intValue() == 0) {
+        if (renewalViewList.isEmpty()) {
             throw BusinessRuntimeException.getInstance("你未有车票账号");
         }
         Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
@@ -637,10 +667,19 @@ public class GroupRelationController {
         if (count > 0) {
             throw BusinessRuntimeException.getInstance("你已申请车票账号候补");
         }
+        if (renewalViewList.size() > 1) {
+            Set<String> accountSet = renewalViewList.stream().map(RenewalView::getAccount).collect(Collectors.toSet());
+            Integer accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
+                    .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
+                    .in(AccountBlockedReplaceRecord::getAccount, accountSet));
+            if (accountBlockedCount > 1) {
+                return GatewayResponse.SUCCESS.newBuilder().toResult(true);
+            }
+        }
         GptTicketStandby gptTicketStandby = new GptTicketStandby();
         gptTicketStandby.setUserId(userId);
         gptTicketStandbyMapper.insert(gptTicketStandby);
-        return GatewayResponse.SUCCESS.newBuilder().toResult(number.intValue() > 0 ? true : false);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(true);
     }
 
     /**
@@ -651,11 +690,12 @@ public class GroupRelationController {
     public Result<String> ticketRefundOrders(@PathVariable Long relationId) throws Exception {
         long userId = StpUserUtil.getLoginIdAsLong();
         List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
+        String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
         RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
                 .field(RenewalView::getRelationId, relationId)
                 .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
+                .put("condition", condition)
                 .field(RenewalView::getGoodsId, 26)
-                .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
                 .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.LessEqual)
                 .build());
         if (renewalView == null) {

+ 33 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -110,6 +110,8 @@ public class CmsAccountController {
 
 	private final SysEmailMapper sysEmailMapper;
 
+	private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@GetMapping("/get")
@@ -1189,4 +1191,35 @@ public class CmsAccountController {
 		sysEmailMapper.deleteById(id);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
+
+	/**
+	 * 批量导入被封禁平台账号
+	 */
+	@PostMapping("/batch/import/blocked")
+	public Result<String> batchImportBlockedAccount(MultipartFile file, Long goodsId) throws IOException {
+		Assert.notNull(goodsId, "请选择对应平台");
+		List<Object> accountBlockedList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync();
+		accountService.batchImportBlockedAccount(goodsId, accountBlockedList);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 删除封禁平台账号
+	 */
+	@DeleteMapping("/delete/blocked/{id}")
+	public Result<String> deleteBlockedAccount(@PathVariable Long id) throws IOException {
+		accountBlockedReplaceRecordMapper.deleteById(id);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 被封禁账号列表
+	 */
+	@GetMapping("/get/blocked")
+	public Result<SearchResult<AccountBlockedReplaceRecord>> getBlockedAccount() {
+		SearchResult<AccountBlockedReplaceRecord> search = beanSearcher.search(AccountBlockedReplaceRecord.class, MapUtils.flatBuilder(request.getParameterMap())
+				.orderBy(AccountBlockedReplaceRecord::getId).desc()
+				.build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
 }