From 74f666605450658b86e1b5ca076500aa341b6f49 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期二, 22 七月 2025 13:59:09 +0800
Subject: [PATCH] yml活动管理代码

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java |  121 +++++++++++++++++++++++++++++++++++----
 1 files changed, 107 insertions(+), 14 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
index 704a60f..1254c44 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -39,14 +39,23 @@
 import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Value;
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
@@ -105,6 +114,12 @@
         return appUserService.mobileLogin(mobileLogin);
     }
 
+    @ResponseBody
+    @PostMapping("/registerAccount")
+    @ApiOperation(value = "注册新账号")
+    public R<LoginVo> registerAccount(@RequestBody RegisterAccount registerAccount) {
+        return appUserService.registerAccount(registerAccount);
+    }
 
     @GetMapping("/logout")
     @ApiOperation(value = "登出")
@@ -127,6 +142,11 @@
     public AppUser getAppUserById(@RequestParam("id") Long id) {
         System.out.println("根据id获取用户:"+id);
         return appUserService.getById(id);
+    }
+    // 获取所有用户
+    @PostMapping("/getAppUserAll")
+    public List<AppUser> getAppUserAll() {
+        return appUserService.list();
     }
 
     @PostMapping("/getBaseUserById")
@@ -519,11 +539,10 @@
         userStatistics.setTotalUser(appUserList.size());//总用户数
         userStatistics.setConsumerUser((int) consumerUser);//消费过的用户
 
-        //用户类型统计门店
-        long shopUserCount = appUserList.stream()
-                .filter(appUser -> appUser.getUserType() == 2)
-                .count();
-        userStatistics.setShopUser((int) shopUserCount);
+        //拥有店铺用户数
+        Integer shopUserCount = appUserShopService.getHaveShopUserNum();
+
+        userStatistics.setShopUser(shopUserCount);
 
         //门店总数
         long shopNum = shopClient.getAllShop().getData().size();
@@ -552,12 +571,19 @@
         if (result == null || result.get("total_points") == null) {
             userStatistics.setTotalScore(0L);
         }else {
-            userStatistics.setTotalScore((Long) result.get("total_points"));
+            userStatistics.setTotalScore(((BigDecimal) result.get("total_points")).longValue());
         }
-
-        //统计消费积分和现金支付数
-        Map<String, Object> data = orderClient.getConsumeScoreAndPayAmount(userId).getData();
-
+        //条件构造  消费积分现金支付金额
+        queryWrapper.clear();
+        QueryWrapper<AppUser> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.select("sum(exchange_point + transferable_out_point - cancel_point) as total_points");
+        queryWrapper1.select("sum(shop_amount) as payment_amounts ");
+        queryWrapper1.eq("del_flag", 0);//未删除的
+        queryWrapper1.ne("status", 3);//未注销的
+        if (userId != null) {
+            queryWrapper1.eq("id", userId);
+        }
+        Map<String, Object> data  = appUserShopService.getPointAndPayAmount(userId);
         if (data == null || data.get("total_points") == null) {
             userStatistics.setConsumeScore(0L);
         }else {
@@ -569,7 +595,6 @@
         }else {
             userStatistics.setShopAmount(new BigDecimal(data.get("payment_amounts").toString()));
         }
-
 
         return R.ok(userStatistics);
     }
@@ -611,7 +636,7 @@
      * @param file
      * @return
      */
-    @PostMapping("/upload")
+ /*   @PostMapping("/upload")
     public R upload(MultipartFile file){
         String s = null;
         try {
@@ -620,9 +645,77 @@
             throw new RuntimeException(e);
         }
         return R.ok(s);
+    }*/
+
+    private static final String FILE_DIRECTORY = "/var/files/ldf_files"; // Linux路径
+//    private static final String FILE_DIRECTORY = "E://ldf_files"; // Linux路径
+
+    @PostMapping("/upload")
+    public R handleFileUpload(@RequestParam("file") MultipartFile file) {
+        if (file.isEmpty()) {
+            return R.fail("请选择一个文件上传");
+        }
+        try {
+            // 1. 构建日期目录路径(格式:/年/月/日)
+            LocalDate today = LocalDate.now();
+            String datePath = String.format("/%d/%02d/%02d",
+                    today.getYear(), today.getMonthValue(), today.getDayOfMonth());
+
+            // 2. 完整目标目录路径
+            String fullDirPath = FILE_DIRECTORY + datePath;
+            File targetDir = new File(fullDirPath);
+
+            // 3. 自动创建目录(如果不存在)
+            if (!targetDir.exists()) {
+                targetDir.mkdirs(); // 递归创建所有父目录
+            }
+            String UUID= java.util.UUID.randomUUID().toString();
+            // 4. 保存文件
+            String filePath = fullDirPath + "/" +UUID+ file.getOriginalFilename();
+            File targetFile = new File(filePath);
+            file.transferTo(targetFile);
+            // 5. 返回可访问的URL(修正路径分隔符为Web格式)
+            return R.ok("http://zjrqxny.com/account/app-user/download" + datePath + "/" + UUID+file.getOriginalFilename());
+        } catch (IOException e) {
+            e.printStackTrace();
+            return R.fail("上传文件失败");
+        }
     }
-    
-    
+    @GetMapping("/download/{year}/{month}/{day}/{fileName:.+}")
+    @ResponseBody
+    public ResponseEntity<org.springframework.core.io.Resource> downloadFile( @PathVariable String year,
+                                                                              @PathVariable String month,
+                                                                              @PathVariable String day,
+                                                                              @PathVariable String fileName) {
+        System.out.println("下载文件名:"+fileName);
+        try {
+            // 1. 解码文件名
+            String decodedFileName = URLDecoder.decode(fileName, "UTF-8");
+
+
+            java.nio.file.Path filePath = java.nio.file.Paths.get(FILE_DIRECTORY, year, month, day, decodedFileName).normalize();
+            org.springframework.core.io.Resource resource = new org.springframework.core.io.UrlResource(filePath.toUri());
+            if (resource.exists() || resource.isReadable()) {
+                // 5. 设置下载头(兼容所有浏览器)
+                String contentDisposition = "attachment; filename=\"" + decodedFileName + "\"; " +
+                        "filename*=UTF-8''" + URLEncoder.encode(decodedFileName, "UTF-8").replace("+", "%20");
+
+                return ResponseEntity.ok()
+                        .contentType(MediaType.APPLICATION_OCTET_STREAM)
+                        .header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
+                        .body(resource);
+
+            } else {
+                return ResponseEntity.notFound().build();
+            }
+        } catch (IOException ex) {
+            ex.printStackTrace();
+            return ResponseEntity.status(500).build();
+        }
+    }
+
+
+
 
     /**
      * 清空绑定门店的用户门店数据

--
Gitblit v1.7.1