zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
commit | author | age
a18bfa 1 package com.changhong.epc.form.tool;
Z 2
3 import com.changhong.epc.config.tool.MybatisTool;
4 import com.changhong.epc.constter.base.Context;
5 import com.changhong.epc.constter.form.utf.FormUrlConst;
6 import com.changhong.epc.form.mapper.tenant.log.OperationLogMapper;
7 import com.changhong.epc.rely.api.bean.report.OperationLog;
8 import com.changhong.epc.rely.api.epc.admin.CostFromTemplateApi;
9 import com.changhong.epc.rely.api.epc.admin.InitCompanyApi;
10 import com.iemsoft.framework.cloud.core.thread.Keys;
11 import com.iemsoft.framework.cloud.core.thread.ThreadData;
12 import com.iemsoft.framework.cloud.core.tools.JSONTool;
13 import lombok.extern.slf4j.Slf4j;
14 import org.springframework.util.ObjectUtils;
15 import org.springframework.web.bind.annotation.PostMapping;
16 import org.springframework.web.bind.annotation.RequestBody;
17 import org.springframework.web.bind.annotation.RestController;
18
19 import javax.annotation.Resource;
20 import java.util.Map;
21 import java.util.Objects;
22
23 /**
24  * Created by guoqy on 2019/10/14
25  */
26 @Slf4j
27 @RestController
28 public class OperationLogTool implements FormUrlConst {
29
30     @Resource
31     private  OperationLogMapper operationlogMapper;
32     @Resource
33     private  InitCompanyApi initCompanyApi;
34     @Resource
35     private  CostFromTemplateApi costFromTemplateApi;
36
37     @PostMapping(OPERATION_LOG_ADD)
38     public  void addOperationLog(@RequestBody Map<String,String> map){
39         //----------→添加日志
40         //----------→获取tenantname,companyname,costType
41         String tenantId = ThreadData.get(Keys.TENANT_ID);
42         String companyId = ThreadData.get(Keys.COMPANY_ID);
43         log.debug("准备查询公司名称租户名称---------------------");
44         Map initCompany = initCompanyApi.getInitCompanynameAndTenantname(Integer.valueOf(tenantId), Integer.valueOf(companyId));
45         log.debug("查询租户名称:{},公司名称:{}", initCompany.get("tenant_name"), initCompany.get("company_name"));
46         Map costType = costFromTemplateApi.getCostType(map.get("formId"),map.get("dataRowNum"));
47         log.debug("费用类型:{},表单名称:{}",costType.get("type"),costType.get("f_name"));
48         //通过dataRowNum查询申请单或者报销单编号
49         if(!ObjectUtils.isEmpty(costType.get("type")) && costType.get("type").equals("SQ")){
50             String tableName = "formdata_"+tenantId+"_"+map.get("formId");
51             String formNum = operationlogMapper.getSQFormNum(map.get("dataRowNum"), tableName);
52             log.debug("查询到的申请单编号----{}",formNum);
53             String cost_type = operationlogMapper.costName(map.get("dataRowNum"),map.get("formId"),tenantId,companyId);
54             log.debug("查询到的费用类型----{}",cost_type);
55             addOperation(initCompany,costType,map,formNum,cost_type);
56         }else if(!ObjectUtils.isEmpty(costType.get("type")) && costType.get("type").equals("BX")){
57             String tableName = "formdata_"+tenantId+"_"+map.get("formId");
58             String formNum = operationlogMapper.getBQFormNum(map.get("dataRowNum"), tableName);
59             log.debug("查询到的报销单编号----{}",formNum);
60             String cost_type = operationlogMapper.costName(map.get("dataRowNum"),map.get("formId"),tenantId,companyId);
61             log.debug("查询到的费用类型名称----{}",cost_type);
62             addOperation(initCompany,costType,map,formNum,cost_type);
63
64         }
65
66     }
67     private void addOperation(Map initCompany,Map costType,Map<String,String> map,String formNum,String cost_type){
68         MybatisTool.setAdminDataSource();
69         MybatisTool.initDataSource();
70         if (initCompany != null && costType != null) {
71             OperationLog operationLog = new OperationLog();
72             operationLog.setTenantId( ThreadData.get(Keys.TENANT_ID));
73             operationLog.setCompanyId(ThreadData.get(Keys.COMPANY_ID));
74             operationLog.setTenantName(Objects.toString(initCompany.get("tenant_name"),""));
75             operationLog.setCompanyName(Objects.toString(initCompany.get("company_name"),""));
76             operationLog.setOpenId(Context.getUserInfo().getUserName());
77             operationLog.setFormId(map.get("formId"));
78             operationLog.setFormNum(formNum);
79             operationLog.setModulesName(Objects.toString(costType.get("type"),""));
80             operationLog.setCostType(Objects.toString(cost_type,""));
81             operationLog.setFormName(Objects.toString(costType.get("f_name"),""));
82             operationLog.setOperation(map.get("operationNum"));//删除
83             try {
84                 log.debug("开始记录操作日志---------->:{}", JSONTool.toJson(operationLog));
85
86                 operationlogMapper.addOperationLog(operationLog);
87                 log.debug("操作日志成功记录---------->");
88             } catch (Exception e) {
89                 log.error("操作日志添加异常---------->{}", e.getMessage());
90             }
91             //----------→添加日志
92         }
93     }
94 }