Browse Source

添加期刊管理 目录管理 (未测试)

asd123a20 3 years ago
parent
commit
957b210de0

+ 29 - 0
service-journal/.autod.conf.js

@@ -0,0 +1,29 @@
+'use strict';
+
+module.exports = {
+  write: true,
+  prefix: '^',
+  plugin: 'autod-egg',
+  test: [
+    'test',
+    'benchmark',
+  ],
+  dep: [
+    'egg',
+    'egg-scripts',
+  ],
+  devdep: [
+    'egg-ci',
+    'egg-bin',
+    'egg-mock',
+    'autod',
+    'autod-egg',
+    'eslint',
+    'eslint-config-egg',
+  ],
+  exclude: [
+    './test/fixtures',
+    './dist',
+  ],
+};
+

+ 1 - 0
service-journal/.eslintignore

@@ -0,0 +1 @@
+coverage

+ 3 - 0
service-journal/.eslintrc

@@ -0,0 +1,3 @@
+{
+  "extends": "eslint-config-egg"
+}

+ 14 - 0
service-journal/.gitignore

@@ -0,0 +1,14 @@
+logs/
+npm-debug.log
+yarn-error.log
+node_modules/
+package-lock.json
+yarn.lock
+coverage/
+.idea/
+run/
+.DS_Store
+*.sw*
+*.un~
+typings/
+.nyc_output/

+ 12 - 0
service-journal/.travis.yml

@@ -0,0 +1,12 @@
+
+language: node_js
+node_js:
+  - '10'
+before_install:
+  - npm i npminstall -g
+install:
+  - npminstall
+script:
+  - npm run ci
+after_script:
+  - npminstall codecov && codecov

+ 33 - 0
service-journal/README.md

@@ -0,0 +1,33 @@
+# service-code
+
+
+
+## QuickStart
+
+<!-- add docs here for user -->
+
+see [egg docs][egg] for more detail.
+
+### Development
+
+```bash
+$ npm i
+$ npm run dev
+$ open http://localhost:7001/
+```
+
+### Deploy
+
+```bash
+$ npm start
+$ npm stop
+```
+
+### npm scripts
+
+- Use `npm run lint` to check code style.
+- Use `npm test` to run unit test.
+- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
+
+
+[egg]: https://eggjs.org

+ 27 - 0
service-journal/app/controller/catalogue.js

@@ -0,0 +1,27 @@
+'use strict';
+const Controller = require('egg').Controller;
+
+class CatalogueController extends Controller {
+  async create() {
+    const res = await this.ctx.service.catalogue.create(this.ctx.request.body);
+    this.ctx.body = res;
+  }
+  async update() {
+    const res = await this.ctx.service.catalogue.update(this.ctx.request.body);
+    this.ctx.body = res;
+  }
+  async delete() {
+    const res = await this.ctx.service.catalogue.delete(this.ctx.params);
+    this.ctx.body = res;
+  }
+  async query() {
+    const res = await this.ctx.service.catalogue.query(this.ctx.query);
+    this.ctx.body = res;
+  }
+  async fetch() {
+    const res = await this.ctx.service.catalogue.fetch(this.ctx.params);
+    this.ctx.body = res;
+  }
+}
+
+module.exports = CatalogueController;

+ 27 - 0
service-journal/app/controller/intact.js

@@ -0,0 +1,27 @@
+'use strict';
+const Controller = require('egg').Controller;
+
+class LntactController extends Controller {
+  async create() {
+    const res = await this.ctx.service.intact.create(this.ctx.request.body);
+    this.ctx.body = res;
+  }
+  async update() {
+    const res = await this.ctx.service.intact.update(this.ctx.request.body);
+    this.ctx.body = res;
+  }
+  async delete() {
+    const res = await this.ctx.service.intact.delete(this.ctx.params);
+    this.ctx.body = res;
+  }
+  async query() {
+    const res = await this.ctx.service.intact.query(this.ctx.query);
+    this.ctx.body = res;
+  }
+  async fetch() {
+    const res = await this.ctx.service.intact.fetch(this.ctx.params);
+    this.ctx.body = res;
+  }
+}
+
+module.exports = LntactController;

