Commit 3310631d by wkliang

init; 基础查询接口;

parent 4a7bf385
var APIBase = require("../../api.base");
var system = require("../../../system");
const os = require("os")
class ProductAPI extends APIBase {
constructor() {
super();
this.productSve = system.getObject("service.product.productSve")
}
async etag (pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空")
}
let result
switch (pobj.actionType) {
case 'getPage':
result = await this.productSve.getPage(pobj.actionBody.page, pobj.actionBody.offset, pobj.actionBody.type)
return result
case 'createOrUpdate':
break
case 'getAll':
result = await this.productSve.getAllDic(pobj.actionBody.type)
return result
case 'getByIds':
result = await this.productSve.getByIds(pobj.actionBody.ids)
break
case 'getItems':
break
default:
break
}
}
exam () {
return `<pre><pre/>`;
}
classDesc () {
return {
groupName: "product",
groupDesc: "产品引擎",
name: "ProductApi",
desc: "产品相关接口",
exam: "",
};
}
methodDescs () {
return [
{
methodDesc: `<pre><pre/>`,
methodName: "product",
paramdescs: [
{
paramDesc: "请求的行为,传递如:sjb",
paramName: "action_process",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型,详情见方法中的描述",
paramName: "action_type",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型的参数,action_body必须传递的参数有,times_tamp(时间戳,类型int)、sign(签名,类型string),其余的为业务需要的参数",
paramName: "action_body",
paramType: "json",
defaultValue: null,
}
],
rtnTypeDesc: `<pre><pre/>`,
rtnType: `<pre><pre/>`
}
];
}
}
module.exports = ProductAPI;
\ No newline at end of file
const Dao = require("../../dao.base");
class productDao extends Dao {
constructor() {
super(Dao.getModelName(productDao));
}
async getPage (page = 1, offset = 10, type = [0, 1]) {
return await this.model.findAndCountAll({
where: { product_type: { [this.db.Op.in]: type } },
limit: offset,
offset: (page - 1) * offset
})
}
async getAllDic (type = [0, 1]) {
// TODO: 筛选字段
return await this.model.findAll({
where: { product_type: { [this.db.Op.in]: type } }
})
}
async getByIds (ids) {
return await this.model.getAll({
where: { id: { [this.db.Op.in]: ids } }
})
}
}
module.exports = productDao;
\ No newline at end of file
const Dao = require("../../dao.base");
class productItemDao extends Dao {
constructor() {
super(Dao.getModelName(productItemDao));
}
async getById (id) {
return await this.model.findOne(id)
}
async deleteById (id) {
return await this.model.destroy({
where: {
id: id
}
})
}
async deleteByParentId (id) {
return await this.model.destroy({
where: {
parent_id: id
}
})
}
}
module.exports = productItemDao;
\ No newline at end of file
module.exports = (db, DataTypes) => {
return db.define("product", {
source_id: DataTypes.BIGINT, // 产品来源 id
product_name: DataTypes.STRING, // 产品名称 50字
product_type: DataTypes.TINYINT, // 产品类型 1: 单产品, 2: 组合产品
product_desc: DataTypes.STRING, // 产品描述
price: DataTypes.BIGINT, // 价格
cost: DataTypes.BIGINT, // 成本
}, {
paranoid: true,
underscored: true,
timestamps: true,
tableName: 'e_product',
version: true,
freezeTableName: true
}
)
}
\ No newline at end of file
module.exports = (db, DataTypes) => {
return db.define("productItem", {
parent_id: DataTypes.BIGINT, // 父产品 id
product_id: DataTypes.BIGINT, // 单产品 id
}, {
paranoid: false,
underscored: true,
timestamps: true,
tableName: 'e_product_item',
version: true,
freezeTableName: true
}
)
}
\ No newline at end of file
module.exports = (db, DataTypes) => {
return db.define("source", {
source_name: DataTypes.STRING, // 产品来源名称
}, {
paranoid: true,
underscored: true,
timestamps: true,
tableName: 'e_soutce',
version: true,
freezeTableName: true
}
)
}
\ No newline at end of file
const ServiceBase = require("../../sve.base");
class ProductService extends ServiceBase {
constructor() {
super("product", ServiceBase.getDaoName(ProductService));
}
async getPage (page, offset, type) {
return await this.dao.getPage(page, offset, type)
}
async getAllDic (type) {
return await this.dao.getAllDic(type)
}
async getByIds (ids) {
return await this.dao.getByIds(ids)
}
async getItems (id) {
// TODO: relation
}
async createOrUpdate (params) {
// TODO:
}
}
module.exports = ProductService;
\ No newline at end of file
......@@ -2,11 +2,12 @@
var system = require("../../base/system");
var fs = require('fs');
var marked = require("marked");
const os = require("os")
module.exports = function (app) {
app.get('/doc', function (req, res) {
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
var path = os.type == 'Windows_NT' ? process.cwd() + "/engine-product/app/front/entry/public/apidoc/README.md" : process.cwd() + "/app/front/entry/public/apidoc/README.md";
console.log(process.cwd(), '----------------');
fs.readFile(path, function(err, data){
if(err){
......@@ -21,8 +22,7 @@ module.exports = function (app) {
});
app.get('/doc/:forder', function (req, res) {
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
var path = os.type == 'Windows_NT' ? process.cwd() + "/engine-product/app/front/entry/public/apidoc/README.md" : process.cwd() + "/app/front/entry/public/apidoc/README.md";
fs.readFile(path, function(err, data){
if(err){
console.log(err);
......@@ -38,7 +38,8 @@ module.exports = function (app) {
app.get('/doc/:forder/:fileName', function (req, res) {
var forder = req.params["forder"];
var fileName = req.params["fileName"] || "README.md";
var path = process.cwd() + "/app/front/entry/public/apidoc";
var path = os.type == 'Windows_NT' ? process.cwd() + "/engine-product/app/front/entry/public/apidoc" : process.cwd() + "/app/front/entry/public/apidoc";
if(forder) {
path = path + "/" + forder + "/" + fileName;
} else {
......
......@@ -21,7 +21,7 @@ var settings = {
cacheprefix: "sjb",
usertimeout: 3600, //单位秒
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 3300,
port: process.env.NODE_PORT || 3301,
defaultPassWord: "987456",
paasUrl: function () {
if (this.env == "dev") {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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