feat_withplan_dto
This commit is contained in:
+62
@@ -5,6 +5,9 @@ import com.central.common.model.Result;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.model.*;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IPackagePlanService;
|
||||
import com.central.order.model.PackagePlan;
|
||||
import com.central.order.model.dto.QrcodeWithPlanDTO;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import com.central.order.service.ITourismService;
|
||||
@@ -13,10 +16,12 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -52,6 +57,9 @@ public class QrCodeController {
|
||||
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
|
||||
@Autowired
|
||||
private IPackagePlanService packagePlanService;
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@@ -164,4 +172,58 @@ public class QrCodeController {
|
||||
map.put("tourismId",qrCode.getTourismId());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建/修改二维码并同步套餐")
|
||||
@PostMapping("/withPlan")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<QrCode> saveOrUpdateQrcodeWithPlan(@RequestBody QrcodeWithPlanDTO body) throws Exception {
|
||||
Assert.notNull(body, "请求体不能为空");
|
||||
Assert.notNull(body.getQrCode(), "二维码参数不能为空");
|
||||
|
||||
QrCode qrCode = body.getQrCode();
|
||||
Integer vlogCount = body.getVlogCount();
|
||||
Integer videoCount = body.getVideoCount();
|
||||
Integer photoCount = body.getPhotoCount();
|
||||
|
||||
// 先复用现有的创建/修改逻辑
|
||||
Result<QrCode> result;
|
||||
if (qrCode.getId() == null) {
|
||||
String codeId = UUID.randomUUID().toString();
|
||||
Result<Map> upload = fileCenterService.uploadQrCodeFile(codeId);
|
||||
if (upload.getResp_code() != 0) {
|
||||
return Result.failed("创建二维码文件失败");
|
||||
}
|
||||
Tourism tourism = tourismService.getTourismById(qrCode.getTourismId());
|
||||
Assert.notNull(tourism, "请选择景区数据");
|
||||
qrCode.setTenantId(tourism.getTenantId());
|
||||
qrCode.setCodeId(codeId);
|
||||
qrCode.setFilePath(upload.getData().get("filePath").toString());
|
||||
qrCode.setFileId(upload.getData().get("fileId").toString());
|
||||
if (qrCodeService.saveOrUpdate(qrCode)) {
|
||||
result = Result.succeed(qrCode, "qrcode创建成功");
|
||||
} else {
|
||||
return Result.failed("qrcode创建失败");
|
||||
}
|
||||
} else {
|
||||
qrCodeService.saveOrUpdate(qrCode);
|
||||
result = Result.succeed(qrCode, "qrcode修改成功");
|
||||
}
|
||||
|
||||
// 同步套餐:有则更新,无则创建
|
||||
String codeId = qrCode.getCodeId();
|
||||
if (codeId != null) {
|
||||
List<PackagePlan> exists = packagePlanService.getByCodeId(codeId);
|
||||
PackagePlan plan = exists != null && !exists.isEmpty() ? exists.get(0) : new PackagePlan();
|
||||
plan.setCodeId(codeId);
|
||||
if (plan.getTenantId() == null) {
|
||||
plan.setTenantId(qrCode.getTenantId());
|
||||
}
|
||||
if (vlogCount != null) plan.setVlogCount(vlogCount);
|
||||
if (videoCount != null) plan.setVideoCount(videoCount);
|
||||
if (photoCount != null) plan.setPhotoCount(photoCount);
|
||||
packagePlanService.saveOrUpdate(plan);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.central.order.model.dto;
|
||||
|
||||
import com.central.order.model.QrCode;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "二维码与套餐创建/修改请求体")
|
||||
public class QrcodeWithPlanDTO {
|
||||
@Schema(description = "二维码实体")
|
||||
private QrCode qrCode;
|
||||
|
||||
@Schema(description = "Vlog数量")
|
||||
private Integer vlogCount;
|
||||
|
||||
@Schema(description = "视频数量")
|
||||
private Integer videoCount;
|
||||
|
||||
@Schema(description = "照片数量")
|
||||
private Integer photoCount;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.central.order.service;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.PackagePlan;
|
||||
|
||||
@@ -17,5 +18,5 @@ public interface IPackagePlanService extends ISuperService<PackagePlan> {
|
||||
/**
|
||||
* 分页条件查询
|
||||
*/
|
||||
com.central.common.model.PageResult<PackagePlan> findList(java.util.Map<String, Object> params);
|
||||
PageResult<PackagePlan> findList(java.util.Map<String, Object> params);
|
||||
}
|
||||
|
||||
+31
-1
@@ -238,8 +238,38 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
||||
}}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
{/* 套餐配置 */}
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="vlogCount"
|
||||
label="Vlog数量"
|
||||
min={0}
|
||||
initialValue={0}
|
||||
placeholder="请输入Vlog数量"
|
||||
/>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="videoCount"
|
||||
label="视频数量"
|
||||
min={0}
|
||||
initialValue={0}
|
||||
placeholder="请输入视频数量"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="photoCount"
|
||||
label="照片数量"
|
||||
min={0}
|
||||
initialValue={0}
|
||||
placeholder="请输入照片数量"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateForm;
|
||||
export default CreateForm;
|
||||
|
||||
@@ -245,6 +245,33 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
}}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
{/* 套餐配置 */}
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="vlogCount"
|
||||
label="Vlog数量"
|
||||
min={0}
|
||||
placeholder="请输入Vlog数量"
|
||||
/>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="videoCount"
|
||||
label="视频数量"
|
||||
min={0}
|
||||
placeholder="请输入视频数量"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="photoCount"
|
||||
label="照片数量"
|
||||
min={0}
|
||||
placeholder="请输入照片数量"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList, getVideoTemplateList, getTenantList } from '@/services/orders/api';
|
||||
import { deleteQrcode, qrcode, saveOrUpdateQrcodeWithPlan, getTourismList, getVideoTemplateList, getTenantList, getPackageByCode } from '@/services/orders/api';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
@@ -121,29 +121,55 @@ const TableList: React.FC = () => {
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
// 处理添加
|
||||
// 处理添加(先创建二维码,再创建套餐)
|
||||
const handleAdd = async (fields: Partial<ORDERS.Qrcode>) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
...fields,
|
||||
} as ORDERS.Qrcode),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const { vlogCount, videoCount, photoCount, ...qrcodePayload } = (fields || {}) as any;
|
||||
const res = await saveOrUpdateQrcodeWithPlan({
|
||||
qrCode: qrcodePayload as ORDERS.Qrcode,
|
||||
vlogCount: Number(vlogCount ?? 0),
|
||||
videoCount: Number(videoCount ?? 0),
|
||||
photoCount: Number(photoCount ?? 0),
|
||||
});
|
||||
if (res.resp_code !== 0) {
|
||||
message.error(res.resp_msg || '创建失败');
|
||||
return false;
|
||||
}
|
||||
message.success('添加成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('添加失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
// 处理编辑(更新二维码,同时新增/更新套餐)
|
||||
const handleEdit = async (original: ORDERS.Qrcode, fields: Partial<ORDERS.Qrcode>) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
id: original.id,
|
||||
...fields
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const { vlogCount, videoCount, photoCount, ...qrcodePayload } = (fields || {}) as any;
|
||||
const qrPayload = { id: original.id, codeId: original.codeId, ...(qrcodePayload as any) } as ORDERS.Qrcode;
|
||||
const res = await saveOrUpdateQrcodeWithPlan({
|
||||
qrCode: qrPayload,
|
||||
vlogCount: vlogCount as number | undefined,
|
||||
videoCount: videoCount as number | undefined,
|
||||
photoCount: photoCount as number | undefined,
|
||||
});
|
||||
if (res.resp_code !== 0) {
|
||||
message.error(res.resp_msg || '更新失败');
|
||||
return false;
|
||||
}
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 处理删除
|
||||
@@ -525,8 +551,19 @@ const TableList: React.FC = () => {
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
setCurrentRow(record);
|
||||
try {
|
||||
if (record?.codeId) {
|
||||
const planRes = await getPackageByCode(record.codeId);
|
||||
const plan = (planRes.resp_code === 0 && Array.isArray(planRes.data) && planRes.data.length > 0) ? planRes.data[0] : undefined;
|
||||
if (plan) {
|
||||
setCurrentRow(prev => ({ ...(prev as any), vlogCount: plan.vlogCount, videoCount: plan.videoCount, photoCount: plan.photoCount } as any));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore preload error
|
||||
}
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -112,6 +112,34 @@ export async function saveOrUpdateQrcode(data: ORDERS.Qrcode): Promise<API.Resul
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 根据二维码编码获取套餐列表 */
|
||||
export async function getPackageByCode(codeId: string): Promise<API.Result<ORDERS.PackagePlan[]>> {
|
||||
return request<API.Result<ORDERS.PackagePlan[]>>(`/api-order/package/byCode/${codeId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
/** 新增或更新套餐 */
|
||||
export async function saveOrUpdatePackagePlan(data: ORDERS.PackagePlan): Promise<API.Result<ORDERS.PackagePlan>> {
|
||||
return request<API.Result<ORDERS.PackagePlan>>('/api-order/package', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/** 一次性创建/修改二维码及套餐 */
|
||||
export async function saveOrUpdateQrcodeWithPlan(payload: {
|
||||
qrCode: ORDERS.Qrcode;
|
||||
vlogCount?: number;
|
||||
videoCount?: number;
|
||||
photoCount?: number;
|
||||
}): Promise<API.Result<ORDERS.Qrcode>> {
|
||||
return request<API.Result<ORDERS.Qrcode>>('/api-order/qrcode/withPlan', {
|
||||
method: 'POST',
|
||||
data: payload,
|
||||
});
|
||||
}
|
||||
|
||||
export async function homeCarousel(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<ORDERS.HomeCarousel>>('/api-order/home/carousel', {
|
||||
@@ -480,4 +508,4 @@ export async function getTenantList(params: {
|
||||
return request('/api-uaa/clients/all', {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +248,18 @@ declare namespace ORDERS {
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
/** 套餐定义 */
|
||||
type PackagePlan = {
|
||||
id?: number;
|
||||
codeId: string;
|
||||
vlogCount?: number;
|
||||
videoCount?: number;
|
||||
photoCount?: number;
|
||||
tenantId?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace API {
|
||||
@@ -292,4 +304,4 @@ declare namespace API {
|
||||
queueCount?: number;
|
||||
estimatedTime?: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user