+ 23 - 0
service-journal/app/model/catalogue.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const SchemaDefine = {
+  // 内容
+  content: { type: String, required: true },
+  // 标题
+  name: { type: String, required: true },
+  // 描述
+  describe: { type: String, required: true },
+  // 商品状态
+  status: { type: String, required: true },
+  // 文件路经
+  url: { type: String, required: true },
+  // 发布时间
+  date: { type: Number, required: true },
+  // 期刊栏目
+  column: { type: String, required: true },
+};
+const schema = new Schema(SchemaDefine);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('catalogue', schema, 'catalogue');
+};

+ 25 - 0
service-journal/app/model/intact.js

@@ -0,0 +1,25 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const SchemaDefine = {
+  // 缩略图
+  thumbnail: { type: String, required: false },
+  // 标题
+  name: { type: String, required: true },
+  // 描述
+  describe: { type: String, required: false },
+  // 状态
+  status: { type: String, required: true },
+  // 文件路经
+  url: { type: String, required: false },
+  // 发布时间
+  date: { type: Number, required: true },
+  // 期刊栏目
+  column: { type: String, required: false },
+  // 期刊类型
+  type: { type: String, required: false },
+};
+const schema = new Schema(SchemaDefine);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('intact', schema, 'intact');
+};

+ 13 - 0
service-journal/app/router.js

@@ -0,0 +1,13 @@
+'use strict';
+
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const { router, controller } = app;
+  // 商城
+  router.post('/api/market/wares/create', controller.market.create);
+  router.post('/api/market/wares/update', controller.market.update);
+  router.delete('/api/market/wares/delete/:id', controller.market.delete);
+  router.get('/api/market/wares/query', controller.market.query);
+};

+ 73 - 0
service-journal/app/service/catalogue.js

