|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.cyksj.web.controller.manage.account;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.AccountMapper;
|
|
|
+import com.cyksj.model.entity.Account;
|
|
|
+import com.cyksj.model.excel.ExcelPrepareAccountData;
|
|
|
+import com.cyksj.service.mange.AccountCommonService;
|
|
|
+import com.cyksj.web.util.EasyExcelUtils;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 项目名: yhlxj
|
|
|
+ * 文件名: AccountTempController
|
|
|
+ * 创建者: JavaZou
|
|
|
+ * 创建时间:2024/10/28 17:17
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("/manage/account/temp")
|
|
|
+@RestController
|
|
|
+public class AccountTempController {
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ private final AccountMapper accountMapper;
|
|
|
+
|
|
|
+ private final AccountCommonService accountCommonService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增临时账号
|
|
|
+ */
|
|
|
+ @PostMapping("/post")
|
|
|
+ public Result<String> post(@RequestBody Account account) {
|
|
|
+ accountMapper.insert(account);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑临时账号
|
|
|
+ */
|
|
|
+ @PutMapping("/post")
|
|
|
+ public Result<String> update(@RequestBody Account account) {
|
|
|
+ accountMapper.updateById(account);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 临时账号模板
|
|
|
+ */
|
|
|
+ @GetMapping("/export/temp/template")
|
|
|
+ public void getPrepareTemplate(HttpServletResponse response) {
|
|
|
+ EasyExcelUtils.createTemplateExcel(response, ExcelPrepareAccountData.class, "临时账号导入模板", "临时账号导入模板", ExcelTypeEnum.XLSX, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入临时账号
|
|
|
+ */
|
|
|
+ @PutMapping("/import")
|
|
|
+ public Result<String> batchImportPrepare(@RequestParam(defaultValue = "1") Long goodsId, MultipartFile file) throws IOException {
|
|
|
+ if (goodsId == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择对应平台");
|
|
|
+ }
|
|
|
+ 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.setType(3);
|
|
|
+ insert.setStartTime(DateTime.now());
|
|
|
+ if (data.getExpiryTime() != null) {
|
|
|
+ insert.setExpiryTime(DateUtil.parse(data.getExpiryTime()));
|
|
|
+ } else {
|
|
|
+ insert.setExpiryTime(DateUtil.offsetMonth(DateTime.now(), 1));
|
|
|
+ }
|
|
|
+ insert.setBankCard(data.getBankCard());
|
|
|
+ //辅助邮箱
|
|
|
+ insert.setEmail(data.getSecondEmail());
|
|
|
+ //关联邮箱
|
|
|
+ insert.setRelateEmail(data.getRelateEmail());
|
|
|
+ //账号是否已经添加过
|
|
|
+ if (!insert.getAccount().contains("客服")) {
|
|
|
+ if (accountCommonService.checkIsDupAccount(insert.getGoodsId(), insert.getAccount())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ accountMapper.insert(insert);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }).sheet().doRead();
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 临时账号列表
|
|
|
+ */
|
|
|
+ @PutMapping("/post")
|
|
|
+ public Result<SearchResult<Account>> get() {
|
|
|
+ SearchResult<Account> search = beanSearcher.search(Account.class, MapUtils.flatBuilder(request.getParameterMap()).field(Account::getType, 3).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+}
|