|
|
@@ -1,5 +1,5 @@
|
|
|
import dayjs from 'dayjs';
|
|
|
-import { Dict, Files, Goods, Video } from '../model/index.js';
|
|
|
+import { Advanced, Dict, Files, Goods, Share, Video } from '../model/index.js';
|
|
|
import resSend from '../util/resSend.js';
|
|
|
import { passWordJia } from '../util/pass.js';
|
|
|
|
|
|
@@ -13,6 +13,7 @@ const issue = {
|
|
|
|
|
|
return resSend(res, 0, '获取Proof成功', arr.join('||'));
|
|
|
},
|
|
|
+ // ---------------项目简介
|
|
|
getIntro: async (req: any, res: any) => {
|
|
|
req.apiDescription = '内容发布-获取项目简介';
|
|
|
const introObj = await Dict.findById('694e4200f4ed1ea12901a424');
|
|
|
@@ -29,6 +30,7 @@ const issue = {
|
|
|
await introObj.save();
|
|
|
return resSend(res, 0, '编辑项目简介成功');
|
|
|
},
|
|
|
+ // ---------------视频展示
|
|
|
getVideoList: async (req: any, res: any) => {
|
|
|
req.apiDescription = '内容发布-获取视频展示列表';
|
|
|
const { pageNum = 1, pageSize = 10, searchKey = '' } = req.body;
|
|
|
@@ -91,10 +93,12 @@ const issue = {
|
|
|
req.apiDescription = `内容发布-编辑视频展示-${videoObj.name}`;
|
|
|
return resSend(res, 0, '编辑视频展示成功', videoObj);
|
|
|
} else {
|
|
|
- const userModel = new Video(req.body);
|
|
|
+ const infoModel = new Video(req.body);
|
|
|
+ infoModel.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ infoModel.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
// 新增视频展示
|
|
|
// 保存数据到数据库
|
|
|
- const dbBack = await userModel.save();
|
|
|
+ const dbBack = await infoModel.save();
|
|
|
// 将文档转换为普通对象
|
|
|
const videoObj = dbBack.toObject();
|
|
|
req.apiDescription = `内容发布-新增视频展示-${videoObj.name}`;
|
|
|
@@ -123,6 +127,7 @@ const issue = {
|
|
|
req.apiDescription = `内容发布-获取视频展示详情-${info.name}`;
|
|
|
return resSend(res, 0, '获取视频展示详情成功', info);
|
|
|
},
|
|
|
+ // ---------------展品展示
|
|
|
getGoodsList: async (req: any, res: any) => {
|
|
|
req.apiDescription = '内容发布-获取展品展示列表';
|
|
|
const { pageNum = 1, pageSize = 10, searchKey = '' } = req.body;
|
|
|
@@ -190,10 +195,12 @@ const issue = {
|
|
|
req.apiDescription = `内容发布-编辑展品展示-${findObj.name}`;
|
|
|
return resSend(res, 0, '编辑展品展示成功', findObj);
|
|
|
} else {
|
|
|
- const userModel = new Goods(req.body);
|
|
|
+ const infoModel = new Goods(req.body);
|
|
|
+ infoModel.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ infoModel.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
// 新增展品展示
|
|
|
// 保存数据到数据库
|
|
|
- const dbBack = await userModel.save();
|
|
|
+ const dbBack = await infoModel.save();
|
|
|
// 将文档转换为普通对象
|
|
|
const findObj = dbBack.toObject();
|
|
|
req.apiDescription = `内容发布-新增展品展示-${findObj.name}`;
|
|
|
@@ -258,6 +265,200 @@ const issue = {
|
|
|
req.apiDescription = `内容发布-获取展品展示详情-${info.name}`;
|
|
|
return resSend(res, 0, '获取展品展示详情成功', info);
|
|
|
},
|
|
|
+ // ---------------先进光源
|
|
|
+ getAdvancedList: async (req: any, res: any) => {
|
|
|
+ req.apiDescription = '内容发布-获取先进光源列表';
|
|
|
+ const { pageNum = 1, pageSize = 10, searchKey = '' } = req.body;
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ const query: any = {};
|
|
|
+
|
|
|
+ if (searchKey) {
|
|
|
+ // 使用正则表达式实现模糊查询,'i'表示不区分大小写
|
|
|
+ query.name = { $regex: searchKey, $options: 'i' };
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算跳过的文档数量
|
|
|
+ const skip = (pageNum - 1) * pageSize;
|
|
|
+
|
|
|
+ // 修改排序逻辑:先按sort字段降序,再按updateTime字段降序
|
|
|
+ const sortCondition: any = { sort: -1, updateTime: -1 };
|
|
|
+
|
|
|
+ // 并行执行:获取总条数和查询当前页数据
|
|
|
+ const [total, data] = await Promise.all([
|
|
|
+ // 获取满足条件的总记录数
|
|
|
+ Advanced.countDocuments(query),
|
|
|
+ // 查询当前页数据
|
|
|
+ Advanced.find(query).skip(skip).limit(parseInt(pageSize)).sort(sortCondition), // 按sort字段降序,数字越大越靠前;相同则按updateTime降序
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 计算总页数
|
|
|
+ const totalPages = Math.ceil(total / pageSize);
|
|
|
+ return resSend(res, 0, '获取先进光源列表成功', {
|
|
|
+ list: data,
|
|
|
+ pageNum: parseInt(pageNum),
|
|
|
+ pageSize: parseInt(pageSize),
|
|
|
+ total,
|
|
|
+ totalPages,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ saveAdvanced: async (req: any, res: any) => {
|
|
|
+ if (req.body._id) {
|
|
|
+ // 编辑先进光源
|
|
|
+ // 检查数据是否存在
|
|
|
+ const existing: any = await Advanced.findById(req.body._id);
|
|
|
+ if (!existing) return resSend(res, 404, '数据不存在');
|
|
|
+
|
|
|
+ // 更新字段
|
|
|
+ // 过滤一些字段
|
|
|
+ const filetStr: string[] = [];
|
|
|
+
|
|
|
+ Object.keys(req.body).forEach((key) => {
|
|
|
+ if (key !== '_id' && req.body[key] !== undefined) {
|
|
|
+ if (!filetStr.includes(key)) {
|
|
|
+ existing[key] = req.body[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ existing.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ const updatedUser = await existing.save();
|
|
|
+
|
|
|
+ const findObj = updatedUser.toObject();
|
|
|
+ req.apiDescription = `内容发布-编辑先进光源-${findObj.name}`;
|
|
|
+ return resSend(res, 0, '编辑先进光源成功', findObj);
|
|
|
+ } else {
|
|
|
+ const infoModel = new Advanced(req.body);
|
|
|
+ infoModel.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ infoModel.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ // 新增先进光源
|
|
|
+ // 保存数据到数据库
|
|
|
+ const dbBack = await infoModel.save();
|
|
|
+ // 将文档转换为普通对象
|
|
|
+ const findObj = dbBack.toObject();
|
|
|
+ req.apiDescription = `内容发布-新增先进光源-${findObj.name}`;
|
|
|
+ return resSend(res, 0, '新增先进光源成功', findObj);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ delAdvanced: async (req: any, res: any) => {
|
|
|
+ const { _id } = req.params; // 从URL参数中获取ID
|
|
|
+ // 1. 根据ID查找数据
|
|
|
+ const info = await Advanced.findById(_id);
|
|
|
+ if (!info) return resSend(res, 404, '_id错误或数据已被删除');
|
|
|
+
|
|
|
+ const deletedInfo: any = await Advanced.findByIdAndDelete(_id);
|
|
|
+ req.apiDescription = `内容发布-删除先进光源数据-${deletedInfo.name}`;
|
|
|
+ return resSend(res, 0, '删除先进光源数据成功');
|
|
|
+ },
|
|
|
+ getAdvancedInfo: async (req: any, res: any) => {
|
|
|
+ const { _id } = req.params;
|
|
|
+
|
|
|
+ if (!_id) return resSend(res, 400, '_id不能为空');
|
|
|
+
|
|
|
+ // 根据ID查询信息
|
|
|
+ const info = await Advanced.findById(_id);
|
|
|
+
|
|
|
+ if (!info) return resSend(res, 404, '_id错误或数据已被删除');
|
|
|
+ req.apiDescription = `内容发布-获取先进光源详情-${info.name}`;
|
|
|
+ return resSend(res, 0, '获取先进光源详情成功', info);
|
|
|
+ },
|
|
|
+ // ---------------素材共享
|
|
|
+ getShareList: async (req: any, res: any) => {
|
|
|
+ req.apiDescription = '内容发布-获取素材共享列表';
|
|
|
+ const { pageNum = 1, pageSize = 10, searchKey = '' } = req.body;
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ const query: any = {};
|
|
|
+
|
|
|
+ if (searchKey) {
|
|
|
+ // 使用正则表达式实现模糊查询,'i'表示不区分大小写
|
|
|
+ query.name = { $regex: searchKey, $options: 'i' };
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算跳过的文档数量
|
|
|
+ const skip = (pageNum - 1) * pageSize;
|
|
|
+
|
|
|
+ // 修改排序逻辑:先按sort字段降序,再按updateTime字段降序
|
|
|
+ const sortCondition: any = { sort: -1, updateTime: -1 };
|
|
|
+
|
|
|
+ // 并行执行:获取总条数和查询当前页数据
|
|
|
+ const [total, data] = await Promise.all([
|
|
|
+ // 获取满足条件的总记录数
|
|
|
+ Share.countDocuments(query),
|
|
|
+ // 查询当前页数据
|
|
|
+ Share.find(query).skip(skip).limit(parseInt(pageSize)).sort(sortCondition), // 按sort字段降序,数字越大越靠前;相同则按updateTime降序
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 计算总页数
|
|
|
+ const totalPages = Math.ceil(total / pageSize);
|
|
|
+ return resSend(res, 0, '获取素材共享列表成功', {
|
|
|
+ list: data,
|
|
|
+ pageNum: parseInt(pageNum),
|
|
|
+ pageSize: parseInt(pageSize),
|
|
|
+ total,
|
|
|
+ totalPages,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ saveShare: async (req: any, res: any) => {
|
|
|
+ if (req.body._id) {
|
|
|
+ // 编辑素材共享
|
|
|
+ // 检查数据是否存在
|
|
|
+ const existing: any = await Share.findById(req.body._id);
|
|
|
+ if (!existing) return resSend(res, 404, '数据不存在');
|
|
|
+
|
|
|
+ // 更新字段
|
|
|
+ // 过滤一些字段
|
|
|
+ const filetStr: string[] = [];
|
|
|
+
|
|
|
+ Object.keys(req.body).forEach((key) => {
|
|
|
+ if (key !== '_id' && req.body[key] !== undefined) {
|
|
|
+ if (!filetStr.includes(key)) {
|
|
|
+ existing[key] = req.body[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ existing.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ const updatedUser = await existing.save();
|
|
|
+
|
|
|
+ const findObj = updatedUser.toObject();
|
|
|
+ req.apiDescription = `内容发布-编辑素材共享-${findObj.name}`;
|
|
|
+ return resSend(res, 0, '编辑素材共享成功', findObj);
|
|
|
+ } else {
|
|
|
+ const infoModel = new Share(req.body);
|
|
|
+ infoModel.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ infoModel.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ // 新增素材共享
|
|
|
+ // 保存数据到数据库
|
|
|
+ const dbBack = await infoModel.save();
|
|
|
+ // 将文档转换为普通对象
|
|
|
+ const findObj = dbBack.toObject();
|
|
|
+ req.apiDescription = `内容发布-新增素材共享-${findObj.name}`;
|
|
|
+ return resSend(res, 0, '新增素材共享成功', findObj);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ delShare: async (req: any, res: any) => {
|
|
|
+ const { _id } = req.params; // 从URL参数中获取ID
|
|
|
+ // 1. 根据ID查找数据
|
|
|
+ const info = await Share.findById(_id);
|
|
|
+ if (!info) return resSend(res, 404, '_id错误或数据已被删除');
|
|
|
+
|
|
|
+ const deletedInfo: any = await Share.findByIdAndDelete(_id);
|
|
|
+ req.apiDescription = `内容发布-删除素材共享数据-${deletedInfo.name}`;
|
|
|
+ return resSend(res, 0, '删除素材共享数据成功');
|
|
|
+ },
|
|
|
+ getShareInfo: async (req: any, res: any) => {
|
|
|
+ const { _id } = req.params;
|
|
|
+
|
|
|
+ if (!_id) return resSend(res, 400, '_id不能为空');
|
|
|
+
|
|
|
+ // 根据ID查询信息
|
|
|
+ const info = await Share.findById(_id);
|
|
|
+
|
|
|
+ if (!info) return resSend(res, 404, '_id错误或数据已被删除');
|
|
|
+ req.apiDescription = `内容发布-获取素材共享详情-${info.name}`;
|
|
|
+ return resSend(res, 0, '获取素材共享详情成功', info);
|
|
|
+ },
|
|
|
};
|
|
|
|
|
|
export default issue;
|