Browse Source

feat(shop): 添加分销商用户批量导入功能

- 新增 ShopDealerUserImportParam 类用于导入参数
- 在 ShopDealerUserController 中添加 importBatch 方法处理批量导入
- 使用 EasyPOI 库进行 Excel 导入
- 导入过程中设置默认值并保存用户信息
pan
科技小王子 4 weeks ago
parent
commit
3aa5f2738a
  1. 43
      src/main/java/com/gxwebsoft/shop/controller/ShopDealerUserController.java
  2. 70
      src/main/java/com/gxwebsoft/shop/param/ShopDealerUserImportParam.java

43
src/main/java/com/gxwebsoft/shop/controller/ShopDealerUserController.java

@ -1,9 +1,14 @@
package com.gxwebsoft.shop.controller; package com.gxwebsoft.shop.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.util.ObjectUtil;
import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.service.ShopDealerUserService; import com.gxwebsoft.shop.service.ShopDealerUserService;
import com.gxwebsoft.shop.entity.ShopDealerUser; import com.gxwebsoft.shop.entity.ShopDealerUser;
import com.gxwebsoft.shop.param.ShopDealerUserParam; import com.gxwebsoft.shop.param.ShopDealerUserParam;
import com.gxwebsoft.shop.param.ShopDealerUserImportParam;
import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
@ -13,7 +18,9 @@ import com.gxwebsoft.common.system.entity.User;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -125,4 +132,40 @@ public class ShopDealerUserController extends BaseController {
return fail("删除失败"); return fail("删除失败");
} }
@PreAuthorize("hasAuthority('shop:shopDealerUser:save')")
@Operation(summary = "批量导入分销商用户")
@Transactional(rollbackFor = {Exception.class})
@PostMapping("/import")
public ApiResult<List<String>> importBatch(MultipartFile file) {
ImportParams importParams = new ImportParams();
try {
List<ShopDealerUserImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(), ShopDealerUserImportParam.class, importParams);
list.forEach(d -> {
ShopDealerUser item = JSONUtil.parseObject(JSONUtil.toJSONString(d), ShopDealerUser.class);
assert item != null;
if (ObjectUtil.isNotEmpty(item)) {
// 设置默认值
if (item.getIsDelete() == null) {
item.setIsDelete(0);
}
if (item.getSortNumber() == null) {
item.setSortNumber(0);
}
// 记录当前登录用户id(如果没有指定userId)
if (item.getUserId() == null) {
User loginUser = getLoginUser();
if (loginUser != null) {
item.setUserId(loginUser.getUserId());
}
}
shopDealerUserService.save(item);
}
});
return success("成功导入" + list.size() + "条", null);
} catch (Exception e) {
e.printStackTrace();
}
return fail("导入失败", null);
}
} }

70
src/main/java/com/gxwebsoft/shop/param/ShopDealerUserImportParam.java

@ -0,0 +1,70 @@
package com.gxwebsoft.shop.param;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 分销商用户导入参数
*
* @author 科技小王子
* @since 2025-08-11 23:51:41
*/
@Data
public class ShopDealerUserImportParam implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "用户ID")
private Integer userId;
@Excel(name = "姓名")
private String realName;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "支付密码")
private String payPassword;
@Excel(name = "当前可提现佣金")
private BigDecimal money;
@Excel(name = "已冻结佣金")
private BigDecimal freezeMoney;
@Excel(name = "累积提现佣金")
private BigDecimal totalMoney;
@Excel(name = "推荐人用户ID")
private Integer refereeId;
@Excel(name = "成员数量(一级)")
private Integer firstNum;
@Excel(name = "成员数量(二级)")
private Integer secondNum;
@Excel(name = "成员数量(三级)")
private Integer thirdNum;
@Excel(name = "专属二维码")
private String qrcode;
@Excel(name = "排序号")
private Integer sortNumber;
@Excel(name = "是否删除")
private Integer isDelete;
@Excel(name = "租户ID")
private Integer tenantId;
@Excel(name = "创建时间")
private LocalDateTime createTime;
@Excel(name = "修改时间")
private LocalDateTime updateTime;
}
Loading…
Cancel
Save