Commit 1c61f959 by 王昆

gsb

parent cf1c11a7
......@@ -7,12 +7,14 @@ const logCtl = system.getObject("web.common.oplogCtl");
const md5 = require("MD5");
const uuidv4 = require('uuid/v4');
const crypto = require('crypto');
const axios = require("axios");
var cacheBaseComp = null;
class TcompanytaxitemCtl extends CtlBase {
constructor() {
super("tax", CtlBase.getServiceName(TcompanytaxitemCtl));
this.redisClient = system.getObject("util.redisClient");
this.tcompanytaxocrSve = system.getObject("service.tax.tcompanytaxocrSve");
}
async taxPage(pobj, pobj2, req, res) {
......@@ -42,17 +44,40 @@ class TcompanytaxitemCtl extends CtlBase {
async taxUrl(pobj, pobj2, req, res) {
let id = pobj.id;
try {
let item = await this.service.findById(id);
if(!item) {
let target = await this.service.findById(id);
if (!target) {
return system.getResult(null, "税务信息不存在");
}
// TODO 请求张云飞
item.last_at = new Date();
item.save();
return system.getResultSuccess({
taxUrl: "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_7511582721898214202026205818214tfb_month_12.pdf"
// 整理请求数据
let itemList = await this.service.byImagepath(target.imagepath);
let data = [];
for (let item of itemList) {
data.push({
idName: item.idName,
idNo: item.idNo,
locations: JSON.parse(item.locations)
});
}
let params = {
target_id: target.idNo,
image_path: target.imagepath,
data: data,
}
// 请求ocr工具
let res = await axios({
method: 'post',
url: "http://43.247.184.92:9002/gsb/ocr/mosaic",
data: params
});
if(!res || !res.data || !res.data.mosaicurl) {
return system.getResult(null, "获取完税图片失败");
}
return system.getResultSuccess({taxUrl: res.data.mosaicurl});
} catch (error) {
console.log(error);
return system.getResult(-1, `服务异常`);
......
......@@ -5,6 +5,22 @@ class TCompanytaxitemDao extends Dao{
super(Dao.getModelName(TCompanytaxitemDao));
}
async byImagepath(imagepath) {
if(!imagepath) {
return [];
}
let sql = "SELECT * FROM t_company_tax_item WHERE imagepath = :imagepath";
return await this.customQuery(sql, {imagepath: imagepath});
}
async delByTaxOcrId(taxOcrId) {
if(!taxOcrId) {
return;
}
let sql = "DELETE FROM t_company_tax_item WHERE taxOcrId = :taxOcrId";
await this.customUpdate(sql, {taxOcrId: taxOcrId});
}
async countByCondition(condition) {
var sql = [];
sql.push("SELECT COUNT(1) AS num FROM `t_company_tax_item` WHERE 1 = 1");
......
......@@ -13,7 +13,8 @@ module.exports = (db, DataTypes) => {
incomeTax: DataTypes.STRING,
actualAmt: DataTypes.STRING,
grant_time: DataTypes.STRING,
param: DataTypes.STRING,
imagepath: DataTypes.STRING,
locations: DataTypes.STRING,
last_at: DataTypes.DATE,
tax_url: DataTypes.STRING,
},{
......
......@@ -73,5 +73,9 @@ class TcompanytaxitemService extends ServiceBase {
await ocr.save();
return system.getResultSuccess();
}
async byImagepath(imagepath) {
return this.dao.byImagepath(imagepath);
}
}
module.exports = TcompanytaxitemService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const axios = require("axios");
class TcompanytaxocrService extends ServiceBase {
constructor() {
super("tax", ServiceBase.getDaoName(TcompanytaxocrService));
this.tcompanytaxitemDao = system.getObject("db.tax.tcompanytaxitemDao");
this.ocr_url = "http://43.247.184.92:9002/gsb/ocr/ocrtable";
}
async sendImg(limit) {
let items = await this.dao.findUnSendIds(limit);
if(!items || items.length == 0) {
let ocrIds = await this.dao.findUnSendIds(limit);
if(!ocrIds || ocrIds.length == 0) {
return;
}
for(let item of items) {
let ocr = await this.dao.findById(item.id);
for(let ocrObj of ocrIds) {
let ocr = await this.dao.findById(ocrObj.id);
try {
// TODO 张云飞接口
ocr.isSend = true;
ocr.send_time = new Date();
await ocr.save();
let data = {
"taxOcrId": 1,
"tax_img": ocr.tax_img,
};
// 张云飞接口
let res = await axios({
method: 'post',
url: this.ocr_url,
data: data
});
if(!res.data || !res.data.data) {
break;
}
await this.saveOcrItems(ocr, res.data.data);
console.log(ocrObj.id);
} catch (error) {
console.log(error);
}
}
}
async saveOcrItems(ocr, itemList) {
if(!ocr) {
return;
}
let items = [];
for(let obj of itemList) {
if(!obj.idNo) {
continue;
}
items.push({
companyId: ocr.companyId,
taxId: ocr.taxId,
taxOcrId: ocr.id,
month: ocr.month,
month_date: ocr.month_date,
idName: obj.idName,
idNo: obj.idNo,
incomeTax: obj.incomeTax,
actualAmt: obj.actualAmt,
grant_time: obj.grant_time,
imagepath: obj.imagepath,
locations: JSON.stringify(obj.locations)
});
}
await this.tcompanytaxitemDao.delByTaxOcrId(ocr.id);
await this.tcompanytaxitemDao.bulkCreate(items);
ocr.isOCR = true;
ocr.ocr_time = new Date();
await ocr.save();
return system.getResultSuccess();
}
}
module.exports = TcompanytaxocrService;
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