zoujiajian 2 роки тому
батько
коміт
50d09ae0cb

+ 21 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelPrepareAccountData.java

@@ -0,0 +1,21 @@
+package com.cyksj.model.excel;
+
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.ejlchina.searcher.bean.DbField;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ExcelPrepareAccountData {
+
+    @ExcelProperty("账号")
+    private String account;
+
+    /**
+     * 省份
+     */
+    @ExcelProperty("密码")
+    private String password;
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/model/request/AccountPrepareReq.java

@@ -0,0 +1,13 @@
+package com.cyksj.model.request;
+
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class AccountPrepareReq {
+    private Long goodsId;
+
+    private String preSkuIds;
+}

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

@@ -28,6 +28,7 @@ import com.cyksj.model.excel.*;
 import com.cyksj.model.manage.request.ReqAccountIncrExpiryTime;
 import com.cyksj.model.manage.views.AccountView;
 import com.cyksj.model.manage.views.GroupsRelationView;
+import com.cyksj.model.request.AccountPrepareReq;
 import com.cyksj.model.response.ExpiredAccountRep;
 import com.cyksj.model.response.OrderDonAccountRep;
 import com.cyksj.model.views.*;
@@ -962,6 +963,64 @@ public class CmsAccountController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(repeat);
 	}
 
+	/**
+	 * 导入备用账号模板
+	 */
+	@GetMapping("/export/prepare/template")
+	public void getPrepareTemplate(HttpServletResponse response) {
+		EasyExcelUtils.createTemplateExcel(response, ExcelPrepareAccountData.class, "导入备用账号模板", "导入备用账号模板", ExcelTypeEnum.XLSX, null);
+	}
+
+	/**
+	 * 批量导入备用账号
+	 */
+	@PostMapping("/batch/import/prepare")
+	public Result<String> batchImportPrepare(Long goodsId, String preSkuIds, MultipartFile file) throws IOException {
+		if (goodsId == null) {
+			throw BusinessRuntimeException.getInstance("请选择对应平台");
+		}
+		if (goodsId == 26) {
+			if (StrUtil.isEmpty(preSkuIds)) {
+				throw BusinessRuntimeException.getInstance("请选择对应规格id");
+			}
+			String[] split = preSkuIds.split(",");
+			preSkuIds = Arrays.stream(split).distinct().collect(Collectors.joining(","));
+		}
+		final String f_skuIds = preSkuIds;
+		EasyExcel.read(file.getInputStream(), ExcelPrepareAccountData.class, new AnalysisEventListener<ExcelPrepareAccountData>() {
+			@Override
+			public void invoke(ExcelPrepareAccountData data, AnalysisContext analysisContext) {
+				String account = data.getAccount();
+				String password = data.getPassword();
+				if (StrUtil.isEmpty(account) || StrUtil.isEmpty(password)) {
+					return;
+				}
+				Account insert = new Account();
+				insert.setAccount(account.trim());
+				insert.setPassword(password.trim());
+				insert.setGoodsId(goodsId);
+				insert.setPreSkuIds(f_skuIds);
+				insert.setType(2);
+				insert.setStartTime(DateTime.now());
+				insert.setExpiryTime(DateUtil.offsetMonth(DateTime.now(), 1));
+				//账号是否已经添加过
+				if (!insert.getAccount().contains("客服")) {
+					if (accountCommonService.checkIsDupAccount(insert.getGoodsId(), insert.getAccount())) {
+						return;
+					}
+				}
+				insert.setType(2);
+				accountService.save(insert);
+			}
+
+			@Override
+			public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+			}
+		}).sheet().doRead();
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
 	/**
 	 * 新增预备账号
 	 */