package com.changhong.epc.form.tool;
|
|
import com.changhong.epc.config.tool.MybatisTool;
|
import com.changhong.epc.constter.base.Context;
|
import com.changhong.epc.constter.form.utf.FormUrlConst;
|
import com.changhong.epc.form.mapper.tenant.log.OperationLogMapper;
|
import com.changhong.epc.rely.api.bean.report.OperationLog;
|
import com.changhong.epc.rely.api.epc.admin.CostFromTemplateApi;
|
import com.changhong.epc.rely.api.epc.admin.InitCompanyApi;
|
import com.iemsoft.framework.cloud.core.thread.Keys;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.util.Map;
|
import java.util.Objects;
|
|
/**
|
* Created by guoqy on 2019/10/14
|
*/
|
@Slf4j
|
@RestController
|
public class OperationLogTool implements FormUrlConst {
|
|
@Resource
|
private OperationLogMapper operationlogMapper;
|
@Resource
|
private InitCompanyApi initCompanyApi;
|
@Resource
|
private CostFromTemplateApi costFromTemplateApi;
|
|
@PostMapping(OPERATION_LOG_ADD)
|
public void addOperationLog(@RequestBody Map<String,String> map){
|
//----------→添加日志
|
//----------→获取tenantname,companyname,costType
|
String tenantId = ThreadData.get(Keys.TENANT_ID);
|
String companyId = ThreadData.get(Keys.COMPANY_ID);
|
log.debug("准备查询公司名称租户名称---------------------");
|
Map initCompany = initCompanyApi.getInitCompanynameAndTenantname(Integer.valueOf(tenantId), Integer.valueOf(companyId));
|
log.debug("查询租户名称:{},公司名称:{}", initCompany.get("tenant_name"), initCompany.get("company_name"));
|
Map costType = costFromTemplateApi.getCostType(map.get("formId"),map.get("dataRowNum"));
|
log.debug("费用类型:{},表单名称:{}",costType.get("type"),costType.get("f_name"));
|
//通过dataRowNum查询申请单或者报销单编号
|
if(!ObjectUtils.isEmpty(costType.get("type")) && costType.get("type").equals("SQ")){
|
String tableName = "formdata_"+tenantId+"_"+map.get("formId");
|
String formNum = operationlogMapper.getSQFormNum(map.get("dataRowNum"), tableName);
|
log.debug("查询到的申请单编号----{}",formNum);
|
String cost_type = operationlogMapper.costName(map.get("dataRowNum"),map.get("formId"),tenantId,companyId);
|
log.debug("查询到的费用类型----{}",cost_type);
|
addOperation(initCompany,costType,map,formNum,cost_type);
|
}else if(!ObjectUtils.isEmpty(costType.get("type")) && costType.get("type").equals("BX")){
|
String tableName = "formdata_"+tenantId+"_"+map.get("formId");
|
String formNum = operationlogMapper.getBQFormNum(map.get("dataRowNum"), tableName);
|
log.debug("查询到的报销单编号----{}",formNum);
|
String cost_type = operationlogMapper.costName(map.get("dataRowNum"),map.get("formId"),tenantId,companyId);
|
log.debug("查询到的费用类型名称----{}",cost_type);
|
addOperation(initCompany,costType,map,formNum,cost_type);
|
|
}
|
|
}
|
private void addOperation(Map initCompany,Map costType,Map<String,String> map,String formNum,String cost_type){
|
MybatisTool.setAdminDataSource();
|
MybatisTool.initDataSource();
|
if (initCompany != null && costType != null) {
|
OperationLog operationLog = new OperationLog();
|
operationLog.setTenantId( ThreadData.get(Keys.TENANT_ID));
|
operationLog.setCompanyId(ThreadData.get(Keys.COMPANY_ID));
|
operationLog.setTenantName(Objects.toString(initCompany.get("tenant_name"),""));
|
operationLog.setCompanyName(Objects.toString(initCompany.get("company_name"),""));
|
operationLog.setOpenId(Context.getUserInfo().getUserName());
|
operationLog.setFormId(map.get("formId"));
|
operationLog.setFormNum(formNum);
|
operationLog.setModulesName(Objects.toString(costType.get("type"),""));
|
operationLog.setCostType(Objects.toString(cost_type,""));
|
operationLog.setFormName(Objects.toString(costType.get("f_name"),""));
|
operationLog.setOperation(map.get("operationNum"));//删除
|
try {
|
log.debug("开始记录操作日志---------->:{}", JSONTool.toJson(operationLog));
|
|
operationlogMapper.addOperationLog(operationLog);
|
log.debug("操作日志成功记录---------->");
|
} catch (Exception e) {
|
log.error("操作日志添加异常---------->{}", e.getMessage());
|
}
|
//----------→添加日志
|
}
|
}
|
}
|