Commit 151a2c19 by 任晓松

add esData sync

parent ee1cdc49
......@@ -10,6 +10,7 @@ class TradeMarkApi{
this.baseUrl=settings.teleDomain();//测试
//this.baseUrl="http://www.telecredit.cn/";//生产
this.cacheManager=System.getObject("db.cacheManager");
this.trademarkSve=System.getObject("service.trademarkSve")
};
async checkParams(obj){
let key = await this.cacheManager["InitAppKeyCache"].getAppKeyVal(obj.appKey);
......@@ -91,6 +92,21 @@ class TradeMarkApi{
return rtn=System.getResult2(null,null);
}
};
/**
* 商标数据同步到es_add_data
* @returns {Promise<void>}
*/
async tradeMarkSync(){
let result = await this.trademarkSve.tradeMarkDataSync();
return result;
}
async bulkCreateEsData(obj){
let result = await this.trademarkSve.bulkCreateEsData(obj);
return result
}
}
module.exports=TradeMarkApi;
// var capi=new CompanyApi();
......
......@@ -38,6 +38,19 @@ class Dao {
var en = await this.model.destroy({ where: { id: { [this.db.Op.in]: ids } } });
return en;
}
//批量添加
async bulkCreate(u,t){
if (t != null && t != 'undefined') {
return this.model.bulkCreate(u, { transaction: t }).then(u => {
return u;
});
} else {
return this.model.bulkCreate(u).then(u => {``
return u;
});
}
}
async delete(qobj) {
var en = await this.model.findOne({ where: qobj });
if (en != null) {
......
const system=require("../../system");
const Dao=require("../dao.base");
class EsadddataDao extends Dao{
constructor(){
super(Dao.getModelName(EsadddataDao));
}
}
module.exports=EsadddataDao;
\ No newline at end of file
const system = require("../../system");
const settings = require("../../../config/settings");
module.exports = (db, DataTypes) => {
return db.define("esadddata", {
tmName: DataTypes.STRING,//商标名称
tmType: DataTypes.STRING,//商标类型
tmTypeName: DataTypes.STRING,//商标类型名称
tmSourceTypeName: DataTypes.STRING,//商标来源名称
picUrl: DataTypes.STRING,//商标图样url
tmStatusName: DataTypes.STRING,//商标状态名称-申请中
tmRegistNum:DataTypes.STRING,//注册号
nclOneCodes: DataTypes.STRING,//商标大类
nclSmallCodes: DataTypes.TEXT,//商标尼斯数据
typeName: DataTypes.STRING,//申请人类型名称(企业、个人)
applyName: DataTypes.STRING,//申请人名称
applyAddr: DataTypes.STRING,//申请人地址
principal: DataTypes.STRING,//代理机构名称
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'es_add_data',
validate: {},
indexes: []
});
}
\ No newline at end of file
const system = require("../../system");
const ServiceBase = require("../sve.base");
const settings = require("../../../config/settings");
const {Op} = require('sequelize');
const uiconfig = system.getUiConfig2(settings.wxconfig.appId);
const logCtl = system.getObject("web.oplogCtl");
const uuidv4 = require('uuid/v4');
......@@ -16,6 +17,7 @@ class TrademarkService extends ServiceBase {
this.calcDao = system.getObject("db.calculatepriceDao");
this.tmapplierinfoDao = system.getObject("db.tmapplierinfoDao");
this.trademarkDao = system.getObject("db.trademarkDao");
this.esadddataDao = system.getObject("db.esadddataDao");
this.tmcustomerinfoDao = system.getObject("db.tmcustomerinfoDao");
this.tmflowDao = system.getObject("db.tmflowDao");
this.connectionbh = system.getObject("db.connection").getConhb();
......@@ -1719,6 +1721,57 @@ class TrademarkService extends ServiceBase {
}
return []
}
/**
* es同步数据
* @returns {Promise<*>}
*/
async tradeMarkDataSync(){
let date = new Date();
let sql = `SELECT a.id,a.tmName,a.tmRegistNum ,a.tmSourceTypeName,a.tmType,a.tmTypeName,a.picUrl,
CASE a.tmStatusName
WHEN '初步审定公告' THEN '已初审'
WHEN '已下发纸质注册证' THEN '已注册'
WHEN '已下发注册证' THEN '已注册'
ELSE '申请中'
END AS tmStatusName
,a.nclOneCodes,a.nclSmallCodes,b.typeName,b.applyName,b.applyAddr,
IFNULL( a.principal,'汉唐信通(北京)咨询股份有限公司') AS principal
,NOW() AS created_at FROM h_trade_mark AS a LEFT JOIN h_tmapplier_info AS b
ON a.orderNum=b.orderNum
WHERE a.tmRegistNum!='' AND a.tmRegistNum IS NOT NULL AND a.deleted_at IS NULL AND a.isEsData=0 LIMIT 200;`;
let queryResult = await this.customQuery(sql);
let ids = [];
let data = queryResult.map(item=>{
ids.push(item.id);
item.created_at = date;
delete item.id;
return item;
})
let self = this;
return self.db.transaction(async function (t) {
await self.esadddataDao.bulkCreate(data,t);
let updateSql = `UPDATE h_trade_mark SET isEsData = 1 WHERE id in (:ids)`;
let where = {
ids
}
await self.dao.customUpdate(updateSql,where,t);
return system.getResultFail(0,"success",ids);
})
}
/**
* 批量插入数据
* @param obj
* @returns {Promise<void>}
*/
async bulkCreateEsData(obj){
let self = this;
return self.db.transaction(async function (t) {
await self.esadddataDao.bulkCreate(obj,t);
return system.getResultFail(0,"success",null);
})
}
}
module.exports = TrademarkService;
// var task = new TrademarkService();
......
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