From 2a6f08facd68df8fae5e43e3d9fbaa9e7237a7f5 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 24 十一月 2025 17:00:38 +0800
Subject: [PATCH] 小程序接口
---
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/PartyBuildingController.java | 142 +++++++++++++++++++++++++++++++++++
ruoyi-system/src/main/java/com/ruoyi/system/dto/UpdateUserDto.java | 32 ++++++++
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/UserIndexController.java | 41 ++++++++++
ruoyi-system/src/main/java/com/ruoyi/system/model/TAppUser.java | 3
4 files changed, 218 insertions(+), 0 deletions(-)
diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/PartyBuildingController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/PartyBuildingController.java
index 731e582..f7c8079 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/PartyBuildingController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/PartyBuildingController.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.deepoove.poi.XWPFTemplate;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.model.TPartyBuilding;
import com.ruoyi.system.query.PartyBuildingListQuery;
@@ -9,7 +10,25 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.*;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+import static com.ruoyi.web.controller.common.ExcelExportExample.example1;
@Slf4j
@RestController
@@ -43,5 +62,128 @@
partyBuildingService.updateById(partyBuilding);
return R.ok(partyBuilding);
}
+ // 默认模板路径 - 根据实际情况修改
+ private static final String DEFAULT_TEMPLATE_PATH = "F:\\code\\mobile_community\\ruoyi-applet\\src\\main\\resources\\11.xlsx";
+ /**
+ * 导出Excel文件
+ */
+ @PostMapping("/excel")
+ public ResponseEntity<?> exportExcel() {
+ try {
+ // 使用提供的模板路径或默认路径
+ String templatePath = DEFAULT_TEMPLATE_PATH;
+
+ // 生成Excel文件字节数据
+ byte[] excelData = createExcelFromTemplate(templatePath, generateTestData());
+
+ // 创建资源对象
+ ByteArrayResource resource = new ByteArrayResource(excelData);
+
+ // 设置文件名
+ String filename = "export_data.xlsx";
+
+ HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
+ return ResponseEntity.ok()
+ .headers(headers)
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
+ .body(resource);
+
+
+ } catch (Exception e) {
+ throw new RuntimeException("导出Excel文件失败: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * 基于模板创建Excel文件
+ */
+ private byte[] createExcelFromTemplate(String templatePath, List<List<Object>> dataList)
+ throws IOException {
+
+ try (FileInputStream templateStream = new FileInputStream(templatePath);
+ Workbook workbook = WorkbookFactory.create(templateStream);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+
+ Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
+
+ // 从第四行开始填充数据(行索引从0开始,第四行索引为3)
+ fillDataToSheet(sheet, dataList, 3);
+
+ // 写入输出流
+ workbook.write(outputStream);
+ return outputStream.toByteArray();
+ }
+ }
+
+ /**
+ * 填充数据到工作表
+ */
+ private void fillDataToSheet(Sheet sheet, List<List<Object>> dataList, int startRowIndex) {
+ if (dataList == null || dataList.isEmpty()) {
+ return;
+ }
+
+ for (int i = 0; i < dataList.size(); i++) {
+ Row row = sheet.createRow(startRowIndex + i);
+ List<Object> rowData = dataList.get(i);
+
+ // 确保每行有22列数据
+ for (int j = 0; j < 22; j++) {
+ Cell cell = row.createCell(j);
+ Object value = j < rowData.size() ? rowData.get(j) : "";
+ setCellValue(cell, value);
+ }
+ }
+ }
+
+ /**
+ * 设置单元格值
+ */
+ private void setCellValue(Cell cell, Object value) {
+ if (value == null) {
+ cell.setCellValue("");
+ } else if (value instanceof String) {
+ cell.setCellValue((String) value);
+ } else if (value instanceof Integer) {
+ cell.setCellValue((Integer) value);
+ } else if (value instanceof Double) {
+ cell.setCellValue((Double) value);
+ } else if (value instanceof Boolean) {
+ cell.setCellValue((Boolean) value);
+ } else if (value instanceof Long) {
+ cell.setCellValue((Long) value);
+ } else {
+ cell.setCellValue(value.toString());
+ }
+ }
+
+ /**
+ * 生成测试数据
+ */
+ private List<List<Object>> generateTestData() {
+ List<List<Object>> dataList = new java.util.ArrayList<>();
+
+ // 生成5行测试数据
+ for (int i = 1; i <= 5; i++) {
+ List<Object> row = new java.util.ArrayList<>();
+
+ // 22列测试数据
+ row.add("数据" + i + "-1");
+ row.add("数据" + i + "-2");
+ row.add(i * 100);
+ row.add(i * 50.5);
+ row.add(i % 2 == 0);
+
+ // 填充剩余列
+ for (int j = 5; j < 22; j++) {
+ row.add("值" + i + "-" + (j + 1));
+ }
+
+ dataList.add(row);
+ }
+
+ return dataList;
+ }
}
diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/UserIndexController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/UserIndexController.java
index 75422ad..fae247d 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/UserIndexController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/UserIndexController.java
@@ -10,6 +10,7 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.UpdatePhoneDto;
+import com.ruoyi.system.dto.UpdateUserDto;
import com.ruoyi.system.model.TAppUser;
import com.ruoyi.system.model.TAppealServices;
import com.ruoyi.system.model.TChildcareServices;
@@ -132,4 +133,44 @@
return R.ok();
}
+
+ @ApiOperation(value = "个人中心--修改信息")
+ @PostMapping(value = "/updateUserInfo")
+ public R<?> updateUserInfo(@RequestBody UpdateUserDto dto) {
+ String userId = tokenService.getLoginUserApplet().getUserId();
+ TAppUser appUser = tAppUserService.getById(userId);
+
+ if(dto.getAvatar()!=null){
+ appUser.setAvatar(dto.getAvatar());
+ }
+
+ if(dto.getNickName()!=null){
+ appUser.setNickName(dto.getNickName());
+ }
+
+ if(dto.getGender()!=null){
+ appUser.setGender(dto.getGender());
+ }
+
+ if(dto.getBirthday()!=null){
+ appUser.setBirthDate(dto.getBirthday());
+ }
+
+ if(dto.getName()!=null){
+ appUser.setName(dto.getName());
+ }
+
+
+ if(dto.getPhone()!=null){
+ long count = tAppUserService.count(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhoneNumber, dto.getPhone()).ne(TAppUser::getId, userId));
+ if (count > 0) {
+ return R.fail("手机号已存在");
+ }
+ appUser.setPhoneNumber(dto.getPhone());
+ }
+ tAppUserService.updateById(appUser);
+
+ return R.ok();
+ }
+
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/UpdateUserDto.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/UpdateUserDto.java
new file mode 100644
index 0000000..b5c9a3c
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/UpdateUserDto.java
@@ -0,0 +1,32 @@
+package com.ruoyi.system.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDate;
+
+@Data
+@ApiModel("修改用户信息dto")
+public class UpdateUserDto {
+ @ApiModelProperty("头像")
+ private String avatar;
+
+
+ @ApiModelProperty("用户名")
+ private String name;
+
+ @ApiModelProperty("昵称")
+ private String nickName;
+
+ @ApiModelProperty("1:男,2:女")
+ private Integer gender;
+
+ @ApiModelProperty("生日")
+ @JsonFormat(pattern = "yyyy-MM-dd")
+ private LocalDate birthday;
+ @ApiModelProperty("手机号")
+ private String phone;
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/model/TAppUser.java b/ruoyi-system/src/main/java/com/ruoyi/system/model/TAppUser.java
index 71318b3..f1bf571 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/model/TAppUser.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/model/TAppUser.java
@@ -34,6 +34,9 @@
@ApiModelProperty(value = "用户昵称")
@TableField("nick_name")
private String nickName;
+ @ApiModelProperty(value = "用户名")
+ @TableField("name")
+ private String name;
@ApiModelProperty(value = "头像")
@TableField("avatar")
--
Gitblit v1.7.1