Commit 23ceb212 by 蒋勇

d

parent cfe3f473
......@@ -22,7 +22,7 @@ class CtlBase {
return system.getResult(apps);
}
async refQuery(pobj, qobj, req) {
return this.dao.refQuery(pobj);
return this.service.refQuery(pobj);
}
async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null;
......
......@@ -8,8 +8,6 @@ var cacheBaseComp = null;
class RoleCtl extends CtlBase {
constructor() {
super("auth",CtlBase.getServiceName(RoleCtl));
//this.loginS=system.getObject("service.userSve");
this.roleS=system.getObject("service.auth.roleSve");
this.redisClient=system.getObject("util.redisClient");
}
async initNewInstance(pobj,queryobj, req) {
......
......@@ -5,6 +5,7 @@ class Dao {
var db = system.getObject("db.common.connection").getCon();
this.db = db;
console.log("........set dao model..........");
console.log(this.modelName)
this.model = db.models[this.modelName];
console.log(this.modelName);
}
......
......@@ -6,7 +6,7 @@ class UserService extends ServiceBase {
constructor() {
super("auth", ServiceBase.getDaoName(UserService));
this.companyDao = system.getObject("db.common.companyDao");
this.roleDao = system.getObject("db.common.roleDao");
this.roleDao = system.getObject("db.auth.roleDao");
}
//平台注册,默认角色,不具备平台级别的管理或运营功能
......
const system=require("../../../system");
const settings=require("../../../../config/settings");
const ServiceBase=require("../../sve.base")
var WXPay = require('wx-pay');
const uuidv4 = require('uuid/v4');
class ApiTradeService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(ApiTradeService));
}
async create(tradeObj){
var self=this;
return this.db.transaction(async function (t){
//获取缓存二个值,一个是赠送次数,一个是调用价格
var pconfig=await self.cacheManager["PConfigCache"].cachePConfig();
var apiInitGift = pconfig.find(item => {
return item.configType === "apiInitGift";
});
var apiCallPrice = pconfig.find(item => {
return item.configType === "apiCallPrice";
});
var app=await self.cacheManager["AppCache"].cacheApp(tradeObj.appkey,null,1);
tradeObj.app_id=app.id;
var callCache=await self.cacheManager["ApiCallCountCache"].getApiCallCount(tradeObj.appkey,tradeObj.op);
var callAccuCache=await self.cacheManager["ApiAccuCache"].getApiCallAccu(tradeObj.appkey);
var calledCount=Number(callCache.callcount);
var balance=Number(callCache.amount);
if(calledCount>Number(apiInitGift.configValue)){//调用次数大于免费次数
tradeObj.amount=Number(apiCallPrice.configValue);
}else{
tradeObj.amount=0;
}
//解决日志大于4000写入的问题
if(tradeObj.params.length>3980){
tradeObj.params=tradeObj.params.substring(0,3980);
}
var apitrade=await self.dao.model.create(tradeObj,{transaction:t});
//按照调用方法缓存
await self.cacheManager["ApiCallCountCache"].addCallCount(tradeObj.appkey,tradeObj.op,1);
await self.cacheManager["ApiCallCountCache"].addCallBalance(tradeObj.appkey,tradeObj.op,tradeObj.amount);
//累计缓存调用次数和金额
await self.cacheManager["ApiAccuCache"].addCallCount(tradeObj.appkey,1);
await self.cacheManager["ApiAccuCache"].addCallBalance(tradeObj.appkey,tradeObj.amount);
// await self.cacheManager["ApiCircuitBreakers"].addCallCount(-1);
return apitrade;
});
}
async beforesel(tradeObj){
var self=this;
var callCaches=await self.cacheManager["ApiCircuitBreakers"].getApiCall();
var calledCounts=Number(callCaches.callcount);
if( calledCounts>100 ){
// return {status:-1,msg:"服务器繁忙,请稍候再试",data:null};
}
else {
// await self.cacheManager["ApiCircuitBreakers"].addCallCount(1);
}
var callCache=await self.cacheManager["ApiCircuitBreakerCache"].getApiCall(tradeObj.appkey);
var calledCount=Number(callCache.callcount);
if( calledCount>1000 ){
return {status:-1,msg:"调用次数太多,请稍候再试",data:null};
}
else {
var result=await self.cacheManager["ApiCircuitBreakerCache"].addCallCount(tradeObj.appkey,1);
}
return {status:1,msg:"OK"};
}
}
module.exports=ApiTradeService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class AppdetailService{
constructor(){
this.cacheManager=system.getObject("db.cacheManager");
}
//app调用次数
async findAndCountAlldetail(obj){
var details=[];
var apicallAccu= await this.cacheManager["ApiAccuCache"].getApiCallAccu(obj);
var result={rows:[],count:0};
var keys=await this.cacheManager["MagCache"].keys("api_call_" + obj + "*");
var detail=null;
for(let j=0;j<keys.length;j++){
var d=keys[j];
var pathdetail=d.substr(d.lastIndexOf("_")+1,d.length);
var apicalldetailAccu= await this.cacheManager["ApiCallCountCache"].getApiCallCount(obj,pathdetail);
var detail={"detailPath":d,"detailCount":apicalldetailAccu.callcount,"detailAmount":apicalldetailAccu.amount};
details.push(detail);
}
result.rows=details;
result.count=details.length;
return result;
}
async delCache(obj){
return this.cacheManager["MagCache"].del(obj.key);
}
async clearAllCache(obj){
return this.cacheManager["MagCache"].clearAll();
}
}
module.exports=AppdetailService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
class OplogService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(OplogService));
//this.appDao=system.getObject("db.appDao");
this.opLogUrl = settings.apiconfig.opLogUrl();
this.opLogEsIsAdd = settings.apiconfig.opLogEsIsAdd();
}
async create(qobj) {
if (!qobj || !qobj.op || qobj.op.indexOf("metaCtl/getUiConfig") >= 0 ||
qobj.op.indexOf("userCtl/checkLogin") >= 0 ||
qobj.op.indexOf("oplogCtl") >= 0 ||
qobj.op.indexOf("getDicConfig") >= 0 ||
qobj.op.indexOf("getRouteConfig") >= 0 ||
qobj.op.indexOf("getRsConfig") >= 0) {
return null;
}
var rc = system.getObject("util.execClient");
var rtn = null;
try {
// var myDate = new Date();
// var tmpTitle=myDate.toLocaleString()+":"+qobj.optitle;
qobj.optitle = (new Date()).Format("yyyy-MM-dd hh:mm:ss") + ":" + qobj.optitle;
if (this.opLogEsIsAdd == 1) {
qobj.content = qobj.content.replace("field list", "字段列表")
qobj.created_at = (new Date()).getTime();
//往Es中写入日志
var addEsData = JSON.stringify(qobj);
rc.execPost(qobj, this.opLogUrl);
} else {
//解决日志大于4000写入的问题
if (qobj.content.length > 3980) {
qobj.content = qobj.content.substring(0, 3980);
}
this.dao.create(qobj);
}
} catch (e) {
console.log("addLog------>>>>>>error-----------------------*****************");
console.log(e);
//解决日志大于4000写入的问题
if (qobj.content.length > 3980) {
qobj.content = qobj.content.substring(0, 3980);
}
this.dao.create(qobj);
}
}
}
module.exports = OplogService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class PConfigService extends ServiceBase{
constructor(){
super("common",ServiceBase.getDaoName(PConfigService));
//this.appDao=system.getObject("db.appDao");
}
async findOrSetPrice(num,appkey){
return this.cacheManager["PriceConfigCache"].cacheGlobalVal(num,appkey);
}
async create(pobj){
await this.cacheManager["PConfigCache"].invalidate(pobj.appkey);
await this.cacheManager["InitGiftCache"].invalidate(pobj.appkey);
return this.dao.create(pobj);
}
async update(pobj,tm=null){
await this.cacheManager["PConfigCache"].invalidate(pobj.appkey);
await this.cacheManager["InitGiftCache"].invalidate(pobj.appkey);
return this.dao.update(pobj,tm);
}
async updateByWhere(setObj,whereObj,t){
await this.cacheManager["PConfigCache"].invalidate(setObj.appkey);
await this.cacheManager["InitGiftCache"].invalidate(setObj.appkey);
return this.dao.updateByWhere(setObj,whereObj,t);
}
//获取配置的发票税率
async getInvoiceTaxRate(){
var tmpInvoiceTaxRate=7;
var pconfig=await this.cacheManager["PConfigCache"].cachePConfig();
var pconfigResult= pconfig.find(item => {
return item.configType === "invoiceTaxRate";
});
if(pconfigResult!=null && pconfigResult.configValue!=null && pconfigResult.configValue!=""){
tmpInvoiceTaxRate=Number(pconfigResult.configValue);
}
return tmpInvoiceTaxRate;
}
//获取配置的信息
async getConfigValue(configName){
var configValue=0;
var pconfig=await this.cacheManager["PConfigCache"].cachePConfig();
var pconfigResult= pconfig.find(item => {
return item.configType === configName;
});
if(pconfigResult!=null && pconfigResult.configValue!=null && pconfigResult.configValue!=""){
configValue=Number(pconfigResult.configValue);
}
return configValue;
}
//获取配置的推荐人分润比例
async getReferrerProfitRatio(){
var tmpInvoiceTaxRate=10;
var pconfig=await this.cacheManager["PConfigCache"].cachePConfig();
var pconfigResult= pconfig.find(item => {
return item.configType === "referrerProfitRatio";
});
if(pconfigResult!=null && pconfigResult.configValue!=null && pconfigResult.configValue!=""){
tmpInvoiceTaxRate=Number(pconfigResult.configValue);
}
return tmpInvoiceTaxRate;
}
//商机分配渠道配置,格式:wssyh5,yzc等
async getBussinessAllotChannelConfig(){
var bussinessAllotChannel="wssyh5";
var pconfig=await this.cacheManager["PConfigCache"].cachePConfig();
var pconfigResult= pconfig.find(item => {
return item.configType === "bussinessAllotChannelConfig";
});
if(pconfigResult!=null && pconfigResult.configValue!=null && pconfigResult.configValue!=""){
bussinessAllotChannel=pconfigResult.configValue;
}
return bussinessAllotChannel;
}
}
module.exports=PConfigService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
const fs=require("fs");
var excel = require('exceljs');
const uuidv4 = require('uuid/v4');
var path= require('path');
class TaskService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(TaskService));
//this.appDao=system.getObject("db.appDao");
this.taskManager=system.getObject("db.taskManager");
this.emailClient=system.getObject("util.mailClient");
this.personTaxDao=system.getObject("db.individualincometaxDao");
this.ossClient=system.getObject("util.ossClient");
}
//写文件并上传到阿里云,返回上传的路径
async writexls(wb,sharecode){
var that=this;
var uuid=uuidv4();
var u=uuid.replace(/\-/g,"");
var fname="zc_"+u+".xlsx";
var filepath="/tmp/"+fname;
var promise=new Promise((resv,rej)=>{
wb.xlsx.writeFile(filepath).then(async function(d) {
var rtn=await that.ossClient.upfile(fname,filepath);
fs.unlink(filepath,function(err){});
return resv(rtn);
}).catch(function(e){
return rej(e);
});
});
return promise;
}
//读取模板文件
async readxls(){
var promise=new Promise((resv,rej)=>{
var workbook = new excel.Workbook();
workbook.properties.date1904 = true;
var bpth=path.normalize(path.join(__dirname, '../'));
workbook.xlsx.readFile(bpth+"/tmpl/tmpl.xlsx")
.then(function() {
return resv(workbook);
}).catch(function(e){
return rej(e);
});
});
return promise;
}
async buildworkbook(taxCalcList){
var workbook = await this.readxls();
var sheet = workbook.getWorksheet(1);
sheet.columns = [
{ header: '年度', key: 'statisticalYear', width: 10 },
{ header: '月份', key: 'statisticalMonth', width: 10 },
{ header: '员工姓名', key: 'employeeName', width: 10 },
{ header: '本月税前薪资', key: 'preTaxSalary', width: 18 },
{ header: '累计税前薪资', key: 'accupreTaxSalary', width: 18 },
// { header: '五险一金比例', key: 'insuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '本月五险一金', key: 'insuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '累计五险一金', key: 'accuinsuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '子女教育', key: 'childrenEducation', width: 10 },
{ header: '继续教育', key: 'continuingEducation', width: 10 },
{ header: '房贷利息', key: 'interestExpense', width: 10 },
{ header: '住房租金', key: 'housingRent', width: 10 },
{ header: '赡养老人', key: 'supportElderly', width: 10 },
{ header: '大病医疗', key: 'illnessMedicalTreatment', width: 10 },
{ header: '专项扣除合计', key: 'specialDeduction', width: 10 },
{ header: '累计已扣专项', key: 'accuSpecialDeduction', width: 18, outlineLevel: 1 },
{ header: '累计已纳个税', key: 'accuPersonalIncomeTax', width: 18 },
{ header: '累计免征额', key: 'accuExemptionAmount', width: 10 },
{ header: '适用税率', key: 'taxRate', width: 10 },
{ header: '速算扣除', key: 'deductionNumber', width: 10 },
{ header: '本月应纳个税', key: 'personalIncomeTax', width: 18 },
{ header: '本月税后薪资', key: 'postTaxSalary', width: 18, outlineLevel: 1 }
// (累计税前薪资-累计五险一金-累计免征额-累计已扣专项)*税率-速算扣除-累计已纳个税=本月应纳个税
];
taxCalcList.forEach(r=>{
sheet.addRow(r);
});
return workbook;
}
async makerpt(qobj){
var self=this;
return this.db.transaction(async t=>{
const sharecode=qobj.sharecode;
const email=qobj.email;
//按照sharecode获取单位某次个税计算
var taxCalcList=await this.personTaxDao.model.findAll({where:{shareOnlyCode:sharecode},transaction:t});
var sheetNameSufix="个税汇总表";
if(taxCalcList && taxCalcList.length>0){
var year=taxCalcList[0].statisticalYear;
var month=taxCalcList[0].statisticalMonth;
sheetNameSufix=year+month+sheetNameSufix;
}
var wb=await this.buildworkbook(taxCalcList);
//生成excel
var result=await this.writexls(wb,sharecode);
//异步不等待发送邮件给
var html='<a href="'+result.url+'">'+sheetNameSufix+'</a>'
self.emailClient.sendMsg(email,sheetNameSufix,null,html,null,null,[]);
//发送手机短信
//写到按咋回哦sharecode,修改下载的url
return result.url;
});
}
async create(qobj){
var self=this;
return this.db.transaction(async t=>{
var task=await this.dao.create(qobj,t);
//发布任务事件
var action="new";
var taskClassName=task.taskClassName;
var exp=task.taskexp;
var msg=action+"_"+taskClassName+"_"+exp;
await self.taskManager.newTask(msg);
await self.taskManager.publish("task","newtask");
return task;
});
}
async restartTasks2(qobj){
return this.restartTasks(qobj);
}
async restartTasks(qobj){
var self=this;
var rtn={};
var tasks=await this.dao.model.findAll({raw:true});
//清空任务列表
await this.taskManager.clearlist();
for(var i=0;i<tasks.length;i++){
var tmpTask2=tasks[i];
try {
(async (tmpTask,that)=>{
var action="new";
var taskClassName=tmpTask.taskClassName;
var exp=tmpTask.taskexp;
var msg=action+"_"+taskClassName+"_"+exp;
// await that.taskManager.newTask(msg);
// await that.taskManager.publish("task","newtask");
await that.taskManager.addTask(taskClassName,exp);
})(tmpTask2,self);
} catch (e) {
rtn=null;
}
}
return rtn;
}
async delete(qobj){
var self=this;
return this.db.transaction(async t=>{
var task= await this.dao.model.findOne({where:qobj});
await this.dao.delete(task,qobj,t);
//发布任务事件
var action="delete";
var taskName=task.taskClassName;
var exp=task.taskexp;
var msg=action+"_"+taskName;
//发布任务,消息是action_taskClassName
await this.taskManager.publish("task",msg,null);
return task;
});
}
}
module.exports=TaskService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class UploadService extends ServiceBase{
constructor(){
super("common",ServiceBase.getDaoName(UploadService));
//this.appDao=system.getObject("db.appDao");
}
}
module.exports=UploadService;
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