lrf402788946 hace 4 años
padre
commit
9abc7bb564
Se han modificado 5 ficheros con 222 adiciones y 6 borrados
  1. 2 1
      README.md
  2. 0 2
      app/model/client.js
  3. 1 1
      app/model/treaty.js
  4. 1 1
      app/service/order/order.js
  5. 218 1
      app/service/util/util.js

+ 2 - 1
README.md

@@ -3,9 +3,10 @@
 此项目没有修改框架,所以model部分如果使用子目录,会引发错误,controller和service,router使用子目录不会产生bug
 
 添加模糊查询
+
 >符号及使用=>在parameters中的query`{key:value} => {key:%value%}`
 
->位置:`naf-framework-mongoose>lib>service>crud-service`中
+>位置:`naf-framework-mongoose>lib>service>crud-service`中 lodash引入部分添加 `get` 函数的引入
 
 `query`和`count`在`操作model前`加上下面的代码
 

+ 0 - 2
app/model/client.js

@@ -12,13 +12,11 @@ const Client = {
   },
   legal: {
     type: String,
-    required: true,
     maxLength: 200,
     field: { label: '联系人', filter: true, required: true },
   },
   mobile: {
     type: String,
-    required: true,
     maxLength: 200,
     field: { label: '联系电话', filter: true, required: true, options: { maxLength: 11 } },
   },

+ 1 - 1
app/model/treaty.js

@@ -37,7 +37,7 @@ const treaty = {
     maxLength: 200,
     field: { label: '结算周期' },
   },
