|
@@ -1,50 +1,222 @@
|
|
|
package net.chenlin.dp.modules.api.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.mysql.cj.util.StringUtils;
|
|
|
import net.chenlin.dp.common.openapi4j.examples.voucher.VoucherAdd;
|
|
|
+import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
|
|
|
+import net.chenlin.dp.common.openapi4j.service.PersonService;
|
|
|
import net.chenlin.dp.common.openapi4j.util.PropUtil;
|
|
|
import net.chenlin.dp.modules.api.controller.DingdingOpenInterface;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Properties;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class ReimbursementService {
|
|
|
|
|
|
- public static void autoReimbursement(){
|
|
|
+ public static void autoReimbursement() throws Exception {
|
|
|
|
|
|
DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
|
|
|
Properties prop = PropUtil.getProperties("/config.properties");
|
|
|
String PROC = prop.getProperty("bx_process_code");
|
|
|
List<String> list = dingdingOpenInterface.getOrderIdList(PROC);
|
|
|
+ String job_number = "";//工号
|
|
|
+ String work_place = "";//办公地(潍坊对03账套 昆山对01账套)
|
|
|
+ String dept_code = ""; //部门编码
|
|
|
+ String account_code = ""; //科目编码
|
|
|
+ String type = ""; //数据源账套 1昆山,3潍坊
|
|
|
|
|
|
if(list.size() > 0){
|
|
|
for(String o:list){
|
|
|
|
|
|
+// Map<String,Object> map = dingdingOpenInterface.getOrderDetails("8ee5b37b-8702-4068-874f-eb74c5e78863");
|
|
|
Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
|
|
|
if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
|
|
|
continue;
|
|
|
}
|
|
|
+ Map<String,Object> map1 = tableToMap2(map);
|
|
|
+ Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId(map.get("originator_userid").toString());
|
|
|
+
|
|
|
+ if(mapPerson !=null ){
|
|
|
+ job_number = mapPerson.get("job_number").toString();
|
|
|
+ work_place = mapPerson.get("work_place").toString();
|
|
|
+ if(StringUtils.isNullOrEmpty(work_place)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (work_place.equals("昆山")){
|
|
|
+ dept_code = getPerson(job_number,"1");
|
|
|
+ type = "1";
|
|
|
+ System.out.println(dept_code);
|
|
|
+ }else if(work_place.equals("潍坊")){
|
|
|
+ dept_code = getPerson(job_number,"3");
|
|
|
+ type = "3";
|
|
|
+ }else{
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(map.get("originator_dept_name") == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(map1.containsKey("差旅报销")){
|
|
|
+ account_code = getDeptCode(map.get("originator_dept_name").toString(),"差旅报销");
|
|
|
+ map1.put("abstract","差旅报销");
|
|
|
+ map1.put("naturalCurrency",map1.get("差旅报销"));
|
|
|
+ map1.put("account_code",account_code);//科目编码
|
|
|
+ map1.put("dept_code",dept_code);//部门编码
|
|
|
+ map1.put("job_number",job_number);//人员编码
|
|
|
+// System.out.println("============================");
|
|
|
+// System.out.println(map1);
|
|
|
+ VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"差旅",type);
|
|
|
+ }
|
|
|
+ if(map1.containsKey("私车公用报销")){
|
|
|
+ account_code = getDeptCode(map.get("originator_dept_name").toString(),"私车公用报销");
|
|
|
+ map1.put("abstract","私车公用报销");
|
|
|
+ map1.put("naturalCurrency",map1.get("私车公用报销"));
|
|
|
+ map1.put("account_code",account_code);//科目编码
|
|
|
+ map1.put("dept_code",dept_code);//部门编码
|
|
|
+ map1.put("job_number",job_number);//人员编码
|
|
|
+// System.out.println("============================");
|
|
|
+// System.out.println(map1);
|
|
|
+ VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"私车公用",type);
|
|
|
+ }
|
|
|
+ if(map1.containsKey("其他报销科目")){
|
|
|
+ account_code = getDeptCode(map.get("originator_dept_name").toString(),"其他报销科目");
|
|
|
+ map1.put("abstract","其他报销科目");
|
|
|
+ map1.put("naturalCurrency",map1.get("其他报销科目"));
|
|
|
+ map1.put("account_code",account_code);//科目编码
|
|
|
+ map1.put("dept_code",dept_code);//部门编码
|
|
|
+ map1.put("job_number",job_number);//人员编码
|
|
|
+// System.out.println("============================");
|
|
|
+// System.out.println(map1);
|
|
|
+ VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"其他",type);
|
|
|
+ }
|
|
|
|
|
|
- Map<String,Object> map1 = dingdingOpenInterface.tableToMap(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
-// System.out.println(map.get("business_id"));
|
|
|
-// System.out.println("============================");
|
|
|
-// System.out.println(map1.get("总计金额"));
|
|
|
- map1.put("abstract","报销");
|
|
|
- map1.put("naturalCurrency",map1.get("总计金额"));
|
|
|
+ public static Map<String,Object> tableToMap2(Map<String,Object> map1){
|
|
|
|
|
|
- VoucherAdd.addVoucher(map1,map.get("business_id").toString());
|
|
|
+ List<Map<String,Object>> listMap = (List<Map<String, Object>>) map1.get("form_component_values");
|
|
|
+ Map<String,Object> newMap = new HashMap<>();
|
|
|
+ int st = 0;
|
|
|
+ for(Map<String, Object> o:listMap){
|
|
|
+ if(o.get("name")==null || StringUtils.isNullOrEmpty(o.get("name").toString())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(o.get("name").equals("差旅报销")){
|
|
|
+ st = 1;
|
|
|
+ }
|
|
|
+ if(o.get("name").equals("私车公用报销")){
|
|
|
+ st = 2;
|
|
|
+ }
|
|
|
+ if(o.get("name").equals("其他报销科目")){
|
|
|
+ st = 3;
|
|
|
+ }
|
|
|
|
|
|
+ if(st == 1 && o.get("name").equals("合计")){
|
|
|
+ if(newMap.containsKey("差旅报销")){
|
|
|
+ newMap.put("差旅报销",Double.valueOf(o.get("value").toString())+Double.valueOf(newMap.get("差旅报销").toString()) );
|
|
|
+ }else {
|
|
|
+ newMap.put("差旅报销",o.get("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(st == 2 && o.get("name").equals("合计")){
|
|
|
+ if(newMap.containsKey("私车公用报销")){
|
|
|
+ newMap.put("私车公用报销",Double.valueOf(o.get("value").toString())+Double.valueOf(newMap.get("私车公用报销").toString()) );
|
|
|
+ }else {
|
|
|
+ newMap.put("私车公用报销",o.get("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(st == 3 && o.get("name").equals("合计")){
|
|
|
+ if(newMap.containsKey("其他报销科目")){
|
|
|
+ newMap.put("其他报销科目",Double.valueOf(o.get("value").toString())+Double.valueOf(newMap.get("其他报销科目").toString()) );
|
|
|
+ }else {
|
|
|
+ newMap.put("其他报销科目",o.get("value"));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ return newMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过部门名称对应u8科目编码
|
|
|
+ * @param dept
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getDeptCode(String dept,String type){
|
|
|
+
|
|
|
+ if(dept.equals("营销设计中心-总经理室") || dept.equals("营销设计中心-采购部") || dept.equals("共享中心-财务部") || dept.equals("共享中心-人事行政部")){
|
|
|
+ if("差旅报销".equals(type)){
|
|
|
+ return "66020704";
|
|
|
+ }else if("私车公用报销".equals(type)){
|
|
|
+ return "66020702";
|
|
|
+ }else{
|
|
|
+ return "66020706";
|
|
|
+ }
|
|
|
+ }else if(dept.equals("营销设计中心-销售部")){
|
|
|
+ if("差旅报销".equals(type)){
|
|
|
+ return "6601070104";
|
|
|
+ }else if("私车公用报销".equals(type)){
|
|
|
+ return "6601070102";
|
|
|
+ }else{
|
|
|
+ return "6601070106";
|
|
|
+ }
|
|
|
+ }else if(dept.equals("营销设计中心-设计部")){
|
|
|
+ if("差旅报销".equals(type)){
|
|
|
+ return "66040704";
|
|
|
+ }else if("私车公用报销".equals(type)){
|
|
|
+ return "66040702";
|
|
|
+ }else{
|
|
|
+ return "66040706";
|
|
|
+ }
|
|
|
+ }else if(dept.equals("营销设计中心-项目部") || dept.equals("营销设计中心-市场部")){
|
|
|
+ if("差旅报销".equals(type)){
|
|
|
+ return "6601070204";
|
|
|
+ }else if("私车公用报销".equals(type)){
|
|
|
+ return "6601070202";
|
|
|
+ }else{
|
|
|
+ return "6601070206";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据人员编码查询u8人员信息
|
|
|
+ * @param id
|
|
|
+ * @param ds
|
|
|
+ */
|
|
|
+ public static String getPerson(String id,String ds){
|
|
|
+ Properties prop = PropUtil.getProperties("/config.properties");
|
|
|
+ String to_account = prop.getProperty("to_account");
|
|
|
+ PersonService par = new PersonService();
|
|
|
+ String code = "";
|
|
|
+ try {
|
|
|
+ JSONObject record = par.get(id, to_account,ds);
|
|
|
+
|
|
|
+ if(record.get("errcode").equals("0")){
|
|
|
+ JSONObject record1 = (JSONObject) record.get("person");
|
|
|
+ code = record1.get("cdept_num").toString();
|
|
|
+ }
|
|
|
+ System.out.println(record);
|
|
|
+
|
|
|
+ } catch (OpenAPIException e) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
|
|
|
+ return code;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
autoReimbursement();
|
|
|
}
|
|
|
|