Commit 56e72547 by 孙亚楠

dd

parent 6f5182bb
......@@ -60,6 +60,11 @@ class OorderprocessDao extends Dao {
}
return result;
}
async findAllByOrderId(order_id){
let sql = `select * from o_order_process where order_id = :order_id`;
return await this.customQuery(sql,{order_id:order_id});
}
}
module.exports = OorderprocessDao;
......@@ -44,5 +44,10 @@ class OprocessDao extends Dao {
}
return result;
}
async findAllByPorductId(productIds){
let sql =`select id,product_id,status from o_process where product_id in (:productIds)`;
return await this.customQuery(sql,{productIds:productIds});
}
}
module.exports = OprocessDao;
\ No newline at end of file
......@@ -5,7 +5,8 @@
module.exports = function (db, DataTypes) {
return db.define('oprocess', {
name: {type: DataTypes.STRING, field: 'name', allowNull: false, defaultValue:'', comment:'流程名称' },
status: { type: DataTypes.STRING, field: 'status', allowNull: false,defaultValue:'', comment:'流程状态'},
status: { type: DataTypes.STRING, field: 'status', allowNull: false,defaultValue:'', comment:'流程状态'},
product_id: { type: DataTypes.STRING, field: 'product_id', allowNull: false,defaultValue:'', comment:'所属产品ID'},
created_at: { type: DataTypes.DATE, field: 'created_at', allowNull: false, defaultValue: DataTypes.NOW },
updated_at: { type: DataTypes.DATE, field: 'updated_at', allowNull: false, defaultValue: DataTypes.NOW },
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }
......
......@@ -220,6 +220,84 @@ class OorderService extends ServiceBase {
return orderProcessList;
}
/**
* 构建产品流程对象
* @param productPid
* @param chooseProductIds
* @returns {Promise<void>}
*/
async buildOrderProcess1(_order,productPid, chooseProductIds) {
try {
// 查询所有产品子项
let productList = await this.oproductDao.findListByPid(productPid);
// 根据所选产品id, 查询产品流程
let productIds = []; //结果 10010100 10010200 10010500 10010600
for (let product of productList) {
// 过滤未选择产品
if (product.is_choose && chooseProductIds && chooseProductIds.indexOf(product.id) == -1) {
continue;
}
productIds.push(product.id);
}
if (productIds.length == 0) {
return null;
}
//查出订单的所有流程
let oorderProcessInfo = await this.oorderprocessDao.findAllByOrderId(_order.id);
//筛选出每个状态对应的 产品ID 格式 1010 -> 10100100
let filterMap = {};
//查询每个状态对应的产品id
let oproductInfo =await this.oprocessDao.findAllByPorductId(productIds);
for(let item of oproductInfo){
filterMap[item.status] = item.product_id;
}
//遍历 oorderProcessInfo 数组 为每一个值都添加 delete_mark product_id change_func三个属性
for(let item of oorderProcessInfo){
item.productId=filterMap[item.status];
item.delete_mark=false;
item.change_func_flag=false;
item.change_func='';
}
for(let i=0;i<oorderProcessInfo.length;i++){
if(oorderProcessInfo[i+1]){
oorderProcessInfo[i+1].change_func=oorderProcessInfo[i].func;
}
if(!productIds.includes(oorderProcessInfo[i].productId)){
oorderProcessInfo[i].delete_mark=true;
if(oorderProcessInfo[i+1]){
oorderProcessInfo[i+1].change_func_flag=true;
}
}
}
let new_oorderProcessInfo = oorderProcessInfo.filter(element=>{
if(!element.delete_mark){
return element;
}
});
for(let j=0;j<new_oorderProcessInfo.length;j++){
if(new_oorderProcessInfo[j].change_func_flag){
let current= new_oorderProcessInfo[j];
let pre= new_oorderProcessInfo[j-1];
pre.func=current.change_func;
let preNextStatus = JSON.parse(pre.next_status)[0];
preNextStatus.next_status=current.status;
preNextStatus.next_name=current.name;
pre.next_status=JSON.stringify(preNextStatus);
}
}
return new_oorderProcessInfo;
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误`);
}
}
/**
* 订单管理列表
* @param {*} params
......
......@@ -52,7 +52,7 @@ class OorderstatusService extends ServiceBase {
chooseItems.push(productId);
}
}
let orderProcessList = await this.oorderSve.buildOrderProcess(_order.product_id, chooseItems);
let orderProcessList = await this.oorderSve.buildOrderProcess1(_order,_order.product_id, chooseItems);
if (!orderProcessList || orderProcessList.length == 0) {
return system.getResult(null, "产品流程未配置");
}
......
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