diff --git a/JY-Core/pom.xml b/JY-Core/pom.xml index 9ca2a6c5..4586bd91 100644 --- a/JY-Core/pom.xml +++ b/JY-Core/pom.xml @@ -193,6 +193,12 @@ httpclient + + org.apache.poi + poi-ooxml + 5.2.5 + + com.qiniu diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminExportController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminExportController.java new file mode 100644 index 00000000..aaf97c6b --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminExportController.java @@ -0,0 +1,47 @@ +package com.xiaowang.jayucloud.core.modules.manager.controller.admin; + +import com.xiaowang.jayucloud.core.annotation.RequirePermission; +import com.xiaowang.jayucloud.core.modules.manager.service.ManagerExportService; +import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; +import lombok.RequiredArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; + +@RestController +@RequestMapping("/admin") +@RequiredArgsConstructor +public class AdminExportController { + + private final ManagerExportService managerExportService; + private final AdminScopeHelper adminScopeHelper; + + @GetMapping("/export") + @RequirePermission("order:view") + public ResponseEntity export(HttpServletRequest request, + @RequestParam String type, + @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, + @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + byte[] content = managerExportService.export(currentUser, type, startDate, endDate); + String fileName = type + "_" + startDate + "_" + endDate + ".xlsx"; + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) + .header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment() + .filename(fileName, StandardCharsets.UTF_8) + .build() + .toString()) + .body(content); + } +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerEmployeeOrderController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerEmployeeOrderController.java new file mode 100644 index 00000000..00c90054 --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerEmployeeOrderController.java @@ -0,0 +1,41 @@ +package com.xiaowang.jayucloud.core.modules.manager.controller.admin; + +import com.xiaowang.jayucloud.core.annotation.RequirePermission; +import com.xiaowang.jayucloud.core.common.Result; +import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService; +import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO; +import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; +import lombok.RequiredArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.time.LocalDate; +import java.util.List; + +@RestController +@RequestMapping("/admin/manager/employees") +@RequiredArgsConstructor +public class AdminManagerEmployeeOrderController { + + private final PlanningService planningService; + private final AdminScopeHelper adminScopeHelper; + + @GetMapping("/{userId}/orders") + @RequirePermission("order:view") + public Result> orders(HttpServletRequest request, + @PathVariable Long userId, + @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, + @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + if (!adminScopeHelper.isPlatformAdmin(currentUser)) { + adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权查看其他店铺员工订单"); + } + return Result.success(planningService.getCalendar(currentUser, startDate, endDate, userId).getAppointments()); + } +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/service/ManagerExportService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/service/ManagerExportService.java new file mode 100644 index 00000000..b8b18c86 --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/service/ManagerExportService.java @@ -0,0 +1,194 @@ +package com.xiaowang.jayucloud.core.modules.manager.service; + +import com.xiaowang.jayucloud.core.common.vo.PageResultVO; +import com.xiaowang.jayucloud.core.modules.artist.dto.NailArtistInfoDTO; +import com.xiaowang.jayucloud.core.modules.artist.service.NailArtistInfoService; +import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService; +import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO; +import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningCalendarVO; +import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; +import com.xiaowang.jayucloud.core.modules.user.service.UserService; +import com.xiaowang.jayucloud.core.modules.user.vo.UserVO; +import lombok.RequiredArgsConstructor; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ManagerExportService { + + private static final String EXPORT_TYPE_ORDER = "订单数据"; + private static final String EXPORT_TYPE_CUSTOMER = "客户数据"; + private static final String EXPORT_TYPE_EMPLOYEE = "员工数据"; + private static final int EXPORT_LIMIT = 10000; + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + private final PlanningService planningService; + private final UserService userService; + private final NailArtistInfoService nailArtistInfoService; + private final AdminScopeHelper adminScopeHelper; + + public byte[] export(UserDO currentUser, String type, LocalDate startDate, LocalDate endDate) { + validateParams(type, startDate, endDate); + try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + if (EXPORT_TYPE_ORDER.equals(type)) { + writeOrders(workbook, currentUser, startDate, endDate); + } else if (EXPORT_TYPE_CUSTOMER.equals(type)) { + writeCustomers(workbook, currentUser); + } else if (EXPORT_TYPE_EMPLOYEE.equals(type)) { + writeEmployees(workbook, currentUser); + } else { + throw new RuntimeException("不支持的导出类型:" + type); + } + workbook.write(outputStream); + return outputStream.toByteArray(); + } catch (IOException error) { + throw new RuntimeException("生成 Excel 文件失败:" + error.getMessage(), error); + } + } + + private void validateParams(String type, LocalDate startDate, LocalDate endDate) { + if (!StringUtils.hasText(type)) { + throw new RuntimeException("导出类型不能为空"); + } + if (startDate == null || endDate == null) { + throw new RuntimeException("导出开始日期和结束日期不能为空"); + } + if (endDate.isBefore(startDate)) { + throw new RuntimeException("结束日期不能早于开始日期"); + } + } + + private void writeOrders(Workbook workbook, UserDO currentUser, LocalDate startDate, LocalDate endDate) { + PlanningCalendarVO calendar = planningService.getCalendar(currentUser, startDate, endDate, null); + Sheet sheet = createSheet(workbook, EXPORT_TYPE_ORDER, List.of("日期", "订单号", "客户", "手机号", "项目", "美甲师", "开始时间", "结束时间", "金额", "状态", "备注")); + List appointments = calendar.getAppointments() == null ? List.of() : calendar.getAppointments(); + int rowIndex = 1; + for (PlanningAppointmentVO appointment : appointments) { + Row row = sheet.createRow(rowIndex); + rowIndex++; + writeRow(row, List.of( + text(appointment.getDate()), + text(appointment.getOrderNo()), + text(appointment.getCustomerName()), + text(appointment.getCustomerPhone()), + text(appointment.getProductTitle()), + text(appointment.getArtistName()), + text(appointment.getStartTime()), + text(appointment.getEndTime()), + money(appointment.getAmount()), + text(appointment.getStatusText()), + text(appointment.getRemark()) + )); + } + sizeColumns(sheet, 11); + } + + private void writeCustomers(Workbook workbook, UserDO currentUser) { + Long shopId = adminScopeHelper.resolveShopScope(currentUser, null); + PageResultVO page = userService.pageUsers(1, EXPORT_LIMIT, null, shopId, 0); + Sheet sheet = createSheet(workbook, EXPORT_TYPE_CUSTOMER, List.of("客户", "账号", "手机号", "联系电话", "会员等级", "状态", "创建时间")); + List customers = page.getList() == null ? List.of() : page.getList(); + int rowIndex = 1; + for (UserVO customer : customers) { + Row row = sheet.createRow(rowIndex); + rowIndex++; + writeRow(row, List.of( + text(firstText(customer.getNickname(), customer.getAccount(), "客户")), + text(customer.getAccount()), + text(customer.getPhone()), + text(customer.getContactPhone()), + text(customer.getVipLevel()), + text(statusText(customer.getStatus())), + dateTime(customer.getCreateTime()) + )); + } + sizeColumns(sheet, 7); + } + + private void writeEmployees(Workbook workbook, UserDO currentUser) { + List employees = adminScopeHelper.isPlatformAdmin(currentUser) + ? nailArtistInfoService.getAllNailArtists() + : nailArtistInfoService.getByShopId(adminScopeHelper.resolveShopScope(currentUser, null)); + Sheet sheet = createSheet(workbook, EXPORT_TYPE_EMPLOYEE, List.of("员工", "手机号", "联系电话", "店铺", "身份", "排班模式", "排班时间", "状态")); + List employeeList = employees == null ? List.of() : employees; + int rowIndex = 1; + for (NailArtistInfoDTO employee : employeeList) { + Row row = sheet.createRow(rowIndex); + rowIndex++; + writeRow(row, List.of( + text(firstText(employee.getNickname(), "美甲师")), + text(employee.getPhone()), + text(employee.getContactPhone()), + text(employee.getShopName()), + text(employee.getIdentity()), + text(employee.getScheduleModeSummary()), + text(employee.getScheduleTimeSummary()), + text(statusText(employee.getStatus())) + )); + } + sizeColumns(sheet, 8); + } + + private Sheet createSheet(Workbook workbook, String sheetName, List headers) { + Sheet sheet = workbook.createSheet(sheetName); + Row header = sheet.createRow(0); + writeRow(header, headers); + return sheet; + } + + private void writeRow(Row row, List values) { + for (int index = 0; index < values.size(); index++) { + Cell cell = row.createCell(index); + cell.setCellValue(values.get(index)); + } + } + + private void sizeColumns(Sheet sheet, int columnCount) { + for (int index = 0; index < columnCount; index++) { + sheet.autoSizeColumn(index); + sheet.setColumnWidth(index, Math.min(Math.max(sheet.getColumnWidth(index), 2800), 12000)); + } + } + + private String firstText(String primary, String fallback) { + return StringUtils.hasText(primary) ? primary : fallback; + } + + private String firstText(String primary, String secondary, String fallback) { + if (StringUtils.hasText(primary)) { + return primary; + } + return StringUtils.hasText(secondary) ? secondary : fallback; + } + + private String text(Object value) { + return value == null ? "" : String.valueOf(value); + } + + private String money(BigDecimal value) { + return value == null ? "" : value.stripTrailingZeros().toPlainString(); + } + + private String dateTime(LocalDateTime value) { + return value == null ? "" : DATE_TIME_FORMATTER.format(value); + } + + private String statusText(Integer status) { + return Integer.valueOf(0).equals(status) ? "停用" : "启用"; + } +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java index cdfde3ac..0a7c678f 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java @@ -49,6 +49,7 @@ import com.xiaowang.jayucloud.core.utils.AccountValidationUtils; import com.xiaowang.jayucloud.core.support.security.OperationGuardStrategy; import lombok.Data; import lombok.RequiredArgsConstructor; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -954,6 +955,10 @@ public class UserController { @OperationGuard(action = "user-update-password", ttlSeconds = 10, message = "保存处理中,请勿重复提交") public Result updatePassword(HttpServletRequest request, @RequestBody PasswordDTO passwordDTO) { Long userId = (Long) request.getAttribute("userId"); + if (StringUtils.hasText(passwordDTO.getOldPassword())) { + boolean success = userService.updatePasswordWithOldPassword(userId, passwordDTO.getOldPassword(), passwordDTO.getPassword()); + return Result.success(success); + } boolean success = userService.updatePassword(userId, passwordDTO.getPassword(), passwordDTO.getVerificationCode()); return Result.success(success); } @@ -1059,6 +1064,7 @@ public class UserController { * Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state. */ private String password; + private String oldPassword; /** * Purpose: verificationCode supports UserController.java by holding or executing the verification code business role. * Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state. diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java index f8f20835..be3fccb9 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java @@ -402,6 +402,8 @@ public interface UserService extends IService { * @return boolean result consumed by the caller or returned to the frontend */ boolean updatePassword(Long userId, String password, String verificationCode); + + boolean updatePasswordWithOldPassword(Long userId, String oldPassword, String password); /** * Update an existing record. diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java index 52e409bd..afd044ed 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java @@ -2272,6 +2272,29 @@ public class UserServiceImpl extends ServiceImpl implements return updated; } + @Override + public boolean updatePasswordWithOldPassword(Long userId, String oldPassword, String password) { + UserDO userDO = userMapper.selectById(userId); + assertUserAvailable(userDO); + if (!StringUtils.hasText(oldPassword)) { + throw new RuntimeException("原密码不能为空"); + } + if (!StringUtils.hasText(userDO.getPassword())) { + throw new RuntimeException("当前账号未设置登录密码"); + } + if (!passwordEncoder.matches(oldPassword, userDO.getPassword())) { + throw new RuntimeException("原密码不正确"); + } + validatePasswordStrength(password); + userDO.setPassword(passwordEncoder.encode(password)); + userDO.setUpdateTime(LocalDateTime.now()); + boolean updated = userMapper.updateById(userDO) > 0; + if (updated) { + userSessionService.revokeAllUserSessions(userId); + } + return updated; + } + @Override /** * Update an existing record. diff --git a/JY-Salon-Front/src/api/client.ts b/JY-Salon-Front/src/api/client.ts index 16f4c8e2..50b2c7d3 100644 --- a/JY-Salon-Front/src/api/client.ts +++ b/JY-Salon-Front/src/api/client.ts @@ -18,12 +18,25 @@ const adminApi = axios.create({ headers: { 'Content-Type': 'application/json' } }) -const normalizeResponse = (response: { data: { code?: number; message?: string; data: T } }): T => { +interface ApiResponsePayload { + code?: number + message?: string + data: T +} + +const isApiResponsePayload = (payload: ApiResponsePayload | T): payload is ApiResponsePayload => ( + payload !== null && payload !== undefined && typeof payload === 'object' && 'data' in payload +) + +const normalizeResponse = (response: { config?: { responseType?: string }; data: ApiResponsePayload | T }): T => { + if (response.config?.responseType === 'blob' || response.config?.responseType === 'arraybuffer') { + return response.data as T + } const payload = response.data - if (payload && payload.code !== undefined && payload.code !== 200) { + if (isApiResponsePayload(payload) && payload.code !== undefined && payload.code !== 200) { throw new Error(payload.message || '请求失败') } - return payload.data as T + return isApiResponsePayload(payload) ? payload.data : payload } const handleExpired = async (): Promise => { diff --git a/JY-Salon-Front/src/api/managerEmployees.ts b/JY-Salon-Front/src/api/managerEmployees.ts index f13a021f..7d7ec9f7 100644 --- a/JY-Salon-Front/src/api/managerEmployees.ts +++ b/JY-Salon-Front/src/api/managerEmployees.ts @@ -8,6 +8,7 @@ import type { ArtistScheduleRuleSetting, EmployeeCreateRequest } from '@/types/manager' +import type { Appointment } from '@/types/manager' export interface ManagerDefaultPasswordResponse { password: string @@ -20,6 +21,9 @@ export const managerEmployeesApi = { detail(userId: IdType): Promise { return adminApi.get(`/manager/employees/${userId}`) }, + orders(userId: IdType, params: { startDate: string; endDate: string }): Promise { + return adminApi.get(`/manager/employees/${userId}/orders`, { params }) + }, save(data: Partial): Promise { return adminApi.post('/manager/employees', data) }, diff --git a/JY-Salon-Front/src/api/managerShop.ts b/JY-Salon-Front/src/api/managerShop.ts index 48a12dda..bb4f6bfc 100644 --- a/JY-Salon-Front/src/api/managerShop.ts +++ b/JY-Salon-Front/src/api/managerShop.ts @@ -16,5 +16,8 @@ export const managerShopApi = { }, exportPreview(params: { type: string; startDate: string; endDate: string }): Promise { return adminApi.get('/export', { params }) + }, + exportData(params: { type: string; startDate: string; endDate: string }): Promise { + return adminApi.get('/export', { params, responseType: 'blob' }) } } diff --git a/JY-Salon-Front/src/api/user.ts b/JY-Salon-Front/src/api/user.ts index 10dba598..df226d97 100644 --- a/JY-Salon-Front/src/api/user.ts +++ b/JY-Salon-Front/src/api/user.ts @@ -7,5 +7,8 @@ export const userApi = { }, update(data: Partial): Promise { return api.put('/user/info', data) + }, + updatePassword(data: { oldPassword: string; password: string }): Promise { + return api.put('/user/password', data) } } diff --git a/JY-Salon-Front/src/views/EmployeeOrdersView.vue b/JY-Salon-Front/src/views/EmployeeOrdersView.vue index a6f8339e..c499c2fb 100644 --- a/JY-Salon-Front/src/views/EmployeeOrdersView.vue +++ b/JY-Salon-Front/src/views/EmployeeOrdersView.vue @@ -1,10 +1,120 @@ + + diff --git a/JY-Salon-Front/src/views/ExportView.vue b/JY-Salon-Front/src/views/ExportView.vue index c57a9e6b..2d8d27a5 100644 --- a/JY-Salon-Front/src/views/ExportView.vue +++ b/JY-Salon-Front/src/views/ExportView.vue @@ -44,7 +44,7 @@
- +
@@ -60,6 +60,7 @@ import MobileShell from '@/components/MobileShell.vue' import { managerCustomersApi } from '@/api/managerCustomers' import { managerEmployeesApi } from '@/api/managerEmployees' import { managerPlanningApi } from '@/api/managerPlanning' +import { managerShopApi } from '@/api/managerShop' import { formatDate, startOfMonth } from '@/utils/date' import { useToastStore } from '@/stores/toast' import type { Appointment, Artist } from '@/types/manager' @@ -78,6 +79,7 @@ const previewColumns = ref([]) const previewRows = ref([]) const previewLoading = ref(false) const previewError = ref('') +const exporting = ref(false) const shortDateTime = (value: unknown): string => { const text = String(value || '') @@ -169,8 +171,35 @@ const loadPreview = async (): Promise => { } } -const exportExcel = (): void => { - toast.success('导出任务已创建') +const buildExportFileName = (): string => `${type.value}_${startDate.value}_${endDate.value}.xlsx` + +const downloadBlob = (blob: Blob): void => { + const url = URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = buildExportFileName() + document.body.appendChild(link) + link.click() + link.remove() + URL.revokeObjectURL(url) +} + +const exportExcel = async (): Promise => { + if (exporting.value) { + return + } + exporting.value = true + try { + const blob = await managerShopApi.exportData({ + type: type.value, + startDate: startDate.value, + endDate: endDate.value + }) + downloadBlob(blob) + toast.success('Excel 已开始下载') + } finally { + exporting.value = false + } } onMounted(loadPreview) diff --git a/JY-Salon-Front/src/views/PasswordView.vue b/JY-Salon-Front/src/views/PasswordView.vue index 0ddd2d18..9e22d8ec 100644 --- a/JY-Salon-Front/src/views/PasswordView.vue +++ b/JY-Salon-Front/src/views/PasswordView.vue @@ -18,7 +18,7 @@
- +
@@ -26,18 +26,31 @@ diff --git a/JY-Salon-WeChat/api/employees.js b/JY-Salon-WeChat/api/employees.js index d3d94d49..6b58c6f2 100644 --- a/JY-Salon-WeChat/api/employees.js +++ b/JY-Salon-WeChat/api/employees.js @@ -14,6 +14,13 @@ module.exports = { }) }, + orders(userId, params) { + return request({ + url: `/manager/employees/${userId}/orders`, + params + }) + }, + save(data) { return request({ url: '/manager/employees', diff --git a/JY-Salon-WeChat/api/shop.js b/JY-Salon-WeChat/api/shop.js index 0caa3b87..7b863180 100644 --- a/JY-Salon-WeChat/api/shop.js +++ b/JY-Salon-WeChat/api/shop.js @@ -1,4 +1,39 @@ const request = require('../utils/request') +const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config') + +function buildDownloadUrl(params) { + const query = Object.keys(params || {}) + .filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '') + .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`) + .join('&') + return `${ADMIN_API_BASE_URL}/export${query ? `?${query}` : ''}` +} + +function downloadFile(url, params) { + const header = request.buildSignatureHeaders({ + url: '/export', + requestUrl: url, + method: 'GET', + params + }) + return new Promise((resolve, reject) => { + wx.downloadFile({ + url, + header, + timeout: REQUEST_TIMEOUT, + success(response) { + if (response.statusCode >= 200 && response.statusCode < 300 && response.tempFilePath) { + resolve(response.tempFilePath) + return + } + reject(new Error(`导出 Excel 下载失败:HTTP ${response.statusCode}`)) + }, + fail(error) { + reject(new Error(`导出 Excel 下载失败:${error.errMsg || '网络异常'}`)) + } + }) + }) +} module.exports = { settings() { @@ -35,5 +70,10 @@ module.exports = { url: '/export', params }) + }, + + downloadExport(params) { + const url = buildDownloadUrl(params) + return downloadFile(url, params) } } diff --git a/JY-Salon-WeChat/api/user.js b/JY-Salon-WeChat/api/user.js index e71fe939..cfc30650 100644 --- a/JY-Salon-WeChat/api/user.js +++ b/JY-Salon-WeChat/api/user.js @@ -20,5 +20,16 @@ module.exports = { }, data }) + }, + + updatePassword(data) { + return request({ + url: '/user/password', + method: 'PUT', + params: { + __baseUrl: API_DOMAIN + }, + data + }) } } diff --git a/JY-Salon-WeChat/pages/employee-orders/index.js b/JY-Salon-WeChat/pages/employee-orders/index.js index 0d226b5e..d35dd846 100644 --- a/JY-Salon-WeChat/pages/employee-orders/index.js +++ b/JY-Salon-WeChat/pages/employee-orders/index.js @@ -1,10 +1,84 @@ +const dateUtil = require('../../utils/date') +const employeesApi = require('../../api/employees') + +function shortDate(value) { + return String(value || '').slice(0, 10) || '-' +} + +function timeRange(item) { + const start = String(item.startTime || '').slice(11, 16) + const end = String(item.endTime || '').slice(11, 16) + if (!start && !end) return '-' + return `${start || '-'}-${end || '-'}` +} + +function orderAmount(item) { + const value = item.amount !== undefined && item.amount !== null ? item.amount : item.manualProductPrice + if (value === undefined || value === null || value === '') return '0' + const amount = Number(value) + if (Number.isNaN(amount)) return String(value) + return amount.toFixed(2).replace(/\.00$/, '') +} + +function toOrderRow(item, index) { + return { + id: item.orderItemId || index, + date: item.date || shortDate(item.startTime), + project: item.productTitle || '预约作品', + customer: item.customerName || '到店客户', + artist: item.artistName || '未分配', + time: timeRange(item), + status: item.statusText || '-', + amount: orderAmount(item) + } +} + Page({ data: { - orders: [ - { id: 1, date: '2026-06-01', project: '纯色美甲', customer: '王女士', amount: 168 }, - { id: 2, date: '2026-05-31', project: '猫眼延长', customer: '陈女士', amount: 268 }, - { id: 3, date: '2026-05-30', project: '手部护理', customer: '林女士', amount: 98 } - ] + id: '', + startDate: dateUtil.formatDate(dateUtil.startOfMonth(new Date())), + endDate: dateUtil.formatDate(new Date()), + orders: [], + loading: false, + loadError: '' }, + + onLoad(options) { + this.setData({ id: options.id || '' }) + this.loadOrders() + }, + + onStartDate(event) { + this.setData({ startDate: event.detail.value }, () => this.loadOrders()) + }, + + onEndDate(event) { + this.setData({ endDate: event.detail.value }, () => this.loadOrders()) + }, + + async loadOrders() { + if (!this.data.id) { + this.setData({ orders: [], loadError: '员工ID不能为空' }) + return + } + this.setData({ loading: true, loadError: '' }) + try { + const list = await employeesApi.orders(this.data.id, { + startDate: this.data.startDate, + endDate: this.data.endDate + }) + this.setData({ + orders: (Array.isArray(list) ? list : []).map(toOrderRow) + }) + } catch (error) { + this.setData({ + orders: [], + loadError: error.message || '员工订单加载失败' + }) + } finally { + this.setData({ loading: false }) + } + }, + back() { wx.navigateBack() } }) diff --git a/JY-Salon-WeChat/pages/employee-orders/index.wxml b/JY-Salon-WeChat/pages/employee-orders/index.wxml index bb432ce4..7f00e2d9 100644 --- a/JY-Salon-WeChat/pages/employee-orders/index.wxml +++ b/JY-Salon-WeChat/pages/employee-orders/index.wxml @@ -1,9 +1,17 @@ - + + 开始日期{{startDate}} + 结束日期{{endDate}} + + 订单加载中... + {{loadError}} + 当前日期范围内没有订单 + {{item.project}} {{item.date}} · {{item.customer}} + {{item.artist}} · {{item.time}} · {{item.status}} ¥{{item.amount}} diff --git a/JY-Salon-WeChat/pages/employee-orders/index.wxss b/JY-Salon-WeChat/pages/employee-orders/index.wxss index a3fb2e06..b6718064 100644 --- a/JY-Salon-WeChat/pages/employee-orders/index.wxss +++ b/JY-Salon-WeChat/pages/employee-orders/index.wxss @@ -15,3 +15,10 @@ color: #6f8f83; font-weight: 900; } + +.order-meta { + display: block; + margin-top: 6rpx; + color: #8b8680; + font-size: 24rpx; +} diff --git a/JY-Salon-WeChat/pages/export/index.js b/JY-Salon-WeChat/pages/export/index.js index 11e12bb3..b9acb9f6 100644 --- a/JY-Salon-WeChat/pages/export/index.js +++ b/JY-Salon-WeChat/pages/export/index.js @@ -2,6 +2,7 @@ const dateUtil = require('../../utils/date') const planningApi = require('../../api/planning') const customersApi = require('../../api/customers') const employeesApi = require('../../api/employees') +const shopApi = require('../../api/shop') const PREVIEW_SIZE = 10 @@ -40,7 +41,8 @@ Page({ previewColumns: [], previewRows: [], previewLoading: false, - previewError: '' + previewError: '', + exporting: false }, onLoad() { @@ -131,7 +133,31 @@ Page({ }) }, - exportExcel() { wx.showToast({ title: '导出任务已创建', icon: 'none' }) }, + async exportExcel() { + if (this.data.exporting) { + return + } + this.setData({ exporting: true }) + try { + const filePath = await shopApi.downloadExport({ + type: this.data.type, + startDate: this.data.startDate, + endDate: this.data.endDate + }) + wx.openDocument({ + filePath, + fileType: 'xlsx', + showMenu: true, + fail(error) { + wx.showToast({ title: error.errMsg || 'Excel 打开失败', icon: 'none' }) + } + }) + } catch (error) { + wx.showToast({ title: error.message || 'Excel 导出失败', icon: 'none' }) + } finally { + this.setData({ exporting: false }) + } + }, back() { wx.navigateBack() } }) diff --git a/JY-Salon-WeChat/pages/export/index.wxml b/JY-Salon-WeChat/pages/export/index.wxml index 1b546e58..412903cd 100644 --- a/JY-Salon-WeChat/pages/export/index.wxml +++ b/JY-Salon-WeChat/pages/export/index.wxml @@ -42,5 +42,5 @@ - + diff --git a/JY-Salon-WeChat/pages/password/index.js b/JY-Salon-WeChat/pages/password/index.js index 1c9d8aee..ff11cb80 100644 --- a/JY-Salon-WeChat/pages/password/index.js +++ b/JY-Salon-WeChat/pages/password/index.js @@ -1,12 +1,48 @@ +const userApi = require('../../api/user') + +function clearSessionAndGoLogin() { + const app = getApp() + if (app && typeof app.clearSession === 'function') { + app.clearSession() + } + wx.reLaunch({ url: '/pages/login/index' }) +} + Page({ - data: { form: { oldPassword: '', newPassword: '', confirmPassword: '' } }, + data: { + form: { oldPassword: '', newPassword: '', confirmPassword: '' }, + saving: false + }, onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) }, - save() { + async save() { + if (this.data.saving) { + return + } + if (!this.data.form.oldPassword) { + wx.showToast({ title: '请填写原密码', icon: 'none' }) + return + } + if (!this.data.form.newPassword || !this.data.form.confirmPassword) { + wx.showToast({ title: '请填写新密码', icon: 'none' }) + return + } if (this.data.form.newPassword !== this.data.form.confirmPassword) { wx.showToast({ title: '两次密码不一致', icon: 'none' }) return } - wx.showToast({ title: '已提交' }) + this.setData({ saving: true }) + try { + await userApi.updatePassword({ + oldPassword: this.data.form.oldPassword, + password: this.data.form.newPassword + }) + wx.showToast({ title: '密码已修改', icon: 'success' }) + setTimeout(clearSessionAndGoLogin, 600) + } catch (error) { + wx.showToast({ title: error.message || '密码修改失败', icon: 'none' }) + } finally { + this.setData({ saving: false }) + } }, back() { wx.navigateBack() } }) diff --git a/JY-Salon-WeChat/pages/password/index.wxml b/JY-Salon-WeChat/pages/password/index.wxml index e1058c91..d626dd68 100644 --- a/JY-Salon-WeChat/pages/password/index.wxml +++ b/JY-Salon-WeChat/pages/password/index.wxml @@ -4,5 +4,5 @@ 新密码 确认密码 - + diff --git a/docs/运维配置与集成说明.md b/docs/运维配置与集成说明.md index bcfe4cf8..64903b4f 100644 --- a/docs/运维配置与集成说明.md +++ b/docs/运维配置与集成说明.md @@ -843,3 +843,9 @@ messagehub: - 处理方式:为 5 个 dataId 的每一条配置行补齐中文注释,仅调整注释文本,不修改配置值、缩进层级、路由顺序、列表顺序和敏感字段内容。 - 敏感信息要求:`secret.yaml` 中密码、token、access key、secret key 等只保留在 Nacos 配置中心,本文档和仓库不记录任何明文值。 - 验证方式:发布后通过 Nacos API 回读 5 个 dataId 并与本地注释版逐项比对,结果均为 `sameContent=true`;配置行与注释行数量分别为 `core.yaml 97/97`、`gateway.yaml 155/155`、`infra.yaml 87/87`、`secret.yaml 75/75`、`logging.yaml 6/6`。 + +### 2026-07-16 店务端 Excel 导出构建依赖 + +- `JY-Core` 管理端导出接口 `/admin/export` 使用 `org.apache.poi:poi-ooxml:5.2.5` 生成 `.xlsx` 文件。 +- 该能力只依赖 Maven 构建下载的 POI 依赖,不需要新增 Nacos 配置、数据库结构、权限种子或对象存储配置。 +- 发布验证时需确认 Core 构建成功,并通过店务端导出入口实际下载或打开 Excel 文件。 diff --git a/docs/项目变更记录.md b/docs/项目变更记录.md index 7c73968c..168131b9 100644 --- a/docs/项目变更记录.md +++ b/docs/项目变更记录.md @@ -197,3 +197,11 @@ - 网页发布:设计师端和店务端静态资源发布到 `aliyun01`,`/opt/jy-artist-frontend/current` 已切换到 `/opt/jy-artist-frontend/releases/20260716-005625/dist`;店务端继续保留在 `current/jy-salon-front`,`nginx -t` 与 reload 均通过。 - 影响范围:更新生产 Core、Gateway 和网页静态资源;不修改数据库、Nacos 配置、Nginx 配置、初始化 SQL 和小程序。 - 验证方式:6 个后端节点均为 `active`,实际 JAR SHA 与本地构建产物一致,本机 `/health/check` 均成功;公网 `https://yunail.art/health/check`、`https://salon.yunail.art/health/check`、设计师入口、店务入口和 `https://yunail.art/api/shop/list` 均返回 200;最近稳定窗口未检出 journal error 或 `Exception/ERROR/系统繁忙` 关键词。 + +## 2026-07-16 店务端改密、导出和员工订单真实能力补齐 + +- 变更原因:店务网页端与店务小程序的修改密码、导出 Excel、员工作品/订单仍停留在前端提示、预览占位或硬编码示例数据,不能形成真实业务闭环。 +- 处理方式:复用现有 `/user/password` 入口,新增原密码校验改密服务方法;新增 `/admin/export` 真实 Excel 下载接口并使用 Apache POI 生成 `.xlsx`;新增 `/admin/manager/employees/{userId}/orders` 员工订单查询接口,网页端和小程序均接入真实接口。 +- 依赖说明:`JY-Core` 新增 Maven 依赖 `org.apache.poi:poi-ooxml:5.2.5`,用于生成 Excel 工作簿;不新增数据库表、字段、权限种子或初始化 SQL。 +- 影响范围:影响 `JY-Core` 用户改密、管理端导出、员工订单查询,以及 `JY-Salon-Front`、`JY-Salon-WeChat` 对应页面;不修改 Gateway、Nacos、生产部署脚本和数据库结构。 +- 验证方式:执行 `JY-Core` 编译、店务网页端构建、小程序变更脚本语法检查,并在提交前运行 GitNexus `detect_changes` 确认影响范围。 diff --git a/memory/bugs.md b/memory/bugs.md index a8a59873..e161440a 100644 --- a/memory/bugs.md +++ b/memory/bugs.md @@ -1,5 +1,13 @@ # JayuCloud 踩坑与风险记忆 +## 2026-07-16 Web API Blob 响应拦截器需要显式类型守卫 + +- 问题:为店务网页端导出 Excel 增加 `responseType: 'blob'` 后,直接把 axios 归一化函数的响应类型扩成 `ApiPayload | T`,`vue-tsc` 报 `code/data/message` 属性不存在以及 `payload` 可能为 `null`。 +- 原因:普通 JSON 响应和 Blob 响应共用同一个响应拦截器;TypeScript 无法从运行时 `responseType` 分支推导后续 `payload` 一定是业务响应结构。 +- 处理方式:新增 `isApiResponsePayload` 类型守卫,先对 blob/arraybuffer 直接返回,再只在确认存在 `data` 字段时读取 `code/message/data`。 +- 以后避免:修改共享 axios 拦截器时,二进制响应必须先从归一化流程短路;业务 payload 字段读取必须走类型守卫,不能只依赖泛型联合类型。 +- 验证方式:执行对应网页端 `npm run build`,确认 `vue-tsc` 通过。 + ## AGENTS.md 中文读取需要指定 UTF-8 - 问题:直接读取 `AGENTS.md` 时,部分 PowerShell 输出会把中文显示成乱码。 diff --git a/memory/progress.md b/memory/progress.md index 85ca8a97..c072167a 100644 --- a/memory/progress.md +++ b/memory/progress.md @@ -2,20 +2,19 @@ ## 当前任务 -当前仓库代码生产发布。 +店务端小程序与网页端三项真实能力补齐:修改密码、导出 Excel、员工作品/订单。 ## 已完成 -- 已重新构建 `JY-Core`、`JY-Gateway`、`JY-Artist-Frontend` 和 `JY-Salon-Front`。 -- 已逐台确认生产 Core 实际运行 `/opt/jayu-cloud/core/JY-Core.jar`,Gateway 实际运行 `/opt/jayu-cloud/gateway/JY-Gateway.jar`。 -- 已滚动发布 3 台 Core 和 3 台 Gateway;Core SHA 前缀 `190BAAC97B66`,Gateway SHA 前缀 `F4348333F146`。 -- 已发布设计师端与店务端 Web 静态资源,`/opt/jy-artist-frontend/current` 指向 `/opt/jy-artist-frontend/releases/20260716-005625/dist`。 -- 已验证 6 个后端服务 active、本机健康检查通过、公网入口和关键静态资源均返回 200。 -- 已确认稳定后最近 3 分钟后端日志无 journal error,且无 `Exception`、`ERROR`、`系统繁忙` 关键词。 +- 已完成后端 `/user/password` 原密码改密分支、`/admin/export` Excel 下载接口、`/admin/manager/employees/{userId}/orders` 员工订单接口。 +- 已完成 `JY-Salon-Front` 修改密码真实提交、导出 Blob 下载、员工订单真实列表。 +- 已完成 `JY-Salon-WeChat` 修改密码真实提交并重新登录、导出下载打开 Excel、员工订单真实列表。 +- 已更新 `docs/项目变更记录.md` 和 `docs/运维配置与集成说明.md`,记录 POI 依赖和接口行为。 +- 已通过 `JY-Core` 编译、`JY-Salon-Front` 构建、小程序变更 JS 语法检查、GitNexus `detect-changes`。 ## 下一步 -- 若后续继续发布,仍需先用 `systemctl cat` 或真实 Java 进程确认实际 JAR 路径,不能只依赖脚本默认路径。 +- 暂存本次相关文件并创建中文 git 提交。 ## 当前阻塞点 @@ -23,4 +22,4 @@ ## 最近一次重要操作结果 -2026-07-16 当前代码已发布到生产后端和网页端,验证通过;本次未修改数据库、Nacos、Nginx 配置、SQL 和小程序。 +2026-07-16 本地验证通过;GitNexus `detect-changes` 显示 23 个文件、44 个符号、0 个流程、风险 LOW。