From 5a7486e9893a706ed464e3197c9711286b077896 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期四, 26 六月 2025 11:12:28 +0800 Subject: [PATCH] 文件导入 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 327 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 225 insertions(+), 102 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 9d7fac9..0f5f3f5 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 @@ -1,6 +1,7 @@ package com.ruoyi.account.controller; +import cn.hutool.http.HttpResponse; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -19,7 +20,9 @@ import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.order.feignClient.OrderClient; @@ -36,13 +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.*; @@ -57,7 +70,7 @@ * @author luodangjia * @since 2024-11-21 */ -@Api(tags = {"登录注册-小程序"}) +@Api(tags = {"用户端-小程序"}) @RestController @RequestMapping("/app-user") @Slf4j @@ -79,6 +92,8 @@ private OrderClient orderClient; @Resource private SysConfigClient sysConfigClient; + @Resource + private AppUserShopService appUserShopService; @Resource private UserCancellationLogService userCancellationLogService; @@ -99,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 = "登出") @@ -310,25 +331,10 @@ public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum, @ApiParam("每一页数据大小") Integer pageSize, AppUser appUser){ - - Long userid = tokenService.getLoginUser().getUserid(); - SysUser sysUser = sysUserClient.getSysUser(userid).getData(); Integer shopId = null; Set<Long> userId = null; - if(sysUser.getRoleType() == 2){ - shopId = sysUser.getObjectId(); - userId = orderClient.getAppUserByShoppingShop(shopId).getData(); - } - appUser.setExcludeStatus(3); IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId); - for (AppUser record : appuserPage.getRecords()) { - Shop shop1 = shopClient.getServiceProvider(record.getId()).getData(); - if(null != shop1){ - record.setShopName(shop1.getName()); - record.setShopId(shop1.getId()); - } - record.setTotalPoint(record.getUserTotalPoint()); - } + return R.ok(appuserPage); } @@ -362,14 +368,14 @@ record.setShopName(shopById.getData().getName()); } } - record.setTotalPoint(record.getUserTotalPoint()); + } return R.ok(appuserPage); } @GetMapping("/shop/getAppuserPage") - @ApiOperation(value = "用户列表", tags = {"门店后台"}) + @ApiOperation(value = "用户列表-在门店下过单的", tags = {"门店后台"}) public R<IPage<AppUser>> shopGetAppuserPage(@ApiParam("页码") @RequestParam Integer pageCurr, @ApiParam("每一页数据大小") Integer pageSize, AppUser appUser) { @@ -437,52 +443,19 @@ @GetMapping("/detail") @ApiOperation(value = "用户列表-详情", tags = {"管理后台"}) - public R<AppUser> detail(Long id, Integer shopId) { - Long userid = tokenService.getLoginUser().getUserid(); - SysUser sysUser = sysUserClient.getSysUser(userid).getData(); + public R<AppUser> detail(Long id) { AppUser byId = appUserService.getById(id); - Shop shop1 = shopClient.getServiceProvider(byId.getId()).getData(); - if(null != shop1){ - byId.setShopName(shop1.getName()); - byId.setShopId(shop1.getId()); + //获取店铺名称 + List<String> shopNames=shopClient.getServiceProvider(byId.getId()).getData(); + if(null != shopNames){ + byId.setShopNames(shopNames); } - R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id); - if (shopByUserId.getData() != null) { - List<String> shopName = new ArrayList<>(); - for (Shop datum : shopByUserId.getData()) { - shopName.add(datum.getName()); - } - byId.setShopNames(shopName); - } - //推广人 - /*if (byId.getInviteUserId() != null) { - AppUser appUser = appUserService.getById(byId.getInviteUserId()); - if(null != appUser){ - byId.setInviteUserName(appUser.getName()); - } - }*/ - //最后下单时间 - R<Order> lastOrder = remoteOrderGoodsClient.getLastOrder(id); - if (lastOrder.getData() != null) { - byId.setLastOrderTime(lastOrder.getData().getCreateTime()); - } - /*List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, id).list(); - byId.setBottomUsers(list);*/ //消费总金额 - if(null == shopId || 1 == sysUser.getRoleType()){ - shopId = -1; - } - if(null == shopId && 2 == sysUser.getRoleType()){ - shopId = sysUser.getObjectId(); - } - R<List<Order>> orderR = remoteOrderGoodsClient.byUserId(id, shopId); - List<Order> orderList = orderR.getData(); - if (!CollectionUtils.isEmpty(orderList)){ - BigDecimal paymentAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); - byId.setShopAmount(paymentAmount); - }else { - byId.setShopAmount(BigDecimal.ZERO); - } + Integer customPoint =(byId.getExchangePoint()==null?0:byId.getExchangePoint())+ + (byId.getTransferableOutPoint()==null?0:byId.getTransferableOutPoint())- + (byId.getCancelPoint()==null?0:byId.getCancelPoint()); + byId.setCustomPoint(customPoint); + return R.ok(byId); } @@ -543,50 +516,80 @@ /** - * 用户统计 + * 工作台-顶部 */ @GetMapping("/statistics") - @ApiOperation(value = "用户统计", tags = {"管理后台-首页统计-用户统计"}) + @ApiOperation(value = "统计", tags = {"后台-工作台-顶部"}) public R<UserStatistics> statistics() { - Long userId = tokenService.getLoginUser().getUserid(); - SysUser data = sysUserClient.getSysUser(userId).getData(); - QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>(); - if (data.getRoleType() == 2) { - Integer shopId = data.getObjectId(); - List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData(); - List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList()); - queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds); // userIds 不为空时,查询 id 在 userIds 中 - } queryWrapper.eq("del_flag", 0); - queryWrapper.ne("status", 3); - List<AppUser> appUserList = appUserService.list(queryWrapper); + queryWrapper.ne("status", 3);//没有注销的 - Map<Integer, Long> vipIdCountMap = appUserList.stream() - .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting())); + List<AppUser> appUserList = appUserService.list(queryWrapper); + long consumerUser = appUserList.stream() + .filter(user -> user.getLastShopTime() != null) + .count();//消费者总数 UserStatistics userStatistics = new UserStatistics(); - userStatistics.setTotalUser(appUserList.size()); - userStatistics.setConsumerUser(vipIdCountMap.getOrDefault(0, 0L).intValue() + - vipIdCountMap.getOrDefault(1, 0L).intValue() + - vipIdCountMap.getOrDefault(2, 0L).intValue() + - vipIdCountMap.getOrDefault(3, 0L).intValue()); - userStatistics.setCommonUser(vipIdCountMap.getOrDefault(1, 0L).intValue()); - userStatistics.setGoldUser(vipIdCountMap.getOrDefault(2, 0L).intValue()); - userStatistics.setDiamondUser(vipIdCountMap.getOrDefault(3, 0L).intValue()); - userStatistics.setEntrepreneurUser(vipIdCountMap.getOrDefault(4, 0L).intValue() + - vipIdCountMap.getOrDefault(5, 0L).intValue() + - vipIdCountMap.getOrDefault(6, 0L).intValue() + - vipIdCountMap.getOrDefault(7, 0L).intValue()); - userStatistics.setProxyUser(vipIdCountMap.getOrDefault(4, 0L).intValue()); - userStatistics.setAgentUser(vipIdCountMap.getOrDefault(5, 0L).intValue()); - userStatistics.setTotalAgentUser(vipIdCountMap.getOrDefault(6, 0L).intValue()); - userStatistics.setPartnerUser(vipIdCountMap.getOrDefault(7, 0L).intValue()); + 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(); + userStatistics.setShopNum((int) shopNum); + return R.ok(userStatistics); + } + + /** + * 工作台-用户分析 + */ + @GetMapping("/homeStatistics/userAnalysis") + @ApiOperation(value = "用户分析", tags = {"后台-工作台-用户分析"}) + public R<UserStatisticsDetail> userAnalysis(@ApiParam(value = "用户id") @RequestParam(value = "userId",required = false) Long userId) { + UserStatisticsDetail userStatistics = new UserStatisticsDetail(); + + QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>(); + // 条件构造 统计充值积分 + queryWrapper.select("SUM(recharge_point) as total_points"); + queryWrapper.eq("del_flag", 0);//未删除的 + queryWrapper.ne("status", 3);//未注销的 + if (userId != null) { + queryWrapper.eq("id", userId); + } + //统计充值积分 + Map<String, Object> result = appUserService.getMap(queryWrapper); + if (result == null || result.get("total_points") == null) { + userStatistics.setTotalScore(0L); + }else { + userStatistics.setTotalScore(((BigDecimal) result.get("total_points")).longValue()); + } + //条件构造 消费积分现金支付金额 + 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 { + userStatistics.setConsumeScore(Long.valueOf(data.get("total_points").toString()) ); + } + + if (data == null || data.get("payment_amounts") == null) { + userStatistics.setShopAmount(BigDecimal.ZERO); + }else { + userStatistics.setShopAmount(new BigDecimal(data.get("payment_amounts").toString())); + } return R.ok(userStatistics); } @@ -628,18 +631,86 @@ * @param file * @return */ - @PostMapping("/upload") - public String upload(MultipartFile file){ + /* @PostMapping("/upload") + public R upload(MultipartFile file){ String s = null; try { s = ObsUploadUtil.obsUpload(file); } catch (IOException e) { throw new RuntimeException(e); } - return s; + 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(); + } + } + + + /** * 清空绑定门店的用户门店数据 @@ -653,5 +724,57 @@ return R.ok(); } + + /** + * 获取所有用户积分列表 + */ + @ResponseBody + @GetMapping("/getUserPointPageList") + @ApiOperation(value = "所有用户积分列表", tags = "后台-财务统计-用户积分统计") + public R<PageInfo<UserPointStatisticsVO>> getUserPointPageList(@RequestParam(value = "name",required = false) String name, + @ApiParam("当前页")@RequestParam("pageCurr") Integer pageCurr, + @ApiParam("分页大小")@RequestParam("pageSize") Integer pageSize) { + PageInfo<UserPointStatisticsVO> pageInfo=appUserService.getUserPointPageList(name,pageCurr,pageSize); + + return R.ok(pageInfo); + } + + /** + * 导出用户积分列表 + */ + @ResponseBody + @GetMapping("/exportUserPoint") + @ApiOperation(value = "导出用户积分列表", tags = "后台-财务统计-用户积分统计") + public void exportUserPoint(HttpServletResponse response, @RequestParam(value = "name",required = false) String name) { + + List<UserPointStatisticsVO> exportList=appUserMapper.exportUserPoint(name); + ExcelUtil<UserPointStatisticsVO> util = new ExcelUtil<UserPointStatisticsVO>(UserPointStatisticsVO.class); + util.exportExcel(response, exportList, "用户积分汇总"); + } + + + @PostMapping("/saveOrUpdateAppUser") + Long saveOrUpdateAppUser(@RequestBody AppUser appuser){ + if (appuser.getId() == null) { + //保存用户 + appUserService.save(appuser); + }else { + appUserService.updateById(appuser); + } + return appuser.getId(); + + } + + @GetMapping("/getAllUser") + @ApiOperation(value = "获取所有用户") + public R<List<AppUser>> getAllUser() { + LambdaQueryWrapper<AppUser> queryWrapper=new LambdaQueryWrapper<>(); + queryWrapper.select(AppUser::getId,AppUser::getName); + queryWrapper.eq(AppUser::getDelFlag,0);//未删除的 + queryWrapper.ne(AppUser::getStatus, 3);//未注销的 + List<AppUser> list = appUserService.list(queryWrapper); + return R.ok(list); + } + } -- Gitblit v1.7.1