Commit b6ac022b by sxy

feat: 年报服务

parent b3dd4a11
......@@ -65,7 +65,7 @@ class CtlBase {
// if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"]
// }
if (!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey != "null" && req.xctx.fromcompanykey!="undefined") {
if (!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey != "null" && req.xctx.fromcompanykey != "undefined") {
let comptmp = await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid = comptmp.id;
}
......
......@@ -19,6 +19,9 @@ class DeliverCtl extends CtlBase {
val.customer_name = val.delivery_info.person;
val.updated_at = moment(val.updated_at).format('YYYY-MM-DD HH:mm:ss');
val.created_at = moment(val.created_at).format('YYYY-MM-DD HH:mm:ss');
if (val.delivery_status === system.ANNUALREPORT.TAKEEFFECT) {
val.delivery_status = val['annualreports.status'] || system.ANNUALREPORT.WAITDECLARE;
}
result.push(val);
}
rs.results.rows = result;
......@@ -123,5 +126,34 @@ class DeliverCtl extends CtlBase {
return system.getResult(null, err.message)
}
}
async findAnnualReportInfo(pobj) {
if (!pobj.id) {
return system.getResult(null, "id can not be empty,100290");
}
try {
const rs = await this.service.findAnnualReportInfo(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
async declareReport(pobj) {
if (!pobj.id) {
return system.getResult(null, "id can not be empty,100290");
}
if (!pobj.file || !pobj.file.url) {
return system.getResult(null, "file can not be empty,100290");
}
try {
const rs = await this.service.declareReport(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
}
module.exports = DeliverCtl;
......@@ -266,5 +266,8 @@ class Dao {
async findById(oid) {
return this.model.findById(oid);
}
async findAll(obj) {
return this.model.findAll({ "where": obj, row: true });
}
}
module.exports = Dao;
......@@ -79,6 +79,9 @@ class DbFactory {
this.db.models.qualification.belongsTo(this.db.models.deliver, { constraints: false, });
this.db.models.deliver.hasOne(this.db.models.qualification, { constraints: false, });
// 交付单表 1:n 年报信息表
this.db.models.deliver.hasMany(this.db.models.annualreport, { constraints: false })
}
//async getCon(){,用于使用替换table模型内字段数据使用
......
const system = require("../../../system");
const Dao = require("../../dao.base");
const url = require("url");
class AnnualreportDao extends Dao {
constructor() {
super(Dao.getModelName(AnnualreportDao));
}
}
module.exports = AnnualreportDao;
......@@ -10,21 +10,59 @@ class DeliverDao extends Dao {
}
extraWhere(qobj, qw, qc) {
qc.raw = true;
qc.where.product_code = qc.where.product_code && [system.SERVICECODE.EDI, system.SERVICECODE.ICP].includes(qc.where.product_code) ? qc.where.product_code : {
[this.db.Op.in]: [system.SERVICECODE.EDI, system.SERVICECODE.ICP]
}
let type = qobj.bizpath.split('/')[1];
if (type === 'deliveryManagement') {
qc.where.product_code = qc.where.product_code && [system.SERVICECODE.EDI, system.SERVICECODE.ICP].includes(qc.where.product_code) ? qc.where.product_code : {
[this.db.Op.in]: [system.SERVICECODE.EDI, system.SERVICECODE.ICP]
}
switch (qobj.bizpath) {
case "/deliveryManagement/wait":
qc.where.delivery_status = qc.where.delivery_status || {
[this.db.Op.in]: [system.SERVERSESTATUS.RECEIVED, system.SERVERSESTATUS.COLLECTING,
system.SERVERSESTATUS.SUBMITING, system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.POSTING
]
}
break
case "/deliveryManagement/all":
break
}
} else if (type === "annualReport") {
qc.where.product_code = qc.where.product_code && [system.SERVICECODE.ICPANNUALREPORT, system.SERVICECODE.EDIANNUALREPORT].includes(qc.where.product_code) ? qc.where.product_code : {
[this.db.Op.in]: [system.SERVICECODE.EDIANNUALREPORT, system.SERVICECODE.ICPANNUALREPORT]
}
switch (qobj.bizpath) {
case "/annualReport/wait":
qc.where.delivery_status = qc.where.delivery_status || {
[this.db.Op.in]: [system.ANNUALREPORT.TAKEEFFECT]
}
break
case "/annualReport/all":
qc.where.delivery_status = qc.where.delivery_status || {
[this.db.Op.in]: [system.ANNUALREPORT.TAKEEFFECT, system.ANNUALREPORT.SUCCESS]
}
break
}
switch (qobj.bizpath) {
case "/deliveryManagement/wait":
qc.where.delivery_status = qc.where.delivery_status || {
[this.db.Op.in]: [system.SERVERSESTATUS.RECEIVED, system.SERVERSESTATUS.COLLECTING,
system.SERVERSESTATUS.SUBMITING, system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.POSTING
]
qc.include = [
{
model: this.db.models.annualreport,
attributes: ['status', "year"],
where: {
year: {
[this.db.Op.or]: [
new Date().getFullYear(),
null
]
}
},
required: false
}
break
case "/deliveryManagement/all":
break
]
}
return qw;
}
......@@ -36,7 +74,7 @@ class DeliverDao extends Dao {
include: [
{
model: this.db.models.qualification,
attributes: ['id', 'certificateNumber', 'businessTypes', 'businessScope', 'serviceProject', 'startAt', 'endAt', 'file'],
// attributes: ['id', 'certificateNumber', 'businessTypes', 'businessScope', 'serviceProject', 'startAt', 'endAt', 'file'],
raw: false
}, {
model: this.db.models.material,
......@@ -47,5 +85,20 @@ class DeliverDao extends Dao {
});
return result;
}
async findAnnualReportInfo(pobj) {
const result = await this.model.findOne({
where: {
id: pobj.id
},
include: [
{
model: this.db.models.annualreport,
// attributes: ['id', 'certificateNumber', 'businessTypes', 'businessScope', 'serviceProject', 'startAt', 'endAt', 'file'],
}
],
raw: false
});
return result;
}
}
module.exports = DeliverDao;
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 年报信息表
*/
module.exports = (db, DataTypes) => {
return db.define("annualreport", {
year: {
allowNull: false,
type: DataTypes.INTEGER
},
status: {
allowNull: false,
type: DataTypes.STRING
},
file: {
allowNull: true,
type: DataTypes.JSON
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'annual_report',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -85,6 +85,10 @@ module.exports = (db, DataTypes) => {
sku_code: {
allowNull: true,
type: DataTypes.STRING
},
master_source_number: { //业务主订单号
allowNull: true,
type: DataTypes.STRING
}
}, {
paranoid: false,//假的删除
......
......@@ -16,7 +16,7 @@ module.exports = (db, DataTypes) => {
},
businessScope: {
allowNull: false,
type: DataTypes.STRING
type: DataTypes.TEXT
},
serviceProject: {
allowNull: false,
......
......@@ -2,6 +2,7 @@ const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const moment = require("moment");
const System = require("../../../system");
class DeliverService extends ServiceBase {
constructor() {
super("delivery", ServiceBase.getDaoName(DeliverService));
......@@ -9,6 +10,7 @@ class DeliverService extends ServiceBase {
this.materialDao = system.getObject("db.delivery.materialDao");
this.statuslogDao = system.getObject("db.bizchance.statuslogDao");
this.qualificationDao = system.getObject("db.delivery.qualificationDao");
this.annualreportDao = system.getObject("db.delivery.annualreportDao");
}
async temporarySave(pobj) {
......@@ -113,6 +115,10 @@ class DeliverService extends ServiceBase {
}
async addQualification(pobj) {
/**
* 1. 保存资质信息
* 2. 判断是否有年报服务,有的话改变年报状态
*/
const deliverData = await this.dao.findOne({
id: pobj.deliver_id
});
......@@ -122,11 +128,53 @@ class DeliverService extends ServiceBase {
if (deliverData.delivery_status !== system.SERVERSESTATUS.DISPOSEING) {
throw new Error("该交付单状态下不可提交");
}
let result = await this.qualificationDao.createOrUpdate(pobj);
return result;
let annualReportData;
let annualReportArry = [];
if (deliverData.master_source_number) {
annualReportData = await this.dao.findOne({
master_source_number: deliverData.master_source_number,
id: {
[this.db.Op.ne]: deliverData.id
}
});
if (annualReportData && annualReportData.delivery_status === System.ANNUALREPORT.RECEIVED) {
let year = annualReportData.delivery_info && annualReportData.delivery_info.year || 5
for (let i = new Date().getFullYear(); i < new Date().getFullYear() + year; i++) {
annualReportArry.push({
year: i,
status: System.ANNUALREPORT.WAITDECLARE,
deliver_id: annualReportData.id
});
}
}
}
return this.db.transaction(async (t) => {
await this.qualificationDao.createOrUpdate(pobj, t);
if (annualReportData && annualReportData.delivery_status === System.ANNUALREPORT.RECEIVED) {
await this.dao.updateByWhere({
delivery_status: System.ANNUALREPORT.TAKEEFFECT
}, {
id: annualReportData.id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.DELIVERY,
flow_id: annualReportData.id,
status_code: System.ANNUALREPORT.TAKEEFFECT
});
await this.annualreportDao.bulkCreate(annualReportArry, t);
}
return "success"
});
}
async closeDeliver(pobj) {
/**
* 1 关闭资质
* 2 查询是否有年报信息 关闭
*/
const deliverData = await this.dao.findOne({
id: pobj.id
});
......@@ -136,18 +184,42 @@ class DeliverService extends ServiceBase {
if (![system.SERVERSESTATUS.RECEIVED, system.SERVERSESTATUS.COLLECTING].includes(deliverData.delivery_status)) {
throw new Error("该交付单状态下不可提交");
}
await this.dao.updateByWhere({
delivery_status: system.SERVERSESTATUS.CLOSED,
close_reason: pobj.close_reason
}, {
id: pobj.id
});
this.statuslogDao.create({
flow_type: system.FLOWCODE.DELIVERY,
flow_id: pobj.id,
status_code: system.SERVERSESTATUS.CLOSED
let annualReportData;
if (deliverData.master_source_number) {
annualReportData = await this.dao.findOne({
master_source_number: deliverData.master_source_number,
id: {
[this.db.Op.ne]: deliverData.id
}
});
}
return this.db.transaction(async (t) => {
await this.dao.updateByWhere({
delivery_status: system.SERVERSESTATUS.CLOSED,
close_reason: pobj.close_reason
}, {
id: pobj.id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.DELIVERY,
flow_id: pobj.id,
status_code: system.SERVERSESTATUS.CLOSED
});
if (annualReportData && annualReportData.delivery_status === System.ANNUALREPORT.RECEIVED) {
await this.dao.updateByWhere({
delivery_status: system.SERVERSESTATUS.CLOSED,
}, {
id: annualReportData.id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.DELIVERY,
flow_id: annualReportData.id,
status_code: system.SERVERSESTATUS.CLOSED
});
}
return "success"
});
return "success"
}
async addMail(pobj) {
......@@ -191,5 +263,83 @@ class DeliverService extends ServiceBase {
});
}
async findAnnualReportInfo(pobj) {
let annualReportResult = await this.dao.findAnnualReportInfo(pobj);
if (!annualReportResult) {
throw new Error("交付单不可查看");
}
if (!annualReportResult.master_source_number) {
throw new Error("查不到主订单号");
}
let data = await this.dao.findOne({
master_source_number: annualReportResult.master_source_number,
id: {
[this.db.Op.ne]: annualReportResult.id
}
});
if (!data) {
throw new Error("查不到对应的交付单");
}
let result = await this.dao.findInfo({ ...pobj, id: data.id });
annualReportResult = JSON.parse(JSON.stringify(annualReportResult));
const { material: { proposerInfo: { businessLicense } }, qualification } = result;
annualReportResult.businessLicense = businessLicense;
annualReportResult.qualification = qualification;
return annualReportResult;
}
async declareReport(pobj) {
/**
* 1. 更新 年报信息
* 2. 判断是否 都已申报完毕
* 3. 改变 交付单状态
*/
const annualReportData = await this.annualreportDao.findOne({
id: pobj.id
});
if (!annualReportData) {
throw new Error("查不到此年报信息");
}
const deliverData = await this.dao.findOne({
id: annualReportData.deliver_id
});
let isChange = false;
if (deliverData && deliverData.delivery_status === system.ANNUALREPORT.TAKEEFFECT) {
const annualReports = await this.annualreportDao.findAll({
deliver_id: deliverData.id,
status: system.ANNUALREPORT.WAITDECLARE
});
const ids = annualReports.map(item => {
return item.id;
});
if (ids.length === 1 && ids.includes(annualReportData.id)) {
isChange = true
}
}
return this.db.transaction(async (t) => {
await this.annualreportDao.updateByWhere({
file: pobj.file,
status: system.ANNUALREPORT.DECLARESUCCESS
}, {
id: annualReportData.id
}, t);
if (isChange) {
await this.dao.updateByWhere({
delivery_status: system.ANNUALREPORT.SUCCESS
}, {
id: deliverData.id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.DELIVERY,
flow_id: deliverData.id,
status_code: System.ANNUALREPORT.SUCCESS
});
}
return 'success';
});
}
}
module.exports = DeliverService;
......@@ -218,6 +218,7 @@ class System {
ClassObj = require(objabspath);
} catch (e) {
// console.log(e)
let fname = objsettings[packageName + "base"];
ClassObj = require(fname);
}
......@@ -282,20 +283,23 @@ Date.prototype.Format = function (fmt) { //author: meizz
// 表分类
System.FLOWCODE = {
"BIZ": "BIZ",//商机表
"SCHEME": "SCHEME",//方案表
"DELIVERY": "DELIVERY"//服务单表
BIZ: "BIZ",//商机表
SCHEME: "SCHEME",//方案表
DELIVERY: "DELIVERY",//服务单表
ANNUALREPORT: "ANNUALREPORT"//年报表
}
// 服务名称
System.SERVICECODE = {
ICP: "ICP",
EDI: 'EDI'
EDI: 'EDI',
ICPANNUALREPORT: "ICPANNUALREPORT",
EDIANNUALREPORT: "EDIANNUALREPORT"
}
// 商机状态
System.BUSSTATUS = {
WAITINGSCHEME: "beforeSubmission",//待业务员响应
WAITINGSCHEME: "beforeSubmission",//待提交方案
WAITINGCONFIRM: "beforeConfirmation",//待用户确认
SUCCESS: "isFinished",//已确认
SUCCESS: "isFinished",//已成交
CLOSED: "isClosed"//需求关闭
}
......@@ -306,7 +310,7 @@ System.SCHEMESTATUS = {
REJECT: "isReject"//方案被拒绝
}
// 服务单状态
// 资质服务单状态
System.SERVERSESTATUS = {
RECEIVED: "received",//已接单
COLLECTING: "collecting",//收集材料中
......@@ -314,7 +318,16 @@ System.SERVERSESTATUS = {
DISPOSEING: "disposeing",//工信部处理中
POSTING: "posting",//证书已邮寄
SUCCESS: "success",//服务已完成
CLOSED: "closed"//已关闭
CLOSED: "closed",//已关闭
}
// 年报服务单状态
System.ANNUALREPORT = {
RECEIVED: "received",//已接单
WAITDECLARE: "waitdeclare",//待申报
DECLARESUCCESS: "declaresuccess",//申报成功
SUCCESS: "success",//服务已完成
CLOSED: "closed",//已关闭
TAKEEFFECT: "takeeffect"//生效
}
/*
......
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