“mitao”
2026-01-05 f07aabaf30a9a73f0da21c6b7ed31577d1f6f93f
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
@@ -132,10 +132,14 @@
        }
        TAppUser appUser = appUserService.getById(dto.getId());
        String code = appUser.getCode();
        if (dto.getCode() != null && !dto.getCode().isEmpty() && !code.equals(dto.getCode())) {
        if(code==null){
            appUser.setCode(dto.getCode());
            // 移除之前的二维码
            redisTemplate.delete("USER_WX_IMG" + appUser.getId());
        }else {
            if (dto.getCode() != null && !dto.getCode().isEmpty() && !dto.getCode().equals(code)) {
                appUser.setCode(dto.getCode());
                // 移除之前的二维码
                redisTemplate.delete("USER_WX_IMG" + appUser.getId());
            }
        }
        if (dto.getPromotionStatus() != null) {
            appUser.setPromotionStatus(dto.getPromotionStatus());
@@ -167,6 +171,35 @@
            tAppUserVo.setReferrerUser(appUserService.getById(appUser.getReferrerUserId()));
        }
        return R.ok(tAppUserVo);
    }
    @ApiOperation(value = "小程序用户金币导入模板下载")
    @GetMapping("/import-template_gold")
    public void importTemplateGold() {
        List<AppUserGoldImport> imports = new ArrayList<>();
        AppUserGoldImport goldImport = new AppUserGoldImport();
        imports.add(goldImport);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AppUserGoldImport.class, imports);
        HttpServletResponse response = WebUtils.response();
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("金币导入模板.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("金币导入模板下载失败!");
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
@@ -244,6 +277,36 @@
    }
    @ApiOperation(value = "小程序用户导入模板下载")
    @GetMapping("/import-template_user")
    public void importTemplate() {
        List<AppUserImport> imports = new ArrayList<>();
        AppUserImport appUserImport = new AppUserImport();
        imports.add(appUserImport);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AppUserImport.class, imports);
        HttpServletResponse response = WebUtils.response();
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("小程序用户导入模板.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("小程序用户导入模板下载失败!");
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @Log(title = "小程序用户-用户导入", businessType = BusinessType.IMPORT)
    @ApiOperation(value = "小程序用户-用户导入")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
@@ -290,6 +353,10 @@
                result.append("第" + i + "行:[", "出生日期" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getPromotion())) {
                result.append("第" + i + "行:[", "推广权限" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getRole())) {
                result.append("第" + i + "行:[", "角色" + "]不能为空");
                continue;
@@ -317,6 +384,13 @@
                continue;
            }
            String promotion = appUserImport.getPromotion();
            Integer promotionType = "是".equals(promotion) ? 1 : "否".equals(promotion) ? 0 : null;
            if (promotionType == null) {
                result.append("第" + i + "行:[", "推广权限" + "]格式错误");
                continue;
            }
            String birth = appUserImport.getBirth();
            LocalDate birthday = null;
            try {
@@ -340,6 +414,7 @@
            tAppUser.setGender(gender);
            tAppUser.setBirthday(birthday);
            tAppUser.setUserType(userType);
            tAppUser.setPromotionStatus(promotionType);
            if (appUserImport.getReferrerCode() != null) {
                TAppUser referrerUser = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getCode, appUserImport.getReferrerCode()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
@@ -355,7 +430,7 @@
            if (one != null) {
                tAppUser.setCompanyId(one.getId());
            }
            appUserService.save(user);
            appUserService.save(tAppUser);
            i++;
        }
        if (!result.isEmpty()) {