|
|
@@ -3,7 +3,12 @@ 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.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GroupsMapper;
|
|
|
@@ -11,20 +16,26 @@ import com.cyksj.mapper.HomeGroupMapper;
|
|
|
import com.cyksj.model.entity.Account;
|
|
|
import com.cyksj.model.entity.GroupsTrips;
|
|
|
import com.cyksj.model.entity.HomeGroup;
|
|
|
+import com.cyksj.model.excel.ExcelAccountTemplateData;
|
|
|
+import com.cyksj.model.excel.ExcelManageAccountData;
|
|
|
import com.cyksj.model.manage.request.ReqAccountIncrExpiryTime;
|
|
|
import com.cyksj.model.manage.views.AccountView;
|
|
|
import com.cyksj.service.mange.CmsAccountService;
|
|
|
+import com.cyksj.web.util.EasyExcelUtils;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -77,6 +88,73 @@ public class CmsAccountController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出账号
|
|
|
+ */
|
|
|
+ @GetMapping("/export/account")
|
|
|
+ public void exportAccount(Long userId, String nickName, String submitAccount, String expiryStartTime, String expiryEndTime, HttpServletResponse response) {
|
|
|
+ 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()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("暂无数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ mapBuilder.field(AccountView::getId, accountIds).op(Operator.InList);
|
|
|
+ }
|
|
|
+ List<ExcelManageAccountData> list = beanSearcher.searchAll(ExcelManageAccountData.class, mapBuilder.build());
|
|
|
+
|
|
|
+ EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelManageAccountData.class, list, "账号列表", "账号列表", ExcelTypeEnum.XLSX, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载导入模板
|
|
|
+ */
|
|
|
+ @GetMapping("/get/account/template")
|
|
|
+ public void getAccountTemplate(HttpServletResponse response) {
|
|
|
+ EasyExcelUtils.createTemplateExcel(response, ExcelAccountTemplateData.class, "账号导入模板", "账号导入模板", ExcelTypeEnum.XLSX, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入账号,修改密码
|
|
|
+ */
|
|
|
+ @PostMapping("/import/account")
|
|
|
+ public Result<String> importAccount(Long goodsId, MultipartFile file) throws Exception {
|
|
|
+ EasyExcel.read(file.getInputStream(), ExcelAccountTemplateData.class, new AnalysisEventListener<ExcelAccountTemplateData>() {
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void invoke(ExcelAccountTemplateData data, AnalysisContext analysisContext) {
|
|
|
+ if (StrUtil.isNotBlank(data.getAccount())) {
|
|
|
+ Account account = accountService.getOne(Wrappers.lambdaQuery(Account.class)
|
|
|
+ .eq(Account::getGoodsId, goodsId)
|
|
|
+ .eq(Account::getAccount, data.getAccount()));
|
|
|
+ if (account != null) {
|
|
|
+ if (StrUtil.isNotBlank(data.getPassword()) && !data.getPassword().equals(account.getPassword())) {
|
|
|
+ account.setPassword(data.getPassword());
|
|
|
+ if (data.getExpiryTime() != null) {
|
|
|
+ account.setExpiryTime(data.getExpiryTime());
|
|
|
+ }
|
|
|
+ accountService.updateById(account);
|
|
|
+ //发放模板消息
|
|
|
+ accountService.sendAccountTemplateMsg(account);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }).sheet().doRead();
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("导入成功");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/post")
|
|
|
public Result<String> add(@RequestBody Account account){
|
|
|
accountService.save(account);
|