Commit 14d4bedb by lixinming

政策速递

parent b7e5690e
/**
* 资讯逻辑
*/
import moment = require("moment");
import { ERRORENUM } from "../../config/errorEnum";
import { createInformation, deleteInformationData, selectInformationByParam, selectInformationDataById } from "../../data/guanWeiHui/information";
import { getInformationId } from "../../tools/system";
import { BizError } from "../../util/bizError";
export async function addOnceInformation(desc:string, title:string ,source:string, coverImg:string ) {
let id = getInformationId();
await createInformation(id, desc, title, source, coverImg);
return {isSuccess:true};
}
export async function openInformation(id:string, isPermanent:boolean, closeTimeMs:number) {
if ( isPermanent ) closeTimeMs = 0;
else {
if (!closeTimeMs) throw new BizError(ERRORENUM.参数错误, "开启任务时 缺少创建时间");
}
let informationData = await selectInformationDataById(id);
if (informationData.state) throw new BizError(ERRORENUM.请不要重复开启资讯);
informationData.isPermanent = isPermanent;
informationData.closeTimeMs = closeTimeMs;
await informationData.save();
return {isSuccess:true};
}
export async function closeInformation(id:string) {
let informationData = await selectInformationDataById(id);
informationData.switch = true;
await informationData.save();
return {isSuccess:true};
}
export async function selectOnceInformationDate(id:string) {
let onceDataInfo = await selectInformationDataById(id);
let result = {
id:onceDataInfo.id,
title:onceDataInfo.title,
desc:onceDataInfo.desc,
source:onceDataInfo.source,
coverImg:onceDataInfo.coverImg,
};
return {dataInfo:result};
}
export async function deleteOnceInformationDate(id:string) {
let onceDataInfo = await selectInformationDataById(id);
if (onceDataInfo.state) throw new BizError(ERRORENUM.请先关闭该资讯, "未关闭资讯进行删除操作");
await deleteInformationData(id);
return {isSuccess:true};
}
export async function updateOnceInformation(id:string, desc:string, title:string ,source:string, coverImg:string ) {
let onceDataInfo = await selectInformationDataById(id);
if (onceDataInfo.state) throw new BizError(ERRORENUM.请先关闭该资讯, "未关闭资讯进行修改操作");
onceDataInfo.coverImg = coverImg;
onceDataInfo.title = title;
onceDataInfo.desc = desc;
onceDataInfo.source = source;
await onceDataInfo.save();
return {isSuccess:true};
}
export async function selectInformation() {
let dataBaseList = await selectInformationByParam({});
let dataList = [];
dataBaseList.forEach(info => {
let {title, createTimeMs, state, closeTimeMs, isPermanent, id} = info;
let stateStr = "下线";
if (state) {
stateStr = "上线";
if (!isPermanent && closeTimeMs< new Date().valueOf()) stateStr = "下线";
}
dataList.push({
id,
title,
createTime:moment(createTimeMs).format("YYYY-MM-DD"),
state,
stateStr
});
});
return {dataList};
}
/**
* 文件上传
*/
\ No newline at end of file
......@@ -305,15 +305,3 @@ export async function updateEnterpriseBaseInfo(uscc:string, param) {
return {isSuccess:true};
}
/**
* 获取资讯列表
* @param uscc 预留好 后期做推荐的参数
*
*/
async function getInformationList(uscc:string) {
let list = [];
}
\ No newline at end of file
/**
* 政策速递
*/
import moment = require("moment");
import { selectInformationByParam, selectInformationByParamCount, selectInformationByParamToPage, selectInformationDataById } from "../../data/guanWeiHui/information";
/**
* 获取资讯列表
*
* @param uscc 预留好 后期做推荐的参数
* @param selectTitle
* @param page 分页
* @returns
*/
export async function getInformationList(uscc:string, selectTitle:string, page:number) {
let selectParam = {state:true, "$or":[{closeTimeMs: {"$gt":new Date().valueOf()} }, {isPermanent:true}] };
if (selectTitle) {
selectParam["title"] = {"$regex":`${selectTitle}`};
}
let informationList = await selectInformationByParamToPage(selectParam, (page-1) * 10 );
let count = await selectInformationByParamCount(selectParam);
let dataList = [];
informationList.forEach((info) => {
let { id, title,createTimeMs, source, coverImg } = info;
dataList.push({title, id, createTime:moment(createTimeMs).format("MM/DD"),source, coverImg});
});
return {dataList, count};
}
/**
* 获取过期资讯列表
*
* @param uscc 预留好 后期做推荐的参数
* @param selectTitle 模糊查询标题
* @param page 分页
* @returns
*/
export async function getOutOfDateInformationList(uscc:string, selectTitle:string, page:number) {
let selectParam = {"$or":[{closeTimeMs: {"$lt":new Date().valueOf()} }, {state:false}] };
if (selectTitle) {
selectParam["title"] = {"$regex":`${selectTitle}`};
}
let informationList = await selectInformationByParamToPage(selectParam, (page-1) * 10 );
let count = await selectInformationByParamCount(selectParam);
let dataList = [];
informationList.forEach((info) => {
let { id, title,createTimeMs, source, coverImg } = info;
dataList.push({title, id, createTime:moment(createTimeMs).format("MM/DD"),source, coverImg});
});
return {dataList, count};
}
/**
* 获取过期资讯详情
* @param uscc
* @param id 标识
*/
export async function getOnceinformation(uscc:string, id:string) {
let informationData = await selectInformationDataById(id );
let reuslt = {
title:informationData.title,
desc:informationData.desc,
source:informationData.source,
createTime:moment(informationData.createTimeMs).format("MM/DD")
};
return {infomation:reuslt};
}
\ No newline at end of file
......@@ -58,6 +58,8 @@ export enum ERRORENUM {
请先创建填报数据,
重复通过填报数据,
请先选择是否拥有,
请先关闭该资讯,
请不要重复开启资讯
}
export enum ERRORCODEENUM {
......
/**
* 企业资讯
* 资讯 包括企业和孵化器
*
*/
......@@ -8,13 +8,15 @@ import { baseDB } from '../../db/mongo/dbInit';
const informationSchema = new Schema({
id:{type:String, index:true},//唯一标识
desc:String,//描述
title:String,//标题
desc:String,//内容
source:String,//来源
createTimeMs:Number,//创建时间
imgs:{type:[String], default:[]},
author:String,
createUid:String,
coverImg:{type:String, default:""},
target:{type:[Number], default:[]},//标签
noAutomatic:{type:Boolean, default:false},//非自动状态 true=关闭,false=开启
closeTimeMs:Number,//关闭时间
isPermanent:{type:Boolean, default:false},//是否永久有效
state:{type:Boolean, default:false},//非自动状态 true=关闭,false=开启
});
var informationModel;
......@@ -43,12 +45,33 @@ export async function save(throwError=false) {
* 创建资讯
* @param id
* @param desc
* @param createTimeMs
* @param author
* @param createUid
* @param target
* @param title
* @param source
* @param imgs
*/
export async function createInformation(id:string, desc:string, imgs,author:string, createUid:string, target:number ) {
// let addInfo = {id, desc, createTimeMs, imgs, author, createUid, target, noAutomatic};
export async function createInformation(id:string, desc:string, title:string ,source:string, coverImg:string ) {
let addInfo = {id, desc, title, source, coverImg, createTimeMs:new Date().valueOf() };
await informationModel.create(addInfo);
}
export async function selectInformationDataById(id:string) {
return await informationModel.selectOnceData({id});
}
export async function deleteInformationData(id:string) {
return await informationModel.deleteOne({id});
}
export async function selectInformationByParam(param) {
return await informationModel.find(param);
}
export async function selectInformationByParamToPage(param, skipNumber:number) {
return await informationModel.find(param).skip(skipNumber).limit(10);;
}
export async function selectInformationByParamCount(param) {
return await informationModel.find(param).count();;
}
\ No newline at end of file
/**
* 管理后台端 资讯相关
*/
import * as asyncHandler from 'express-async-handler';
import { checkGuanWeiHuiToken } from '../../middleware/user';
import { eccReqParamater } from '../../util/verificationParam';
import * as informationBiz from '../../biz/admin/information';
export function setRouter(httpServer) {
httpServer.post('/admin/infomation/add',checkGuanWeiHuiToken, asyncHandler(addInformation));
httpServer.post('/admin/infomation/update',checkGuanWeiHuiToken, asyncHandler(updateInformation));
httpServer.post('/admin/infomation/delete',checkGuanWeiHuiToken, asyncHandler(deleteInformation));
httpServer.post('/admin/infomation/info',checkGuanWeiHuiToken, asyncHandler(infoInformation));
httpServer.post('/admin/infomation/list',checkGuanWeiHuiToken,asyncHandler(listInformation));
httpServer.post('/admin/infomation/open',checkGuanWeiHuiToken, asyncHandler(openInformation));
httpServer.post('/admin/infomation/close',checkGuanWeiHuiToken, asyncHandler(closeInformation));
}
/**
* 创建资讯
* @param req
* @param res
*/
async function addInformation(req, res) {
let reqConf = {
desc:"String", title:"String" ,source:"String", coverImg:"String"
};
const NotMustHaveKeys = ["coverImg"];
let {desc, title, source, coverImg} = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
let data = await informationBiz.addOnceInformation(desc, title, source, coverImg);
res.success(data);
}
/**
* 修改资讯
* @param req
* @param res
*/
async function updateInformation(req, res) {
let reqConf = {
id:"String", desc:"String", title:"String" ,source:"String", coverImg:"String"
};
const NotMustHaveKeys = ["coverImg"];
let {id, desc, title, source, coverImg} = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
let data = await informationBiz.updateOnceInformation(id, desc, title, source, coverImg);
res.success(data);
}
/**
* 删除资讯
* @param req
* @param res
*/
async function deleteInformation(req, res) {
let reqConf = { id:"String" };
let {id} = eccReqParamater(reqConf, req.body, []);
let data = await informationBiz.deleteOnceInformationDate(id);
res.success(data);
}
/**
* 回显
* @param req
* @param res
*/
async function infoInformation(req, res) {
let reqConf = { id:"String" };
let {id} = eccReqParamater(reqConf, req.body, []);
let data = await informationBiz.selectOnceInformationDate(id);
res.success(data);
}
/**
* 资讯列表
* @param req
* @param res
*/
async function listInformation(req, res) {
let data = await informationBiz.selectInformation();
res.success(data);
}
/**
* 打开资讯
* @param req
* @param res
*/
async function openInformation(req, res) {
let reqConf = {
id:"String", isPermanent:"Boolean", closeTimeMs:"Number"
};
const NotMustHaveKeys = ["closeTimeMs"];
let {id, isPermanent, closeTimeMs} = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
let data = await informationBiz.openInformation(id, isPermanent, closeTimeMs);
res.success(data);
}
/**
* 关闭资讯
* @param req
* @param res
*/
async function closeInformation(req, res) {
let reqConf = { id:"String" };
let {id} = eccReqParamater(reqConf, req.body, []);
let data = await informationBiz.closeInformation(id);
res.success(data);
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import { checkEnterpriseToken } from '../../middleware/user';
import { eccReqParamater } from '../../util/verificationParam';
import * as enterpriseBiz from '../../biz/mobileEnterprise/enterprise';
import * as dataDeclarationBiz from '../../biz/mobileEnterprise/dataDeclaration';
import * as policyBiz from '../../biz/mobileEnterprise/policy';
export function setRouter(httpServer) {
......@@ -26,6 +27,8 @@ export function setRouter(httpServer) {
httpServer.post('/enterprise/qualification/info', checkEnterpriseToken, asyncHandler(qualificationInfo));
/**资讯 */
httpServer.post('/enterprise/information/list', checkEnterpriseToken, asyncHandler(informationList));
httpServer.post('/enterprise/information/outofdate', checkEnterpriseToken, asyncHandler(outOfDateInformationList));
httpServer.post('/enterprise/information/info', checkEnterpriseToken, asyncHandler(onceInformationData));
/**团队信息 */
httpServer.post('/enterprise/team/info', checkEnterpriseToken, asyncHandler(showTeamInfomation));
}
......@@ -173,9 +176,43 @@ async function showTeamInfomation(req, res) {
}
/**
* 政策列表
* @param req
* @param res
*/
async function informationList(req, res) {
const Uscc = req.headers.uscc;
let reqConf = {selectTitle:'String', page:'Number'};
let {selectTitle, page} = eccReqParamater(reqConf, req.body, ["selectTitle"]);
let result = await policyBiz.getInformationList(Uscc, selectTitle, page);
res.success(result);
}
async function informationList(req, res) {
/**
* 往期政策列表
* @param req
* @param res
*/
async function outOfDateInformationList(req, res) {
const Uscc = req.headers.uscc;
let reqConf = {selectTitle:'String', page:'Number'};
let {selectTitle, page} = eccReqParamater(reqConf, req.body, ["selectTitle"]);
let result = await policyBiz.getInformationList(Uscc, selectTitle, page);
res.success(result);
}
/**
* 政策详情
* @param req
* @param res
*/
async function onceInformationData(req, res) {
const Uscc = req.headers.uscc;
let reqConf = {id:'String'};
let {id} = eccReqParamater(reqConf, req.body);
let result = await policyBiz.getOnceinformation(Uscc, id);
res.success(result);
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import * as adminFuHuaQiRouters from './admin/fuHuaQi';
import * as adminUserRouters from './admin/user';
import * as adminScoreRouters from './admin/score';
import * as adminTaskRouters from './admin/task';
import * as informationRouters from './admin/information';
import * as provideRouters from './provide';
......@@ -39,6 +40,7 @@ export function setRouter(httpServer){
adminUserRouters.setRouter(httpServer);
adminScoreRouters.setRouter(httpServer);
adminTaskRouters.setRouter(httpServer);
informationRouters.setRouter(httpServer);
/**系统维护 入口路由 */
provideRouters.setRouter(httpServer);
/**小程序企业端 入口路由 */
......
......@@ -186,5 +186,9 @@ export function getFinancingId(uscc) {
* @returns
*/
export function getInitialTeamMemberId(uscc:string, name:string) {
return md5(`${uscc}${name}${Math.ceil(Math.random() * 1000000)}`);
return md5(`${uscc}${name}${Math.ceil(Math.ceil(Math.random() * 1000000))}`);
}
export function getInformationId() {
return md5(`${Math.ceil(Math.ceil(Math.random() * 1000000))}${new Date().valueOf() }${Math.ceil(Math.ceil(Math.random() * 1000000))}`);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment