Commit b7e6c76a by lixinming

2.0分数

parent ba0f10c9
......@@ -7,5 +7,8 @@
<dataBase>baseDB</dataBase>
<wtimeoutMS>30000</wtimeoutMS>
</mongodb>
<secret>5907d55efdd2f6b3e11e719b8d781111</secret>
<appId>wxbfc5695971b3e395</appId>
<getOpenIdUrl>https://api.weixin.qq.com/sns/jscode2session</getOpenIdUrl>
</config>
\ No newline at end of file
......@@ -102,20 +102,23 @@ export async function outPutFinancingList(monthData:string, fuHuaQiName:string,
/**拼接返回 需要注意的是 keyList要和titleList一一对应 */
let keyList = [
"name", "logonAdd", "operatingAdd", "financingAmount","investmentInstitutionsName",
"name", "uscc", "fuhuaqiUscc","logonAdd", "logonTime", "industry", "financingRounds", "operatingAdd", "financingAmount","investmentInstitutionsName",
"timeToObtainInvestment", "fuHuaQiInvestment", "fuHuaQiInvestmentAmount", "fuHuaQiInvestmentStyle", "createTime"
];
let titleList = [
"企业名称","注册地址","经营地址","融资金额(万元)","投资机构名称","获得投资时间",
"企业名称", "信用代码", "所属孵化器","注册地址","注册时间", "行业领域", "融资轮次", "经营地址","融资金额(万元)","投资机构名称","获得投资时间",
"孵化器是否投资","孵化器投资金额(万元)","孵化器投资方式","录入时间",
];
let result = [titleList];
dataBaseList.forEach( info => {
/**截取返回字段 */
let changeData:any = extractData(splitResultConfig.FinancingListConfig, info, true);
changeData.fuhuaqiUscc = usccMap[info.fuHuaQiUscc] || "";
changeData.industry = changeEnumValue(configEnum.INDUSTRY, info.industry);
changeData.financingRounds = changeEnumValue(configEnum.FINANCINGROUNDS, info.financingRounds);
changeData.fuHuaQiInvestmentStyle = changeEnumValue(configEnum.FUHUAQILNVESTMENTSTYLE, info.fuHuaQiInvestmentStyle);
/**根据keyList的顺序生成小数组 */
let subList = [];
keyList.forEach(keyStr => {
......
......@@ -270,6 +270,8 @@ export async function addUser(param) {
const Pwd = param.uscc.slice(param.uscc.length-6);
param.pwd = getPwdMd5(param.uscc, md5PwdStr(Pwd));
param.createTime = new Date().valueOf();
await fuhuaqiData.createFuHuaQiUser(param);
let addList = [];//任务列表
......@@ -285,9 +287,9 @@ export async function addUser(param) {
fuHuaQiList.forEach(info => {
let { uscc } = info;
let taskId = getTaskId(uscc);
addList.push( { key:TimeKey, type:configEnum.TASKTYPEENUM.孵化器月度填报, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false},
{ key:TimeKey, type:configEnum.TASKTYPEENUM.新注册或迁入企业登记, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false },
{ key:TimeKey, type:configEnum.TASKTYPEENUM.融资企业填报, taskId, month:MonthNumber, fuHuaQiUscc:uscc, isSubmit:false});
addList.push( { key:TimeKey, type:configEnum.TASKTYPEENUM.孵化器月度填报, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false, year:YearNumber},
{ key:TimeKey, type:configEnum.TASKTYPEENUM.新注册或迁入企业登记, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false , year:YearNumber},
{ key:TimeKey, type:configEnum.TASKTYPEENUM.融资企业填报, taskId, month:MonthNumber, fuHuaQiUscc:uscc, isSubmit:false, year:YearNumber});
/**任务报表的初始状态为 草稿(draftLock=fals) 未被编辑(isUpdate=false) */
monthList.push({ taskId, name:MonthTableName, fuHuaQiUscc:uscc, month:MonthNumber, year:YearNumber, draftLock:false, isUpdate:false });
});
......
......@@ -3,11 +3,13 @@
import * as monthTableData from "../../data/fuHuaQi/monthTable";
import * as taskData from "../../data/fuHuaQi/task";
import * as enterpriseData from "../../data/enterprise/enterprise";
import { FUHUASTATE, TASKTYPEENUM } from "../../config/enum";
import { FUHUASTATE, SCOREWAYS, TASKTYPEENUM } from "../../config/enum";
import { ERRORENUM } from "../../config/errorEnum";
import { findAllNotDisabledFuHuaQi } from "../../data/fuHuaQi/fuhuaqi";
import { findAllNotDisabledFuHuaQi, findFuHuaQiList } from "../../data/fuHuaQi/fuhuaqi";
import { BizError } from "../../util/bizError";
import { logHandle } from "../../util/log";
import { initFuHuaQiScore } from "../../data/fuHuaQi/score";
import { updateScore } from "../mobileFuHuaQi/fuHuaQi/score";
......@@ -57,3 +59,41 @@ export async function updateFuHuaQiTaskYear() {
await taskData.updateTaskYearData(2023);
return {};
}
export async function initScoreData() {
let data = await findFuHuaQiList({});
let addList = [];
data.forEach(info => {
addList.push({
uscc:info.uscc,//孵化器uscc
startScore: 400,//初始分 400 创建孵化器的时候要在这里加上
lastYearStar: 3,//去年星值 这里默认是3星 每年12月31日12时,需要根据分算星然后更新到这里
myDataScore: 0,//我的数据获得的分数
baseDataScore: 0,//基础数据获得的分数
myEnterpriseScore: 0,//我的企业获得的分数
taskScore: 0,//任务获得分数
updateTime: new Date().valueOf(),//更新时间戳
/**上一次评分 */
lastScore:0//在获取列表的时候要同步数据
});
});
await initFuHuaQiScore(addList);
for (let i =0; i < data.length; i++) {
let {uscc} = data[i];
await updateScore(uscc, SCOREWAYS.我的企业数据, false);
await updateScore(uscc, SCOREWAYS.我的信息, false);
await updateScore(uscc, SCOREWAYS.我的数据, false);
}
/**初始化任务得分 */
let taskList = await taskData.findTaskListByParam({});
for (let i =0; i < taskList.length; i++) {
let {fuHuaQiUscc, isSubmit, type} = taskList[i];
if ( isSubmit ) await updateScore(fuHuaQiUscc, SCOREWAYS.任务得分, true, type);
else await updateScore(fuHuaQiUscc, SCOREWAYS.任务得分, false, type);
}
console.log("初始化评分成功");
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import * as configEnum from "../../../config/enum";
import { eccFormParam } from "../../../util/verificationParam";
import * as verificationEnumTools from "../../../util/verificationEnum";
import { checkChange, extractData } from "../../../util/piecemeal";
import * as scoreBiz from "../fuHuaQi/score";
/**
......@@ -37,6 +38,7 @@ export async function registerEnterprise(uscc:string, param) {
param.draftId = sysTools.getDraftId(uscc);//草稿箱id
param.isCreate = true;//标识此次操作是否是新注册企业并不是迁入企业
const TaskId = sysTools.getTaskId(uscc);
param.state = configEnum.FUHUASTATE.实体孵化;
await enterpriseData.createEnterprise(uscc, TaskId, param);
return {isSuccess:true};
......@@ -97,6 +99,8 @@ export async function moveInEnterprise(uscc:string, param) {
param.draftId = sysTools.getDraftId(uscc);//草稿箱id
param.isCreate = false;//标识此次操作是否是迁入企业并不是新注册企业
const TaskId = sysTools.getTaskId(uscc);
param.state = configEnum.FUHUASTATE.实体孵化;//默认就是实体孵化
await enterpriseData.createEnterprise(uscc, TaskId, param);
return {isSuccess:true};
......@@ -384,6 +388,9 @@ export async function updateMyEnterpriseBaseInfo(fuHuaQiUscc:string, param) {
await enterpriseInfo.save();
/**更新分数 */
await scoreBiz.updateScore(fuHuaQiUscc, configEnum.SCOREWAYS.我的企业数据, false);
return {isSuccess:true};
}
......
......@@ -14,6 +14,7 @@ import { BizError } from "../../../util/bizError";
import { ERRORENUM } from "../../../config/errorEnum";
import { eccFormParam } from "../../../util/verificationParam";
import { changeEnumValue, eccEnumValue } from "../../../util/verificationEnum";
import * as scoreBiz from "./score";
/**
......@@ -104,12 +105,15 @@ export async function updateFuHuaQiBaseData(uscc:string, param) {
await baseDataInfo.save();
/**更新分数 */
await scoreBiz.updateScore(uscc, configEnum.SCOREWAYS.我的数据, false);
return {isSuccess:true};
}
/**
* 更新孵化器机构信息数据
* 更新孵化器机构信息数据 (我的信息)
* 小程序端
* @param uscc 孵化器统一信用代码
* @param param 表单内容
......@@ -148,6 +152,9 @@ export async function updateOrganizationData(uscc:string, param) {
await baseDataInfo.save();
/**更新分数 */
await scoreBiz.updateScore(uscc, configEnum.SCOREWAYS.我的信息, false);
return {isSuccess:true};
}
......
......@@ -2,60 +2,38 @@
* 分数
*/
import { CHANGEMODE, SCOREWAYS } from "../../../config/enum";
import { FuHuaQiMyDataScoreConfig, ScoreConfig, FuHuaQiBaseDataScoreConfig, EnterpriseScoreConfig, StarConfig } from "../../../config/scoreConfig";
import { findEnterpriseList } from "../../../data/enterprise/enterprise";
import { findFuHuaQiByUSCC } from "../../../data/fuHuaQi/fuhuaqi";
import { findTaskListByParam } from "../../../data/fuHuaQi/task";
import * as scoreData from "../../../data/fuHuaQi/score";
import * as scoreLogData from "../../../data/fuHuaQi/scoreLog";
/**
* 统计孵化器分数
* @param uscc 孵化器统一信用代码
* 获取 孵化器 分数
* @param uscc
*/
export async function MyScore(uscc:string) {
let fuHuaQiInfo = await findFuHuaQiByUSCC(uscc);
/** 初始分*/
let startScore = fuHuaQiInfo.startScore || 400;
/**我的数据分 */
let isValueCount = 0;
let valueCount = Object.keys(FuHuaQiMyDataScoreConfig).length;
for (let key in FuHuaQiMyDataScoreConfig) {
let type = FuHuaQiMyDataScoreConfig[key];
if (type == '[Object]' || type == '[Number]') {
if (fuHuaQiInfo[key] && fuHuaQiInfo[key].length) isValueCount += 1;
} else if (fuHuaQiInfo[key]) isValueCount += 1;
}
let myDataScore = ScoreConfig["我的数据"] * (isValueCount / valueCount);
/**基础数据分 */
isValueCount = 0;
valueCount = Object.keys(FuHuaQiBaseDataScoreConfig).length;
for (let key in FuHuaQiBaseDataScoreConfig) {
let type = FuHuaQiBaseDataScoreConfig[key];
if (type == '[Object]' || type == '[Number]') {
if (fuHuaQiInfo[key] && fuHuaQiInfo[key].length) isValueCount += 1;
} else if (fuHuaQiInfo[key]) isValueCount += 1;
}
let baseDataScore = ScoreConfig["孵化器基础数据"] * (isValueCount / valueCount);
export async function getFuHuaQiScore(uscc:string) {
/**计算总分是否和展示分一样 */
/**得分信息 */
let scoreInfo = await scoreData.findFuHuaQiScoreInfo(uscc);
/**我的企业数据分 */
let myEnterpriseScore = await myEnterpriseScoreCount(uscc);
let { startScore, lastYearStar, myDataScore, baseDataScore, myEnterpriseScore, taskScore, lastScore } = scoreInfo;
let count = Math.ceil(startScore +lastYearStar +myDataScore +baseDataScore +myEnterpriseScore +taskScore);
/**任务分 */
let taskScore = await taskScoreCount(uscc);
let oldStar = starCount(lastScore);
let newStar = starCount(count);
let newScore = startScore + myDataScore + baseDataScore + myEnterpriseScore + taskScore;
let oldScore = fuHuaQiInfo.socre;
/**根据分数算星星 */
let oldStar = starCount(oldScore);
let newStar = starCount(newScore);
let scoreChange = (count - lastScore) > 0 ? count - lastScore : 0;
let starUp = newStar > oldStar;
/**将分数写入数据 用于下一次比对 */
fuHuaQiInfo.socre = newScore;
await fuHuaQiInfo.save();
return {scoreInfo:{star:newStar, starUp, score:newScore-oldScore}};
scoreInfo.lastScore = count;
await scoreInfo.save();
let url = `/images/${newStar}.png`;
return {scoreChange, score:count, starUp, star:newStar, url};
}
......@@ -78,22 +56,99 @@ function starCount(socre:number) {
/**
* 算任务分数
* 更新孵化器得分
* @param uscc 孵化器统一信用代码
* @returns 任务得分
* @param type 类别
* @param subType 子类别
* @param isSubmitTask 是否是填报任务 提交任务调用时这里是true 其他都是false
* 由于不提交任务要扣分,并且分值不一样,所以这里要考虑传入触发状态
*/
async function taskScoreCount(uscc:string) {
let taskList = await findTaskListByParam({fuHuaQiUscc:uscc});
let should = taskList.length;
let completed = 0;//已完成
let unfinished = 0;//未完成
taskList.forEach(info => {
if ( info.isSubmit ) completed += 1;
else unfinished += 1;
});
let addScoreParam = ScoreConfig["任务分数_加分"] * 3 * 12;
let subtractionScoreParam = ScoreConfig["任务分数_扣分"] * 3 * 12;
return (addScoreParam * (completed/should) ) - ( subtractionScoreParam * (unfinished/should) );
export async function updateScore(uscc:string, type:number, isSubmitTask:boolean, subType?) {
/**得分信息 */
let scoreInfo = await scoreData.findFuHuaQiScoreInfo(uscc);
let fuHuaQiInfo = await findFuHuaQiByUSCC(uscc);
let newScore = 0;//新分数
let oldScore = 0;//老分数
let countScore = scoreInfo.startScore +scoreInfo.lastYearStar +scoreInfo.myDataScore +scoreInfo.baseDataScore +scoreInfo.myEnterpriseScore +scoreInfo.taskScore;
switch (type) {
case SCOREWAYS.任务得分:
/**单个任务得分 */
let createMonth = !fuHuaQiInfo.createTime ? 0 : new Date(fuHuaQiInfo.createTime).getMonth();
if (isSubmitTask) newScore = getOnceTaskScore(createMonth);
else newScore = getOnceTaskDeductScore(createMonth);
/**赋值新的分数 */
scoreInfo.taskScore = scoreInfo.taskScore + newScore
break;
case SCOREWAYS.我的信息:
case SCOREWAYS.我的数据:
let scoreParamKeyConfig = {};
let scoreConfigNumber=0;
if (type == SCOREWAYS.我的数据) {
scoreParamKeyConfig = FuHuaQiMyDataScoreConfig;
scoreConfigNumber = ScoreConfig["我的数据"];
oldScore = scoreInfo.myDataScore;
}else {
scoreParamKeyConfig = FuHuaQiBaseDataScoreConfig;
scoreConfigNumber = ScoreConfig["孵化器基础数据"];
oldScore = scoreInfo.baseDataScore;
}
let isValueCount = 0;
for (let key in scoreParamKeyConfig) {
let keyType = scoreParamKeyConfig[key];
if (keyType == '[Object]' || keyType == '[Number]') {
if (fuHuaQiInfo[key] && fuHuaQiInfo[key].length) isValueCount += 1;
} else if (fuHuaQiInfo[key]) isValueCount += 1;
}
let valueCount = Object.keys(scoreParamKeyConfig).length;
newScore = scoreConfigNumber * (isValueCount / valueCount);
/**赋值新的分数 */
type == SCOREWAYS.我的数据 ? scoreInfo.myDataScore = newScore : scoreInfo.baseDataScore = newScore;
break;
case SCOREWAYS.我的企业数据:
newScore = await myEnterpriseScoreCount(uscc);
oldScore = scoreInfo.myEnterpriseScore;
/**赋值新的分数 */
scoreInfo.myEnterpriseScore = newScore;
break;
};
/**分数没有变化 */
if (oldScore == newScore) return;
let changeMode = oldScore > newScore ? CHANGEMODE.减少 : CHANGEMODE.增加;
let newCountScore = countScore - oldScore + newScore;
if (SCOREWAYS.任务得分 == type) {
newScore = -1 * newScore;
await scoreLogData.addLog(uscc, type, changeMode, newCountScore, newScore, subType);
} await scoreLogData.addLog(uscc, type, changeMode, newCountScore, newScore);
scoreInfo.updateTime = new Date().valueOf();
await scoreInfo.save();
}
/**
* 算单个任务得分
* @param month 入住月份 如果是去年 就是0 范围是0-11
* @returns
*/
function getOnceTaskScore(month:number) {
let thisMonthTaskCount = 3; //后续接入任务可编辑要改这里
return (ScoreConfig["任务常量_加分"]/(12-month)) * (1/thisMonthTaskCount);
}
/**
* 算单个任务扣分
* @param month 入住月份 如果是去年 就是0 范围是0-11
* @returns
*/
function getOnceTaskDeductScore(month:number) {
let thisMonthTaskCount = 3; //后续接入任务可编辑要改这里
return -((ScoreConfig["任务常量_扣分"]/(12-month)) * (1/thisMonthTaskCount));
}
......@@ -119,8 +174,6 @@ async function myEnterpriseScoreCount(uscc:string) {
valueCount += Object.keys(EnterpriseScoreConfig).length;
});
if (!valueCount) return ScoreConfig["企业基础数据"];
return ScoreConfig["企业基础数据"] * (isValueCount / valueCount);
}
// async function
......@@ -13,7 +13,7 @@
*/
import moment = require("moment");
import { TASKTYPEENUM } from "../../../config/enum";
import { SCOREWAYS, TASKTYPEENUM } from "../../../config/enum";
import { ERRORENUM } from "../../../config/errorEnum";
import { findEnterpriseListByTaskId, updateEnterpriseDraftLock } from "../../../data/enterprise/enterprise";
import { findFinancingListByTaskId, updateFinancingDraftLock } from "../../../data/enterprise/financing";
......@@ -22,7 +22,8 @@ import * as monthTableData from "../../../data/fuHuaQi/monthTable";
import * as taskData from "../../../data/fuHuaQi/task";
import { BizError } from "../../../util/bizError";
import { logHandle } from "../../../util/log";
import { getTaskId, getTaskIdByTime, getTimeKey } from "../../../tools/system";
import { getLastMonthTimeKey, getTaskId, getTaskIdByTime, getTimeKey } from "../../../tools/system";
import * as scoreBiz from "../fuHuaQi/score";
/**
......@@ -151,6 +152,7 @@ export async function fuHuaQiCompletedList(uscc:string, selectTime:number) {
return {taskList:result};
}
/**
* 孵化器 过期任务列表
* 小程序端 2.0
......@@ -216,7 +218,6 @@ export async function fuHuaQiPastdueList(uscc:string, selectTime:number) {
}
/**
* 提交任务
* 小程序端
......@@ -241,14 +242,21 @@ export async function checkTask(uscc:string, taskType:number) {
monthTableInfo.draftLock = true;
await monthTableInfo.save();
/**更新分数 */
await scoreBiz.updateScore(uscc, SCOREWAYS.任务得分, true, TASKTYPEENUM.孵化器月度填报);
break;
case TASKTYPEENUM.新注册或迁入企业登记:
/**将录入的企业数据 draftLock 改为 true 表示不再是草稿状态 */
await updateEnterpriseDraftLock(TaskId);
/**更新分数 */
await scoreBiz.updateScore(uscc, SCOREWAYS.任务得分, true, TASKTYPEENUM.新注册或迁入企业登记);
break;
case TASKTYPEENUM.融资企业填报:
/**将录入的融资数据 draftLock 改为 true 表示不再是草稿状态 */
/**将录入的融资数据 draftLock 改为 true 表示不再是草稿状态 */
await updateFinancingDraftLock(TaskId);
/**更新分数 */
await scoreBiz.updateScore(uscc, SCOREWAYS.任务得分, true, TASKTYPEENUM.融资企业填报);
break;
}
......@@ -279,16 +287,16 @@ export async function provideTask() {
let monthList = [];//月度填报列表
const MonthNumber = moment().subtract(1, 'months').month() + 1;//数据填报月份
const YearNumber =moment().subtract(1, 'months').year();
const YearNumber =moment().subtract(1, 'months').year();//数据填报年份
const MonthTableName = `${MonthNumber}月孵化器月度填报`;
let fuHuaQiList = await findAllNotDisabledFuHuaQi();
fuHuaQiList.forEach(info => {
let { uscc } = info;
let taskId = getTaskId(uscc);
addList.push( { key:TimeKey, type:TASKTYPEENUM.孵化器月度填报, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false},
{ key:TimeKey, type:TASKTYPEENUM.新注册或迁入企业登记, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false },
{ key:TimeKey, type:TASKTYPEENUM.融资企业填报, taskId, month:MonthNumber, fuHuaQiUscc:uscc, isSubmit:false});
addList.push( { key:TimeKey, type:TASKTYPEENUM.孵化器月度填报, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false, year:YearNumber},
{ key:TimeKey, type:TASKTYPEENUM.新注册或迁入企业登记, month:MonthNumber, taskId, fuHuaQiUscc:uscc, isSubmit:false , year:YearNumber},
{ key:TimeKey, type:TASKTYPEENUM.融资企业填报, taskId, month:MonthNumber, fuHuaQiUscc:uscc, isSubmit:false, year:YearNumber});
/**任务报表的初始状态为 草稿(draftLock=fals) 未被编辑(isUpdate=false) */
monthList.push({ taskId, name:MonthTableName, fuHuaQiUscc:uscc, month:MonthNumber, year:YearNumber, draftLock:false, isUpdate:false });
});
......@@ -306,3 +314,25 @@ export async function provideTask() {
}
/**
* 回收任务分数
*/
export async function retrieveTask() {
/**获取上个月 时间key */
let TimeKey = getLastMonthTimeKey();
let notSubmitList = await taskData.findTaskListByParam({key:TimeKey, isSubmit:false});
for (let i = 0; i < notSubmitList.length; i++) {
let uscc = "";
try {
let { fuHuaQiUscc, type } = notSubmitList[i];
uscc = fuHuaQiUscc;
await scoreBiz.updateScore(fuHuaQiUscc, SCOREWAYS.任务得分, false, type);
} catch (err) {
new BizError(ERRORENUM.系统错误, `回收任务时出现错误 uscc:${uscc} TimeKey:${TimeKey}`, err);
}
}
logHandle(`${TimeKey} 任务回收成功=> 分数更新成功(${notSubmitList.length})条`);
}
\ No newline at end of file
......@@ -6,14 +6,13 @@
* 密码规则:6-18位 只允许有数字和字符,可以只有数字也可以只有字母 不允许有特殊字符 2023年02月21日确定需求
*/
import * as eccFormParamConfig from "../../../config/eccFormParamConfig";
import { ERRORENUM } from "../../../config/errorEnum";
import * as splitResultConfig from "../../../config/splitResultConfig";
import { ERRORCODEENUM, ERRORENUM } from "../../../config/errorEnum";
import * as fuhuaqiData from "../../../data/fuHuaQi/fuhuaqi"
import { BizError } from "../../../util/bizError";
import * as sysTools from "../../../tools/system";
import { eccFormParam } from "../../../util/verificationParam";
import { extractData } from "../../../util/piecemeal";
import { get } from "../../../util/request";
import { systemConfig } from "../../../config/serverConfig";
/**
......@@ -129,7 +128,10 @@ export async function logout(uscc:string){
* @param bindPwd 被绑定账号密码
* @param deviceId 绑定时的设备号id
*/
export async function bindFuHuaQi(uscc:string, bindUscc:string, bindPwd:string, deviceId:string) {
export async function bindFuHuaQi(uscc:string, bindUscc:string, bindPwd:string, code:string) {
/**获取微信的openid */
let openId = await getOpenId(code);
/**校验被绑定账号存不存在 */
let bindFuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUSCC(bindUscc);
if (!bindFuhuaqiInfo) throw new BizError(ERRORENUM.账号不存在, `绑定账号时 =${bindUscc}=`);
......@@ -145,11 +147,11 @@ export async function bindFuHuaQi(uscc:string, bindUscc:string, bindPwd:string,
const BindId = !fuhuaqiInfo.bindId ? sysTools.getBindId(uscc, bindUscc) : fuhuaqiInfo.bindId;
bindFuhuaqiInfo.bindId = BindId;
bindFuhuaqiInfo.bindDeviceId = deviceId;
bindFuhuaqiInfo.bindDeviceId = openId;
await bindFuhuaqiInfo.save();
/**直接覆盖发起账号的设备信息 */
fuhuaqiInfo.bindDeviceId = deviceId;
fuhuaqiInfo.bindDeviceId = openId;
fuhuaqiInfo.bindId = BindId;
await fuhuaqiInfo.save();
......@@ -163,15 +165,20 @@ export async function bindFuHuaQi(uscc:string, bindUscc:string, bindPwd:string,
* @param uscc 孵化器统一信用代码
* @param deviceId 当前设备号id
*/
export async function bindUserList(uscc:string, deviceId:string) {
export async function bindUserList(uscc:string, code:string) {
/**获取微信的openid */
let openId = await getOpenId(code);
/**发起账号信息 */
let fuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);
/**找绑定关系 */
/**
* 找绑定关系
* 原始需求:更换设备绑定之后,换回以前的设备是无法看到绑定关系的
* */
let bindList = [];
if (fuhuaqiInfo.bindId && fuhuaqiInfo.bindDeviceId && deviceId == fuhuaqiInfo.bindDeviceId ) {
let checkList = await fuhuaqiData.findFuHuaQiList({ bindId:fuhuaqiInfo.bindId, deviceId:deviceId });
if (fuhuaqiInfo.bindId && fuhuaqiInfo.bindDeviceId && openId == fuhuaqiInfo.bindDeviceId ) {
let checkList = await fuhuaqiData.findFuHuaQiList({ bindId:fuhuaqiInfo.bindId, bindDeviceId:openId });
checkList.forEach(info => {
let currentAccount = info.uscc == fuhuaqiInfo.uscc;
bindList.push({
......@@ -216,4 +223,22 @@ export async function changeUser(uscc:string, targetUscc:string) {
firstLogin : !targetFuhuaqiInfo.firstLoginIsChangePwd,
token:Token
};
}
async function getOpenId(code:string) {
let param = {
js_code:code,
secret:systemConfig.secret,
appid:systemConfig.appId,
grant_type:"authorization_code"
};
let weixinRes:any = await get(systemConfig.getOpenIdUrl, param);
if (!weixinRes) throw new BizError(ERRORENUM.code无效, code);
if (weixinRes.errcode == ERRORCODEENUM.code无效) throw new BizError(ERRORENUM.code无效, code);
if (weixinRes.errcode == ERRORCODEENUM.频繁操作请稍后再试) throw new BizError(ERRORENUM.频繁操作请稍后再试, code);
if (weixinRes.errcode == ERRORCODEENUM.高风险等级用户) throw new BizError(ERRORENUM.高风险等级用户, code);
if (weixinRes.errcode == -1) throw new BizError(ERRORENUM.系统繁忙, code);
if (!weixinRes.openid) throw new BizError(ERRORENUM.绑定失败, code);
return weixinRes.openid;
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
import { findTaskCountByKey } from "../data/fuHuaQi/task";
import { getTimeKey } from "../tools/system";
import { provideTask } from "./mobileFuHuaQi/fuHuaQi/task";
import { provideTask, retrieveTask } from "./mobileFuHuaQi/fuHuaQi/task";
export function initSystemTask() {
fuHuaQiTask();
......@@ -18,12 +18,16 @@ export function initSystemTask() {
console.log(`systemTask init success`);
}
async function fuHuaQiTask() {
const Key = getTimeKey();
let count = await findTaskCountByKey(Key);
if (count != 0) return;
/**生成新的任务 */
await provideTask();
/**回收旧任务计算分数 */
await retrieveTask();
}
......
......@@ -204,3 +204,24 @@ export enum MOVEOUTCAUSE{
产业环境不足,
其他
}
/**
* 得分途径
*/
export enum SCOREWAYS {
我的信息 = 1,
我的数据,
我的企业数据,
任务得分
}
/**
* 分数变化方式
*/
export enum CHANGEMODE {
增加 = 1,
减少
}
......@@ -29,13 +29,22 @@ export enum ERRORENUM {
该任务已提交,
无法操作其他孵化器的企业,
请填入其他原因,
账号非绑定关系
账号非绑定关系,
code无效,
频繁操作请稍后再试,
高风险等级用户,
系统繁忙,
绑定失败
}
export enum ERRORCODEENUM {
身份验证失败 = 401,
非法登录 = 402,
身份验证过期 = 403
身份验证过期 = 403,
code无效 = 40029,
频繁操作请稍后再试 = 45011,
高风险等级用户 = 40226,
系统繁忙 = 40227
}
let bizErrorMsgMap = {};
......
......@@ -3,8 +3,8 @@ export const ScoreConfig = {
"我的数据":25,
"孵化器基础数据":25,
"企业基础数据":50,
"任务分数_扣分":10,
"任务分数_加分":5,
"任务常量_扣分":360,
"任务常量_加分":180,
}
export const StarConfig = [
......
......@@ -16,9 +16,13 @@ export async function initConfig() {
if (!configInfo || !configInfo.config) throw new BizError('xml中无配置');
else {
let {port, mongodb } = configInfo.config;
let {port, mongodb, secret, getOpenIdUrl, appId } = configInfo.config;
systemConfig.port = parseInt(port[0]);
systemConfig.secret = secret[0];
systemConfig.getOpenIdUrl = getOpenIdUrl[0];
systemConfig.appId = appId[0];
const MongoPath = mongodb[0].path[0];
const MongoPort = mongodb[0].port[0];
const MongoW = mongodb[0].w[0];
......
......@@ -6,5 +6,8 @@
export class ServerConfig {
port:number;
mongodbStr:string
mongodbStr:string;
secret:string;
getOpenIdUrl:string;
appId:string;
}
\ No newline at end of file
......@@ -58,10 +58,6 @@ const fuHuaQiSchema = new Schema({
/**绑定账号相关 */
bindDeviceId:String,//绑定时的设备号
bindId:{type:String},//绑定标识
/**分数相关 */
score:Number,//分数
startScore:Number,//初始分 400 创建孵化器的时候要在这里加上
lastYearStar:Number,//去年星值 这里默认是3星 每年12月31日12时,需要根据分算星然后更新到这里
});
var fuHuaQiModel;
......
/**
* 得分表
* 记录孵化器分数
*
*/
import {Schema} from 'mongoose';
import { baseDB } from '../../db/mongo/dbInit';
const fuHuaQiScoreSchema = new Schema({
uscc:{type:String, index:true},//孵化器uscc
startScore:{type:Number, default:400},//初始分 400 创建孵化器的时候要在这里加上
lastYearStar:{type:Number, default:3},//去年星值 这里默认是3星 每年12月31日12时,需要根据分算星然后更新到这里
myDataScore:{type:Number, default:0},//我的数据获得的分数
baseDataScore:{type:Number, default:0},//基础数据获得的分数
myEnterpriseScore:{type:Number, default:0},//我的企业获得的分数
taskScore:{type:Number, default:0},//任务获得分数
updateTime:{type:Number, default:0},//更新时间戳
/**上一次评分 */
lastScore:{type:Number, default:0}//在获取列表的时候要同步数据
});
var fuHuaQiScoreModel;
export function initModel(){
fuHuaQiScoreModel = baseDB.model('fuhuaqiscore', fuHuaQiScoreSchema);
fuHuaQiScoreModel.selectOnceData = async function (paramater:object) {
let selectInfo = await fuHuaQiScoreModel.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 findFuHuaQiScoreInfo(uscc:string) {
return await fuHuaQiScoreModel.selectOnceData({uscc});
}
/**
* 创建分数信息
* @param uscc 孵化器统一信用代码
*/
export async function createFuHuaQiScore(uscc:string) {
return await fuHuaQiScoreModel.create({uscc, updateTime:new Date().valueOf() });
}
export async function initFuHuaQiScore(array) {
return await fuHuaQiScoreModel.insertMany(array);
}
/**
* 得分日志表
*
*
*/
import {Schema} from 'mongoose';
import { baseDB } from '../../db/mongo/dbInit';
const fuHuaQiScoreLogSchema = new Schema({
uscc:{type:String, index:true},//孵化器uscc
ways:Number,//途径 遵循枚举 SCOREWAYS 值
taskType:Number,//任务类型 遵循枚举 TASKTYPEENUM 值
changeMode:Number,//分数变化方式 遵循枚举 CHANGEMODE 值
score:Number,//分数
addScore:Number,//增加/减少的分数
timeMs:{type:Number, index:true}//获得时间 时间戳
});
var fuHuaQiScoreLogModel;
export function initModel(){
fuHuaQiScoreLogModel = baseDB.model('fuhuaqiscorelog', fuHuaQiScoreLogSchema);
}
/**
* 添加得分日志
* @param ways 途径
* @param changeMode 增加或减少
* @param uscc 孵化器uscc
* @param score 分数
* @param addScore 增加/删除分数
* @param taskType 任务类型 选填
*/
export async function addLog(uscc:string, ways:number, changeMode:number, score:number, addScore:number, taskType?) {
let addInfo:any = {uscc, ways, changeMode, score, addScore, timeMs:new Date().valueOf() };
if (taskType) addInfo.taskType = taskType;
await fuHuaQiScoreLogModel.create(addInfo);
}
/**
* 批量添加得分日志
* @param addList 添加列表
*/
export async function addMany(addList) {
await fuHuaQiScoreLogModel.insertMany(addList);
}
/**
* 获取得分列表
* @param uscc 孵化器uscc
*
*/
export async function getLog(uscc:string, startTime:number, endTime:number) {
// await fuHuaQiScoreModel.create({uscc, score, addScore, timeMs:new Date().valueOf() });
}
\ No newline at end of file
......@@ -70,12 +70,15 @@ export async function findEnterpriseByTaskIdAndType(taskId:string, type:number)
}
export async function findTaskCountByKey(key:string) {
export async function findTaskCountByKey(key:number) {
return await fuHuaQiTaskModel.find({key}).count();
}
/**
* 批量创建任务
* @param taskList 任务列表
*/
export async function createTaskToList(taskList:object) {
await fuHuaQiTaskModel.insertMany(taskList);
}
......
......@@ -4,6 +4,8 @@ import * as enterpriseinModel from "../../data/enterprise/enterprise";
import * as financinginModel from "../../data/enterprise/financing";
import * as monthTableModel from "../../data/fuHuaQi/monthTable";
import * as guanweihuiModel from "../../data/guanWeiHui/guanweihui";
import * as scoreModel from "../../data/fuHuaQi/score";
import * as scoreLogModel from "../../data/fuHuaQi/scoreLog";
export async function initTable() {
taskinModel.initModel();
......@@ -12,4 +14,6 @@ export async function initTable() {
financinginModel.initModel();
monthTableModel.initModel();
guanweihuiModel.initModel();
scoreModel.initModel();
scoreLogModel.initModel();
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ async function lanuch() {
await initConfig();//初始化配置解析
await initDB();
await initBasicData();
// await initSystemTask();
await initSystemTask();
httpServer.createServer(systemConfig.port);
console.log('This indicates that the server is started successfully.');
......
......@@ -27,6 +27,7 @@ export class httpServer {
// }
});
httpServer.use(express.static("./static") );
const root = path.join(__dirname, "../../public");
httpServer.use(express.static(root));
httpServer.use(fallback('index.html', { root }));
......
......@@ -20,31 +20,10 @@ export function setRouter(httpServer) {
httpServer.post('/admin/fuhuaqi/adduser',checkGuanWeiHuiToken,asyncHandler(addUser));
httpServer.post('/admin/data/output/fuhuaqi',checkGuanWeiHuiToken, asyncHandler(outPutFuHuaQiData));
httpServer.post('/admin/data/output/month',checkGuanWeiHuiToken, asyncHandler(outPutMonthData));
/**测试接口 用于发放1月份任务 */
httpServer.post('/admin/provide/task/add12',checkInterior, asyncHandler(provideLastTask));
httpServer.post('/admin/provide/enterprise/updatestate',checkInterior, asyncHandler(updateEnterpriseState));
httpServer.post('/admin/provide/task/updatetaskyear',checkInterior, asyncHandler(updateTaskYear));
}
async function updateTaskYear(req, res) {
let data = await provideBiz.updateEnterpriseFuHuaState();
res.success({isUsccess:true});
}
async function updateEnterpriseState(req, res) {
let data = await provideBiz.updateEnterpriseFuHuaState();
res.success({isUsccess:true});
}
async function provideLastTask(req, res) {
await provideBiz.provideLastTask();
res.success({isUsccess:true});
}
/**
* 孵化器基本信息列表
* @param req
......
......@@ -38,7 +38,9 @@ export function setRouter(httpServer) {
async function baseInfo(req, res) {
const Uscc = req.headers.uscc;
let userInfo = await baseBiz.homeData(Uscc);
res.success(userInfo);
let scoreInfo = await scoreBiz.getFuHuaQiScore(Uscc);
let result = Object.assign(userInfo, { scoreInfo } );
res.success(result);
}
......@@ -112,7 +114,8 @@ async function taskList(req, res) {
const Uscc = req.headers.uscc;
let taskListObj = await taskBiz.fuHuaQiTaskList(Uscc);
/**拼接分数 */
let scoreObj = await scoreBiz.MyScore(Uscc);
// let scoreObj = await scoreBiz.MyScore(Uscc);
let scoreObj = {};
let result = Object.assign(scoreObj, taskListObj);
res.success(result);
}
......
......@@ -85,12 +85,12 @@ async function changePwd(req, res) {
* @param res
*/
async function bindUser(req, res) {
let reqConf = {bindUscc:'String', bindPwd:'String', deviceId:'String' };
let {bindUscc, bindPwd, deviceId} = eccReqParamater(reqConf, req.body);
let reqConf = {bindUscc:'String', bindPwd:'String', code:'String' };
let {bindUscc, bindPwd, code} = eccReqParamater(reqConf, req.body);
const Uscc = req.headers.uscc;
let result = await userBiz.bindFuHuaQi(Uscc, bindUscc, bindPwd, deviceId);
let result = await userBiz.bindFuHuaQi(Uscc, bindUscc, bindPwd, code);
res.success(result);
}
......@@ -103,12 +103,12 @@ async function bindUser(req, res) {
*/
async function bindList(req, res) {
let reqConf = { deviceId:'String' };
let { deviceId} = eccReqParamater(reqConf, req.body);
let reqConf = { code:'String' };
let { code} = eccReqParamater(reqConf, req.body);
const Uscc = req.headers.uscc;
let result = await userBiz.bindUserList(Uscc, deviceId);
let result = await userBiz.bindUserList(Uscc, code);
res.success(result);
}
......
/**
* 私有路由 用于维护迭代过程中造成的缺失数据
* 注意:需要保证每个路由都使用 checkInterior 中间件
*/
import * as asyncHandler from 'express-async-handler';
import * as provideBiz from '../biz/admin/provide';
import { checkInterior } from '../middleware/user';
export function setRouter(httpServer) {
httpServer.post('/admin/provide/task/add12',checkInterior, asyncHandler(provideLastTask));//已经弃用
httpServer.post('/admin/provide/enterprise/updatestate',checkInterior, asyncHandler(updateEnterpriseState));
httpServer.post('/admin/provide/task/updatetaskyear',checkInterior, asyncHandler(updateTaskYear));
httpServer.post('/admin/provide/task/initScore',checkInterior, asyncHandler(initScore));
}
/**
* 手动发放一月份任务
* 使用情况:1.0使用 已弃用
* @param req
* @param res
*/
async function provideLastTask(req, res) {
await provideBiz.provideLastTask();
res.success({isUsccess:true});
}
/**
* 添加任务的年份字段 用于筛选数据
* 使用情况:2.0使用
* @param req
* @param res
*/
async function updateTaskYear(req, res) {
await provideBiz.updateFuHuaQiTaskYear();
res.success({isUsccess:true});
}
/**
* 更新企业的状态为 在孵企业
* 使用情况:2.0使用
* @param req
* @param res
*/
async function updateEnterpriseState(req, res) {
await provideBiz.updateEnterpriseFuHuaState();
res.success({isUsccess:true});
}
/**
* 初始化所有孵化器分数
* 使用情况:2.0使用
* 备注:只能调用一次
* @param req
* @param res
*/
async function initScore(req, res) {
await provideBiz.initScoreData();
res.success({isUsccess:true});
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ import * as adminEnterpriseRouters from './admin/enterprise';
import * as adminFuHuaQiRouters from './admin/fuHuaQi';
import * as adminUserRouters from './admin/user';
import * as provideRouters from './provide';
export function setRouter(httpServer){
/**下拉框等公用 路由 */
......@@ -27,4 +29,6 @@ export function setRouter(httpServer){
adminEnterpriseRouters.setRouter(httpServer);
adminFuHuaQiRouters.setRouter(httpServer);
adminUserRouters.setRouter(httpServer);
/**系统维护 入口路由 */
provideRouters.setRouter(httpServer);
}
\ No newline at end of file
......@@ -38,8 +38,19 @@ export function getTaskIdByTime(uscc:string, timeMs:number) {
* @returns
*/
export function getTimeKey(timeMs?) {
if (timeMs) return `${new Date(timeMs).getFullYear()}${new Date(timeMs).getMonth() + 1 }`;
return `${new Date().getFullYear()}${new Date().getMonth() + 1 }`;
if (timeMs) return parseInt(`${new Date(timeMs).getFullYear()}${new Date(timeMs).getMonth() + 1 }`);
return parseInt(`${new Date().getFullYear()}${new Date().getMonth() + 1 }`);
}
/**
* 获取上一个月日期的key
* @param timeMs 指定时间,如果不传
* @returns
*/
export function getLastMonthTimeKey() {
let time = moment().subtract(1, 'months').valueOf();
return parseInt(`${new Date(time).getFullYear()}${new Date(time).getMonth() + 1 }`);
}
......
......@@ -5,6 +5,13 @@
import * as request from 'request';
import { BizError } from './bizError';
/**
* 请求接口(get)
* @param url 路由
* @param query 请求参数
* @param headers 请求头
* @returns
*/
export function get(url:string, query?, headers?) {
if (!url || (url.search(/http:/) && url.search(/https:/)) ) throw new BizError(!url ? "请求地址为空" : "请求地址错误");
return new Promise((resolve, reject)=>{
......
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