Commit 8c62d44e by lixinming

no message

parent 70031caf
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
* 孵化器相关逻辑 包括孵化器的增删改查 * 孵化器相关逻辑 包括孵化器的增删改查
* *
*/ */
import moment = require("moment");
import { BaseParamUpdateConfig } from "../../config/checkParamConfig"; import { BaseParamUpdateConfig } from "../../config/checkParamConfig";
import { findEnterpriseCountByFuHuaQiUscc } from "../../data/enterprise/enterprise"; import { findEnterpriseCountByFuHuaQiUscc, groupFindEnterprise } from "../../data/enterprise/enterprise";
import { findFuHuaQiByUSCC } from "../../data/fuHuaQi/fuhuaqi"; import { findFuHuaQiByUSCC, findFuHuaQiList } from "../../data/fuHuaQi/fuhuaqi";
import * as tools from "../../util/tools"; import * as tools from "../../util/tools";
import { FuHuaQiBaseListConfig } from "../../config/ojbectResultKeyConfig";
/** /**
...@@ -61,7 +63,7 @@ export async function selectFuHuaQiBaseData(uscc:string) { ...@@ -61,7 +63,7 @@ export async function selectFuHuaQiBaseData(uscc:string) {
*/ */
export async function homeData(uscc:string) { export async function homeData(uscc:string) {
let dataBaseInfo = await findFuHuaQiByUSCC(uscc); let dataBaseInfo = await findFuHuaQiByUSCC(uscc);
let keyList = [ "incubatedAcreage", "acreageTotal", "acreagePersonalUse"]; let keyList = [ "incubatedAcreage", "acreageTotal", "acreagePersonalUse", "name"];
let data:any = {enterpriseCount:0}; let data:any = {enterpriseCount:0};
keyList.forEach( key => { keyList.forEach( key => {
...@@ -72,3 +74,26 @@ export async function homeData(uscc:string) { ...@@ -72,3 +74,26 @@ export async function homeData(uscc:string) {
return data; return data;
} }
/**
* 获取孵化器列表
* @param lv 孵化器等级
* @param institutionalNature 机构性质
* @param industry 领域
* @returns
*/
export async function fuHuaQiBaseList(lv:number, institutionalNature:number, industry:number) {
let enterpriseMap = await groupFindEnterprise();
let dataBaseList = await findFuHuaQiList();
let dataList = [];
dataBaseList.forEach( info => {
let changeData = tools.extractData(FuHuaQiBaseListConfig, info);
const Count = enterpriseMap[info.uscc] || 0;
dataList.push(changeData);
});
return {dataList};
}
\ No newline at end of file
...@@ -17,7 +17,7 @@ import { getPwdMd5, getToken } from "../../util/tools"; ...@@ -17,7 +17,7 @@ import { getPwdMd5, getToken } from "../../util/tools";
*/ */
export async function login(uscc:string, pwd:string) { export async function login(uscc:string, pwd:string) {
let fuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc); let fuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);
if(!fuhuaqiInfo) throw new BizError(ERRORENUM.未找到数据); if(!fuhuaqiInfo) throw new BizError(ERRORENUM.账号不存在);
let checkPwd = getPwdMd5(fuhuaqiInfo.uscc, pwd); let checkPwd = getPwdMd5(fuhuaqiInfo.uscc, pwd);
if (fuhuaqiInfo.pwd != checkPwd) throw new BizError(ERRORENUM.密码错误); if (fuhuaqiInfo.pwd != checkPwd) throw new BizError(ERRORENUM.密码错误);
...@@ -26,7 +26,7 @@ export async function login(uscc:string, pwd:string) { ...@@ -26,7 +26,7 @@ export async function login(uscc:string, pwd:string) {
let fuhuaqiUserInfo = { let fuhuaqiUserInfo = {
uscc: fuhuaqiInfo.uscc, uscc: fuhuaqiInfo.uscc,
name: fuhuaqiInfo.name, // name: fuhuaqiInfo.name,
firstLogin : !fuhuaqiInfo.firstLoginIsChangePwd, firstLogin : !fuhuaqiInfo.firstLoginIsChangePwd,
token:Token token:Token
}; };
...@@ -51,7 +51,8 @@ export async function firstLoginChangePwd(uscc:string, pwd:string, confirmPwd:st ...@@ -51,7 +51,8 @@ export async function firstLoginChangePwd(uscc:string, pwd:string, confirmPwd:st
let dataBaseInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc); let dataBaseInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);
if (dataBaseInfo.firstLoginIsChangePwd) throw new BizError(ERRORENUM.不能重复修改密码, `重复调用了首次登录之后的修改密码接口${uscc}`); if (dataBaseInfo.firstLoginIsChangePwd) throw new BizError(ERRORENUM.不能重复修改密码, `重复调用了首次登录之后的修改密码接口${uscc}`);
//todo 校验密码 //todo 校验密码
dataBaseInfo.pwd = pwd; dataBaseInfo.pwd = getPwdMd5(uscc, pwd);
dataBaseInfo.firstLoginIsChangePwd = true;
await dataBaseInfo.save(); await dataBaseInfo.save();
return {isSuccess:true}; return {isSuccess:true};
......
/**
* 管理后台用户逻辑层
* 作者: 李欣鸣
* 主要包括有 孵化器账号的登录
* 预留好 重置密码 退出登录 接口
*/
import { ERRORENUM } from "../../config/errorEnum";
import { findGuanWeiHuiUserInfoByLoginId } from "../../data/guanWeiHui/guanweihui";
import { BizError } from "../../util/bizError";
import { getPwdMd5, getToken } from "../../util/tools";
/**
* 登录
* @param loginId 信用代码
* @param pwd 密码
* @returns resultUserInfo:{uscc, name} 登录后的信息
*/
export async function login(loginId:string, pwd:string) {
let userInfo = await findGuanWeiHuiUserInfoByLoginId(loginId);
if(!userInfo) throw new BizError(ERRORENUM.账号不存在, loginId);
let checkPwd = getPwdMd5(userInfo.loginId, pwd);
if (userInfo.pwd != checkPwd) throw new BizError(ERRORENUM.密码错误);
const Token = getToken(loginId);
let resultUserInfo = {
loginId: userInfo.loginId,
name: userInfo.name,
token:Token
};
userInfo.token = Token;
userInfo.tokenMs = new Date().valueOf();
await userInfo.save();
return resultUserInfo;
}
\ No newline at end of file
...@@ -15,7 +15,8 @@ export enum ERRORENUM { ...@@ -15,7 +15,8 @@ export enum ERRORENUM {
身份验证失败, 身份验证失败,
非法登录, 非法登录,
身份验证过期, 身份验证过期,
密码长度不能超过24个字符 密码长度不能超过24个字符,
账号不存在
} }
export enum ERRORCODEENUM { export enum ERRORCODEENUM {
......
/**
* 孵化器基础数据列表 参数转换配置
*/
export const FuHuaQiBaseListConfig = {
name:{key:"名称"},
operationName:{key:"运营机构名称 不可修改"},
uscc:{key:"统一信用代码 也是登录账号 不可修改"},
virtualEnterpriseNum:{key:"虚拟企业数量"},
logonTime:{key:"注册时间", changeDate:true},
incubatedAcreage:{key:"在孵面积(㎡)"},
acreageTotal:{key:"孵化器总面积(㎡)"},
acreagePersonalUse:{key:"孵化器自用面积(㎡)"},
lv:{key:"孵化器级别"},
identificationTime:{key:"认定时间", changeDate:true},
industry:{key:"领域[]"},
institutionalNature:{key:"机构性质"},
liaison:{key:"联系人"},
liaisonPhone:{key:"联系电话"},
personInCharge:{key:"负责人"},
personInChargePhone:{key:"负责人联系电话"},
personInChargeAdd:{key:"孵化场地地址"},
siteAcreage:{key:"孵化场地面积(㎡)"},
leasePrice:{key:"孵化场地出租单价"},
};
\ No newline at end of file
...@@ -94,3 +94,19 @@ export async function createEnterprise(fuHuaQiUscc:string, taskId:string, param) ...@@ -94,3 +94,19 @@ export async function createEnterprise(fuHuaQiUscc:string, taskId:string, param)
export async function findEnterpriseCountByFuHuaQiUscc(fuHuaQiUscc:string) { export async function findEnterpriseCountByFuHuaQiUscc(fuHuaQiUscc:string) {
return await enterpriseModel.count({fuHuaQiUscc}).exec(); return await enterpriseModel.count({fuHuaQiUscc}).exec();
} }
/**
* 聚合查询 孵化器所拥有的企业数量
* @returns {} key=孵化器统一信用 value=企业数量
*/
export async function groupFindEnterprise() {
let match = {draftLock:true};//前置条件
let dataList = await enterpriseModel.aggregate([{$match:match},{$group:{_id:"$fuHuaQiUscc",count:{$sum:1}}}]).exec();
let result = {};
dataList.forEach(info => {
let {_id, count} = info;
result[_id] = count;
});
return result;
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ const fuHuaQiSchema = new Schema({ ...@@ -12,7 +12,7 @@ const fuHuaQiSchema = new Schema({
name: {type:String,index: true},//名称 name: {type:String,index: true},//名称
operationName:String,//运营机构名称 不可修改 operationName:String,//运营机构名称 不可修改
uscc:{type:String, index: true},//统一信用代码 也是登录账号 不可修改 uscc:{type:String, index: true},//统一信用代码 也是登录账号 不可修改
virtualEnterpriseNum:Number,//虚拟企业数量 virtualEnterpriseNum:{type:Number, default:0},//虚拟企业数量
logonTime:Number,//注册时间 logonTime:Number,//注册时间
incubatedAcreage:Number,//在孵面积(㎡) incubatedAcreage:Number,//在孵面积(㎡)
acreageTotal:Number,//孵化器总面积(㎡) acreageTotal:Number,//孵化器总面积(㎡)
...@@ -95,3 +95,11 @@ export async function findFuHuaQiByToken(token:string) { ...@@ -95,3 +95,11 @@ export async function findFuHuaQiByToken(token:string) {
return await fuHuaQiModel.findOne({token}).exec(); return await fuHuaQiModel.findOne({token}).exec();
} }
/**
* 获取所有孵化器
* @returns [] 孵化器列表
*/
export async function findFuHuaQiList() {
return await fuHuaQiModel.find({}).skip();
}
\ No newline at end of file
/**
* 管委会用户表
* 没有权限 2023-02-06 确定此需求
*/
import {Schema} from 'mongoose';
import { baseDB } from '../../db/dbInit';
const guanWeiHuiSchema = new Schema({
name:String,//名称
loginId: {type:String, index:true},//登录账号
pwd:String,//密码
token:String,
tokenMs:Number
});
var guanWeiHuiModel;
export function initModel(){
guanWeiHuiModel = baseDB.model('guanWeiHui', guanWeiHuiSchema);
guanWeiHuiModel.selectOnceData = async function (paramater:object) {
let selectInfo = await guanWeiHuiModel.findOne(paramater).exec();
if (selectInfo) {
if (!selectInfo.runSave) {
selectInfo.runSave = selectInfo.save;
selectInfo.save = save.bind(selectInfo)
}
}
return selectInfo;
}
}
export async function save(throwError=false) {
if (!this.isModified()) return;
await this.runSave({validateBeforeSave:false}).catch(err=>{
console.log(err);
});
}
export async function findGuanWeiHuiUserInfoByLoginId(loginId:string) {
return await guanWeiHuiModel.findOne({loginId}).exec();
}
\ No newline at end of file
...@@ -2,10 +2,12 @@ import * as taskinModel from "../data/fuHuaQi/task"; ...@@ -2,10 +2,12 @@ import * as taskinModel from "../data/fuHuaQi/task";
import * as fuhuaqiinModel from "../data/fuHuaQi/fuhuaqi"; import * as fuhuaqiinModel from "../data/fuHuaQi/fuhuaqi";
import * as enterpriseinModel from "../data/enterprise/enterprise"; import * as enterpriseinModel from "../data/enterprise/enterprise";
import * as financinginModel from "../data/enterprise/financing"; import * as financinginModel from "../data/enterprise/financing";
import * as monthTableModel from "../data/fuHuaQi/monthTable";
export async function initTable() { export async function initTable() {
taskinModel.initModel(); taskinModel.initModel();
fuhuaqiinModel.initModel(); fuhuaqiinModel.initModel();
enterpriseinModel.initModel(); enterpriseinModel.initModel();
financinginModel.initModel(); financinginModel.initModel();
monthTableModel.initModel();
} }
\ No newline at end of file
import * as asyncHandler from 'express-async-handler'; import * as asyncHandler from 'express-async-handler';
import * as userBiz from '../biz/guanWeiHui/user';
import * as baseBiz from '../biz/fuHuqQi/base';
import { checkReqParam } from '../util/tools';
import { BizError } from '../util/bizError';
import { ERRORENUM } from '../config/errorEnum';
export function setRouter(httpServer) { export function setRouter(httpServer) {
httpServer.post('/admin/login', asyncHandler(getConfig)); // /**登录 */
// httpServer.post('/admin/login', asyncHandler(login));
// /** 孵化器*/
// httpServer.post('/admin/fuhuaqi/baselist', asyncHandler());
// httpServer.post('/admin/fuhuaqi/monthoccupancyrate', asyncHandler());
// httpServer.post('/admin/fuhuaqi/userlist', asyncHandler());
// httpServer.post('/admin/fuhuaqi/updatestate', asyncHandler());
// /**企业 */
// httpServer.post('/admin/enterprise/list', asyncHandler());
// httpServer.post('/admin/enterprise/financinglist', asyncHandler());
}
/**
* 管理后天登录
* @param req
* @param res
*/
async function login(req, res) {
let reqConf = {loginId:'String', pwd:'String'};
let {uscc, pwd} = checkReqParam(reqConf, req.body);
let userInfo = await userBiz.login(uscc, pwd);
res.success(userInfo);
}
/**
* 孵化器基本信息列表
* @param req
* @param res
*/
async function fuHuaQiBaseList(req, res) {
let {lv, institutionalNature, industry} = req.body;
if (typeof lv != 'number' || typeof institutionalNature != 'number' || typeof industry != 'number') {
throw new BizError(ERRORENUM.参数错误, lv, institutionalNature, industry);
}
let result = await baseBiz.fuHuaQiBaseList(lv, institutionalNature, industry);
res.success(result);
} }
async function getConfig(req, res) { async function occupancyRate() {
res.success({});
} }
;
\ No newline at end of file
...@@ -9,31 +9,32 @@ import * as monthBiz from '../biz/fuHuqQi/month'; ...@@ -9,31 +9,32 @@ import * as monthBiz from '../biz/fuHuqQi/month';
import * as enterpriseBiz from '../biz/enterprise/enterprise'; import * as enterpriseBiz from '../biz/enterprise/enterprise';
import * as financingBiz from '../biz/enterprise/financing'; import * as financingBiz from '../biz/enterprise/financing';
import { checkReqParam } from '../util/tools'; import { checkReqParam } from '../util/tools';
import { checkFuHuaQiToken } from '../middleware/user';
export function setRouter(httpServer) { export function setRouter(httpServer) {
httpServer.post('/fuhuaqi/login', asyncHandler(login)); httpServer.post('/fuhuaqi/login', asyncHandler(login));
httpServer.post('/fuhuaqi/login/firstupdate', asyncHandler(firstUpdatePwd)); httpServer.post('/fuhuaqi/login/firstupdate', checkFuHuaQiToken, asyncHandler(firstUpdatePwd));
/**基础数据 */ /**基础数据 */
httpServer.post('/fuhuaqi/base', asyncHandler(baseInfo)); httpServer.post('/fuhuaqi/base', checkFuHuaQiToken, asyncHandler(baseInfo));
httpServer.post('/fuhuaqi/mydata', asyncHandler(myDataInfo)); httpServer.post('/fuhuaqi/mydata', checkFuHuaQiToken, asyncHandler(myDataInfo));
httpServer.post('/fuhuaqi/base/update', asyncHandler(updateMyDataInfo)); httpServer.post('/fuhuaqi/base/update', checkFuHuaQiToken, asyncHandler(updateMyDataInfo));
/**任务 */ /**任务 */
httpServer.post('/fuhuaqi/task/list', asyncHandler(taskList)); httpServer.post('/fuhuaqi/task/list', checkFuHuaQiToken, asyncHandler(taskList));
httpServer.post('/fuhuaqi/task/submit', asyncHandler(submitTask)); httpServer.post('/fuhuaqi/task/submit', checkFuHuaQiToken, asyncHandler(submitTask));
/**月度报表 */ /**月度报表 */
httpServer.post('/fuhuaqi/month/addreport', asyncHandler(addReport)); httpServer.post('/fuhuaqi/month/addreport', checkFuHuaQiToken, asyncHandler(addReport));
httpServer.post('/fuhuaqi/month/updatereport', asyncHandler(updateReport)); httpServer.post('/fuhuaqi/month/updatereport', checkFuHuaQiToken, asyncHandler(updateReport));
httpServer.post('/fuhuaqi/month/deletereport', asyncHandler(deleteReport)); httpServer.post('/fuhuaqi/month/deletereport', checkFuHuaQiToken, asyncHandler(deleteReport));
/**融资企业填报 */ /**融资企业填报 */
httpServer.post('/fuhuaqi/financing/create', asyncHandler(createFinancingInfo)); httpServer.post('/fuhuaqi/financing/create', checkFuHuaQiToken, asyncHandler(createFinancingInfo));
httpServer.post('/fuhuaqi/financing/update', asyncHandler(updateFinancingInfo)); httpServer.post('/fuhuaqi/financing/update', checkFuHuaQiToken, asyncHandler(updateFinancingInfo));
/**新注册或迁入企业 */ /**新注册或迁入企业 */
httpServer.post('/fuhuaqi/enterprise/register', asyncHandler(registerEnterprise)); httpServer.post('/fuhuaqi/enterprise/register', checkFuHuaQiToken, asyncHandler(registerEnterprise));
httpServer.post('/fuhuaqi/enterprise/updateregister', asyncHandler(updateRegisterEnterprise)); httpServer.post('/fuhuaqi/enterprise/updateregister', checkFuHuaQiToken, asyncHandler(updateRegisterEnterprise));
httpServer.post('/fuhuaqi/enterprise/move', asyncHandler(moveInEnterprise)); httpServer.post('/fuhuaqi/enterprise/move', checkFuHuaQiToken, asyncHandler(moveInEnterprise));
httpServer.post('/fuhuaqi/enterprise/updatemove', asyncHandler(updateMoveInEnterprise)); httpServer.post('/fuhuaqi/enterprise/updatemove', checkFuHuaQiToken, asyncHandler(updateMoveInEnterprise));
} }
/** /**
......
import moment = require("moment");
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../config/errorEnum";
import { BizError } from "./bizError"; import { BizError } from "./bizError";
const md5 = require("md5"); const md5 = require("md5");
...@@ -139,3 +140,23 @@ export function checkReqParam(conf, param) { ...@@ -139,3 +140,23 @@ export function checkReqParam(conf, param) {
export function getToken(uscc:string) { export function getToken(uscc:string) {
return md5(`${uscc}${new Date().valueOf()}${Math.ceil(Math.random() *100)}`); return md5(`${uscc}${new Date().valueOf()}${Math.ceil(Math.random() *100)}`);
} }
/**
* 根据conf截取data中的数据
* @param conf
* @param data
* @returns
*/
export function extractData(conf, data) {
let result = {};
for (let key in conf) {
let confInfo = conf[key];
if (confInfo.changeDate) {
result[key] = moment(data[key]).format("YYYY-MM-DD");
}else {
result[key] = data[key];
}
}
return result;
}
\ 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