@@ -0,0 +1,73 @@
+'use strict';
+
+const assert = require('assert');
+const Service = require('egg').Service;
+class CatalogueService extends Service {
+  constructor(ctx) {
+    super(ctx);
+    this.model = this.ctx.model.Catalogue;
+  }
+  async create({ content, name, describe, status, url, date, column }) {
+    assert(name, '名称不存在');
+    assert(date, '发布时间不存在');
+    assert(status, '状态不存在');
+    try {
+      const res = await this.model.create({ content, name, describe, status, url, date, column });
+      return { errcode: 0, errmsg: 'ok', data: res };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async update({ id, content, name, describe, status, url, date, column }) {
+    assert(id, 'id不存在');
+    try {
+      await this.model.updateOne({ _id: id }, { content, name, describe, status, url, date, column });
+      return { errcode: 0, errmsg: 'ok', data: '' };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async delete({ id }) {
+    assert(id, 'id不存在');
+    try {
+      await this.model.deleteOne({ _id: id });
+      return { errcode: 0, errmsg: 'ok', data: '' };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async query({ skip, limit, name, status, date, column }) {
+    const filter = {};
+    const arr = { name, status, date, column };
+    for (const e in arr) {
+      const data = `{ "${e}": { "$regex": "${arr[e]}" } }`;
+      if (arr[e]) {
+        filter.$or = [];
+        filter.$or.push(JSON.parse(data));
+      }
+    }
+    try {
+      const total = await this.model.find({ ...filter });
+      let res;
+      if (skip && limit) {
+        res = await this.model.find({ ...filter }, { content: false, url: false }).skip(Number(skip) * Number(limit)).limit(Number(limit));
+      } else {
+        res = await this.model.find({ ...filter }, { content: false, url: false });
+      }
+      return { errcode: 0, errmsg: 'ok', data: res, total: total.length };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async fetch({ id }) {
+    assert(id, 'id不存在');
+    try {
+      const res = await this.model.findOne({ _id: id });
+      return { errcode: 0, errmsg: 'ok', data: res };
+    } catch (error) {
+      throw error;
+    }
+  }
+}
+
+module.exports = CatalogueService;

+ 73 - 0
service-journal/app/service/intact.js

@@ -0,0 +1,73 @@
+'use strict';
+
+const assert = require('assert');
+const Service = require('egg').Service;
+class LntactService extends Service {
+  constructor(ctx) {
+    super(ctx);
+    this.model = this.ctx.model.lntact;
+  }
+  async create({ thumbnail, name, describe, status, url, date, column, type }) {
+    assert(name, '名称不存在');
+    assert(date, '发布时间不存在');
+    assert(status, '状态不存在');
+    try {
+      const res = await this.model.create({ thumbnail, name, describe, status, url, date, column, type });
+      return { errcode: 0, errmsg: 'ok', data: res };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async update({ id, thumbnail, name, describe, status, url, date, column, type }) {
+    assert(id, 'id不存在');
+    try {
+      await this.model.updateOne({ _id: id }, { thumbnail, name, describe, status, url, date, column, type });
+      return { errcode: 0, errmsg: 'ok', data: '' };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async delete({ id }) {
+    assert(id, 'id不存在');
+    try {
+      await this.model.deleteOne({ _id: id });
+      return { errcode: 0, errmsg: 'ok', data: '' };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async query({ skip, limit, name, status, url, date, column, type }) {
+    const filter = {};
+    const arr = { name, status, url, date, column, type };
+    for (const e in arr) {
+      const data = `{ "${e}": { "$regex": "${arr[e]}" } }`;
+      if (arr[e]) {
+        filter.$or = [];
+        filter.$or.push(JSON.parse(data));
+      }
+    }
+    try {
+      const total = await this.model.find({ ...filter });
+      let res;
+      if (skip && limit) {
+        res = await this.model.find({ ...filter }, { url: false }).skip(Number(skip) * Number(limit)).limit(Number(limit));
+      } else {
+        res = await this.model.find({ ...filter }, { url: false });
+      }
+      return { errcode: 0, errmsg: 'ok', data: res, total: total.length };
+    } catch (error) {
+      throw error;
+    }
+  }
+  async fetch({ id }) {
+    assert(id, 'id不存在');
+    try {
+      const res = await this.model.findOne({ _id: id });
+      return { errcode: 0, errmsg: 'ok', data: res };
+    } catch (error) {
+      throw error;
+    }
+  }
+}
+
+module.exports = LntactService;

+ 14 - 0
service-journal/appveyor.yml

@@ -0,0 +1,14 @@
+environment:
+  matrix:
+    - nodejs_version: '10'
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm i npminstall && node_modules\.bin\npminstall
+
+test_script:
+  - node --version
+  - npm --version
+  - npm run test
+
+build: off

+ 54 - 0
service-journal/config/config.default.js

@@ -0,0 +1,54 @@
+/* eslint valid-jsdoc: "off" */
+
+'use strict';
+
+/**
+ * @param {Egg.EggAppInfo} appInfo app info
+ */
+module.exports = appInfo => {
+  /**
+   * built-in config
+   * @type {Egg.EggAppConfig}
+   **/
+  const config = exports = {};
+
+  // use for cookie sign key, should change to your own and keep security
+  config.keys = appInfo.name + '_1635902541751_9477';
+
+  // add your middleware config here
+  config.middleware = [];
+  // add your user config here
+  const userConfig = {
+    // myAppName: 'egg',
+  };
+  // 安全配置
+  config.security = {
+    csrf: {
+      // ignoreJSON: true, // 默认为 false,当设置为 true 时,将会放过所有 content-type 为 `application/json` 的请求
+      enable: false,
+    },
+  };
+  config.cluster = {
+    listen: {
+      port: 9017,
+    },
+  };
+  // 数据库配置
+  config.mongoose = {
+    url: 'mongodb://127.0.0.1/Microservices',
+    options: {
+      // user: 'root',
+      // pass: 'cms@cc-lotus',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+    },
+  };
+  config.logger = {
+    level: 'DEBUG',
+  };
+  return {
+    ...config,
+    ...userConfig,
+  };
+};

+ 9 - 0
service-journal/config/plugin.js

@@ -0,0 +1,9 @@
+'use strict';
+
+/** @type Egg.EggPlugin */
+module.exports = {
+  mongoose: {
+    enable: true,
+    package: 'egg-mongoose',
+  },
+};

+ 17 - 0
service-journal/ecosystem.config.js

@@ -0,0 +1,17 @@
+'use strict';
+
+const app = 'service-code';
+module.exports = {
+  apps: [{
+    name: app, // 应用名称
+    script: './server.js', // 实际启动脚本
+    out: `./logs/${app}.log`,
+    error: `./logs/${app}.err`,
+    watch: [ // 监控变化的目录,一旦变化,自动重启
+      'app', 'config',
+    ],
+    env: {
+      NODE_ENV: process.env.NODE_ENV || 'production', // 环境参数,当前指定为生产环境
+    },
+  }],
+};

+ 5 - 0
service-journal/jsconfig.json

@@ -0,0 +1,5 @@
+{
+  "include": [
+    "**/*"
+  ]
+}

+ 47 - 0
service-journal/package.json

@@ -0,0 +1,47 @@
+{
+  "name": "service-journal",
+  "version": "1.0.0",
+  "description": "",
+  "private": true,
+  "egg": {
+    "declarations": true
+  },
+  "dependencies": {
+    "egg": "^2.15.1",
+    "egg-mongoose": "^3.3.1",
+    "egg-scripts": "^2.11.0"
+  },
+  "devDependencies": {
+    "autod": "^3.0.1",
+    "autod-egg": "^1.1.0",
+    "egg-bin": "^4.11.0",
+    "egg-ci": "^1.11.0",
+    "egg-mock": "^3.21.0",
+    "eslint": "^5.13.0",
+    "eslint-config-egg": "^7.1.0"
+  },
+  "engines": {
+    "node": ">=10.0.0"
+  },
+  "scripts": {
+    "start": "egg-scripts start --daemon --title=egg-server-service-journal",
+    "stop": "egg-scripts stop --title=egg-server-service-journal",
+    "dev": "egg-bin dev",
+    "debug": "egg-bin debug",
+    "test": "npm run lint -- --fix && npm run test-local",
+    "test-local": "egg-bin test",
+    "cov": "egg-bin cov",
+    "lint": "eslint .",
+    "ci": "npm run lint && npm run cov",
+    "autod": "autod"
+  },
+  "ci": {
+    "version": "10"
+  },
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": "",
+  "license": "MIT"
+}

+ 9 - 0
service-journal/server.js

@@ -0,0 +1,9 @@
+
+// eslint-disable-next-line strict
+const egg = require('egg');
+
+const workers = Number(process.argv[2] || require('os').cpus().length);
+egg.startCluster({
+  workers,
+  baseDir: __dirname,
+});

+ 20 - 0
service-journal/test/app/controller/home.test.js

@@ -0,0 +1,20 @@
+'use strict';
+
+const { app, assert } = require('egg-mock/bootstrap');
+
+describe('test/app/controller/home.test.js', () => {
+  it('should assert', () => {
+    const pkg = require('../../../package.json');
+    assert(app.config.keys.startsWith(pkg.name));
+
+    // const ctx = app.mockContext({});
+    // yield ctx.service.xx();
+  });
+
+  it('should GET /', () => {
+    return app.httpRequest()
+      .get('/')
+      .expect('hi, egg')
+      .expect(200);
+  });
+});