-  expiry_date: { type: String, required: true, maxLength: 200, field: { label: '截止日期', type: 'date' } },
+  expiry_date: { type: String, maxLength: 200, field: { label: '截止日期', type: 'date' } },
   status: {
     type: String,
     maxLength: 200,

+ 1 - 1
app/service/order/order.js

@@ -272,7 +272,7 @@ class OrderService extends CrudService {
     const res = await this.model.update({ _id: ObjectId(_id) }, { principal });
     try {
       // 跨库查询该用户姓名
-      const user = await this.ctx.service.httpUtil.cget(
+      const user = await this.ctx.service.util.httpUtil.cget(
         `/user/${principal}`,
         'userAuth',
         { _tenant: 'zhwl' }

+ 218 - 1
app/service/util/util.js

@@ -1,6 +1,8 @@
 'use strict';
 const _ = require('lodash');
+const moment = require('moment');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
+const fs = require('fs');
 
 class UtilService extends CrudService {
   constructor(ctx) {
@@ -8,7 +10,21 @@ class UtilService extends CrudService {
     this.mq = this.ctx.mq;
   }
   async utilMethod(query, body) {
-    console.log(query, body);
+    const routes = await this.ctx.model.Route.find();
+    const dic = await this.ctx.model.Dictionary.find({ categroy: 'xzqh' });
+    console.log(routes.length);
+    for (const route of routes) {
+      const { s_p, s_c, e_p, e_c } = route;
+      const s_p_o = dic.find(f => f.value == s_p);
+      if (s_p_o) route.s_p = s_p_o._id;
+      const s_c_o = dic.find(f => f.value == s_c);
+      if (s_c_o) route.s_c = s_c_o._id;
+      const e_p_o = dic.find(f => f.value == e_p);
+      if (e_p_o) route.e_p = e_p_o._id;
+      const e_c_o = dic.find(f => f.value == e_c);
+      if (e_c_o) route.e_c = e_c_o._id;
+      route.save();
+    }
   }
   /**
    * 获取字段前置函数
@@ -119,5 +135,206 @@ class UtilService extends CrudService {
     }
     return filter;
   }
+
+  /**
+   * sql的车辆表转换到mongodb
+   */
+  async dataTurnCar() {
+    const file = await fs.readFileSync('C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_car.json');
+    let res = file.toString();
+    res = JSON.parse(res);
+    let arr = res.RECORDS;
+    arr = arr.map(i => {
+      const { car_no } = i;
+      const obj = {
+        car_no,
+        onwer: _.get(i, 'car_onwer'),
+        id_name: _.get(i, 'it'),
+        id_number: _.get(i, 'it_member'),
+        organ: _.get(i, 'ro'),
+        r_date: moment(_.get(i, 'r_time')).format('YYYY-MM-DD'),
+        c_type: _.get(i, 'car_type'),
+        c_doc_no: _.get(i, 'cc_no'),
+        c_weight: _.get(i, 'cc_weight'),
+        c_scrap_date: moment(_.get(i, 'cc_scrap_time')).format('YYYY-MM-DD'),
+        c_examine_date: moment(_.get(i, 'cc_examine_time')).format('YYYY-MM-DD'),
+        r_tran_no: _.get(i, 'rc_no'),
+        r_examine_date: moment(_.get(i, 'rc_examine_time')).format('YYYY-MM-DD'),
+        buy_car_taxes_no: _.get(i, 'bcc_no'),
+        f_company: _.get(i, 'fi_name'),
+        f_tel: _.get(i, 'fi_tel'),
+        f_no: _.get(i, 'fi_no'),
+        f_cost: _.get(i, 'fi_cost'),
+        f_start_date: moment(_.get(i, 'fi_start_time')).format('YYYY-MM-DD'),
+        f_end_date: moment(_.get(i, 'fi_end_time')).format('YYYY-MM-DD'),
+        f_solve: _.get(i, 'fi_dw'),
+        f_car_taxes: _.get(i, 'fi_vt'),
+        f_sign_date: moment(_.get(i, 'fi_sign_time')).format('YYYY-MM-DD'),
+        b_company: _.get(i, 'bi_name'),
+        b_tel: _.get(i, 'bi_tel'),
+        b_no: _.get(i, 'bi_no'),
+        b_start_date: _.get(i, 'bi_start_time') ? moment(_.get(i, 'bi_start_time')).format('YYYY-MM-DD') : undefined,
+        b_end_date: _.get(i, 'bi_start_time') ? moment(_.get(i, 'bi_end_time')).format('YYYY-MM-DD') : undefined,
+        b_solve: _.get(i, 'bi_dw'),
+        b_sign_date: _.get(i, 'bi_start_time') ? moment(_.get(i, 'bi_sign_time')).format('YYYY-MM-DD') : undefined,
+      };
+      return obj;
+    });
+    // await this.ctx.model.Car.insertMany(arr);
+  }
+
+  /**
+   * sql的客户/供应商表初步转换
+   */
+  async dataTurnClientFirst() {
+    const file = await fs.readFileSync(
+      'C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_client.json'
+    );
+    const users = await this.ctx.service.util.httpUtil.cget(
+      '/user',
+      'userAuth',
+      { _tenant: 'zhwl' }
+    );
+    let res = file.toString();
+    res = JSON.parse(res);
+    let arr = res.RECORDS;
+    arr = arr.map(i => {
+      const { name, address, taxes_no, type } = i;
+      const obj = {
+        name,
+        address,
+        taxes_no,
+        type: type === '0' ? '客户' : '供应商',
+        legal: _.get(i, 'legal_person'),
+        mobile: _.get(i, 'tel'),
+        account_bank: _.get(i, 'bank'),
+        account: _.get(i, 'card_account'),
+        id: _.get(i, 'id'),
+      };
+      if (_.get(i, 'login_id')) {
+        let lid = _.get(i, 'login_id');
+        if (lid === 'lsyw') lid = 'liushuang';
+        const user = users.find(f => f.login_id === lid);
+        if (user) {
+          obj.owner = user.id;
+          return obj;
+        }
+      }
+    });
+    await this.ctx.model.IClient.insertMany(_.compact(arr));
+  }
+  /**
+   * sql的合同表初步转换
+   */
+  async dataTurnTreatyFirst() {
+    const file = await fs.readFileSync('C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_client_pact.json');
+    const iclients = await this.ctx.model.IClient.find();
+    let res = file.toString();
+    res = JSON.parse(res);
+    let arr = res.RECORDS;
+    arr = arr.map(i => {
+      const { jf, yf, id, cus_id } = i;
+      const obj = {
+        number: _.get(i, 'pact_no'),
+        period: _.get(i, 'cycle'),
+        settle_up: _.get(i, 'js_type'),
+        settle_up_period: _.get(i, 'js_cycle'),
+        jf, yf, id,
+      };
+      if (cus_id) {
+        const client = iclients.find(f => f.id == cus_id);
+        if (client) {
+          obj.client = client._id;
+          obj.owner = client.owner;
+          return obj;
+        }
+      }
+    });
+    arr = _.compact(arr);
+    await this.ctx.model.ITreaty.insertMany(arr);
+  }
+
+  /**
+   * sql的项目表初步转换
+   */
+  async dataTurnItemFirst() {
+    const file = await fs.readFileSync('C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_client_pact_item.json');
+    let res = file.toString();
+    res = JSON.parse(res);
+    const iitems = res.RECORDS; // 对应itemconst arr = [];
+    const treatys = await this.ctx.model.ITreaty.find();
+    const arr = [];
+    for (const treaty of treatys) {
+      const { _id, id, owner } = treaty;
+      let arritems = iitems.filter(f => f.pact_id == id && f.cess && f.cess !== '');
+      arritems = arritems.map(i => {
+        const obj = {
+          id: _.get(i, 'id'),
+          treaty: _id,
+          name: _.get(i, 'item_name'),
+          taxes: _.get(i, 'cess'),
+          owner,
+        };
+        arr.push(obj);
+      });
+    }
+    await this.ctx.model.IItem.insertMany(arr);
+
+  }
+
+  /**
+   * sql的线路表初步转换
+   */
+  async dataTurnRouteFirst() {
+    const file = await fs.readFileSync('C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_dly_way.json');
+    let res = file.toString();
+    res = JSON.parse(res);
+    const iway = res.RECORDS; // 对应route
+    const iitems = await this.ctx.model.IItem.find();
+    const dic = await this.ctx.model.Dictionary.find({ categroy: 'xzqh' });
+    const arr = [];
+    for (const item of iitems) {
+      const { _id, id, owner } = item;
+      const ways = iway.filter(f => f.item_id == id);
+      for (const way of ways) {
+        const obj = { item: _id, name: way.name, owner, id: way.id, start: way.start_site, end: way.end_site };
+        const s_p_o = dic.find(f => f.label.includes(way.start_province) && f.pid === '5fcb00a6f6ed0b0b70df95cf');
+        const s_c_o = dic.find(f => f.label.includes(way.start_city) && f.pid !== '5fcb00a6f6ed0b0b70df95cf');
+        const e_p_o = dic.find(f => f.label.includes(way.end_province) && f.pid === '5fcb00a6f6ed0b0b70df95cf');
+        const e_c_o = dic.find(f => f.label.includes(way.end_city) && f.pid !== '5fcb00a6f6ed0b0b70df95cf');
+        if (s_p_o) obj.s_p = s_p_o.value;
+        if (s_c_o) obj.s_c = s_c_o.value;
+        if (e_p_o) obj.e_p = e_p_o.value;
+        if (e_c_o) obj.e_c = e_c_o.value;
+        if (obj.s_p && obj.s_c && obj.e_p && obj.e_c) arr.push(obj);
+      }
+
+    }
+    await this.ctx.model.IRoute.insertMany(arr);
+  }
+
+  /**
+   * sql的付费方式表转换(没有初步,直接成型,下面需要做的是将之前的初步转换成成品)
+   */
+  async dataTurnModeFirst() {
+    const file = await fs.readFileSync('C:\\Users\\liuruifeng\\Desktop\\暂存文件夹\\zhwl-turn\\zhwl_client_pact_item_way_type.json');
+    let res = file.toString();
+    res = JSON.parse(res);
+    const itype = res.RECORDS; // 对应rmode
+    const routes = await this.ctx.model.IRoute.find();
+    const arr = [];
+    for (const route of routes) {
+      const { _id, id, owner } = route;
+      const modes = itype.filter(f => f.dly_way_id == id);
+      for (const mode of modes) {
+        const obj = { name: mode.type_name, route: _id, price: mode.price, owner, status: mode.status };
+        if (mode.send_type) obj.send_type = mode.send_type == '1' ? '整车' : '零担';
+        if (mode.count_type) obj.computed_type = mode.count_type == '1' ? '按重量' : '按体积';
+        if (mode.is_lf) obj.is_lf = mode.is_lf == '0';
+        arr.push(obj);
+      }
+    }
+    await this.ctx.model.Mode.insertMany(arr);
+  }
 }
 module.exports = UtilService;