package cn.autoform.util; import cn.autoform.log.bean.OperationLog; import cn.autoform.log.mapper.InitCompanyMapper; import cn.autoform.log.mapper.OperationLogMapper; import cn.autoform.log.service.SystemMathService; 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.stereotype.Service; import javax.annotation.Resource; import java.util.Map; import java.util.Objects; /** * Created by guoqy on 2019/10/14 */ @Slf4j @Service public class OperationLogTool { @Resource private InitCompanyMapper initCompanyMapper; @Resource private OperationLogMapper operationLogMapper; @Resource private SystemMathService systemMathService; public void addOperationLog(String formId,String operNum){ //----------→添加日志 //----------→获取tenantname,companyname,costType String tenantId = ThreadData.get(Keys.TENANT_ID); String companyId = ThreadData.get(Keys.COMPANY_ID); String openId = ThreadData.get(Keys.USER_ID); log.debug("准备查询公司名称租户名称---------------------"); Map initCompany = initCompanyMapper.selectTenantnameAndCompanynameByid(String.valueOf(tenantId), String.valueOf(companyId)); log.debug("装备查询费用类型-----------------------------"); Map costType = systemMathService.getCostTypeByFormId(formId); log.debug("查询租户名称:{},公司名称:{}", initCompany.get("tenant_name"), initCompany.get("company_name")); log.debug("费用类型:{},表单名称:{}",costType.get("type"),costType.get("f_name")); if (initCompany != null && costType != null) { OperationLog operationLog = new OperationLog(); operationLog.setTenantId(tenantId); operationLog.setCompanyId(companyId); operationLog.setTenantName(Objects.toString(initCompany.get("tenant_name"),"")); operationLog.setCompanyName(Objects.toString(initCompany.get("company_name"),"")); operationLog.setOpenId(openId); operationLog.setFormId(costType.get("formId")); operationLog.setCostType(Objects.toString(costType.get("type"),"")); operationLog.setFormName(Objects.toString(costType.get("f_name"),"")); operationLog.setOperation(operNum);//删除 try { log.debug("操作日志启动---------->:{}", JSONTool.toJson(operationLog)); operationLogMapper.addOperationLog(operationLog); log.debug("操作日志成功记录---------->"); } catch (Exception e) { log.error("操作日志添加异常---------->{}", e.getMessage()); } //----------→添加日志 } } }