PettyCashService.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package net.chenlin.dp.modules.api.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.mysql.cj.util.StringUtils;
  4. import net.chenlin.dp.common.openapi4j.examples.voucher.VoucherAdd;
  5. import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
  6. import net.chenlin.dp.common.openapi4j.service.PersonService;
  7. import net.chenlin.dp.common.openapi4j.util.PropUtil;
  8. import net.chenlin.dp.common.utils.JSONUtils;
  9. import net.chenlin.dp.common.utils.SpringContextUtils;
  10. import net.chenlin.dp.modules.api.controller.DingdingOpenInterface;
  11. import net.chenlin.dp.modules.sys.entity.SyViewEntity;
  12. import net.chenlin.dp.modules.sys.service.testU8Service;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.Properties;
  17. /**
  18. * 钉钉备用金
  19. * 生成至u8总账
  20. */
  21. public class PettyCashService {
  22. private testU8Service u8Service= SpringContextUtils.getBean("testU8Service",testU8Service.class);
  23. public void autoUpdataPetty() throws Exception {
  24. DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
  25. Properties prop = PropUtil.getProperties("/config.properties");
  26. String PROC = prop.getProperty("byj_process_code");
  27. List<String> list = dingdingOpenInterface.getOrderIdList(PROC);
  28. //
  29. List<SyViewEntity> listId = u8Service.selectView("备用金");
  30. if(list.size() > 0){
  31. outCycle:for(String o:list){
  32. if(listId.size() > 0){
  33. for(SyViewEntity en:listId){
  34. if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
  35. continue outCycle;
  36. }
  37. }
  38. }
  39. String job_number = "";//工号
  40. String work_place = "";//办公地(潍坊对03账套 昆山对01账套)
  41. String dept_code = ""; //部门编码
  42. String type = ""; //数据源账套 1昆山,3潍坊
  43. Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
  44. // Map<String,Object> map = dingdingOpenInterface.getOrderDetails("0861edce-4cfb-4b1d-ac3a-19ed29ae5214");
  45. if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
  46. continue;
  47. }
  48. // System.out.println(map.get("originator_dept_name"));CHK2019001
  49. Map<String,Object> map1 = dingdingOpenInterface.tableToMap(map);
  50. Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId(map.get("originator_userid").toString());
  51. // Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId("2006265537678286");
  52. if(mapPerson !=null ){
  53. job_number = mapPerson.get("job_number").toString();
  54. work_place = mapPerson.get("work_place").toString();
  55. if(StringUtils.isNullOrEmpty(work_place)){
  56. continue;
  57. }
  58. if (work_place.equals("昆山")){
  59. dept_code = getPerson(job_number,"1");
  60. type = "1";
  61. }else if(work_place.equals("潍坊")){
  62. dept_code = getPerson(job_number,"3");
  63. type = "3";
  64. }else{
  65. continue;
  66. }
  67. }else{
  68. continue;
  69. }
  70. map1.put("abstract",map1.get("申请事由"));
  71. map1.put("naturalCurrency",map1.get("申请金额(元)"));
  72. map1.put("account_code","122102");//科目编码
  73. map1.put("dept_code",dept_code);//部门编码
  74. map1.put("job_number",job_number);//人员编码
  75. String mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString(),type);
  76. SyViewEntity entity = new SyViewEntity();
  77. entity.setOaId(o);
  78. entity.setAccountCode("122102");
  79. entity.setParType("备用金");
  80. // entity.setDeptName(map.get("originator_dept_name").toString());
  81. entity.setDeptCode(dept_code);
  82. entity.setJobNumber(job_number);
  83. entity.setJobNumber("备用金");
  84. entity.setSyMessage(mess);
  85. try {
  86. u8Service.saveSyView(entity);
  87. }catch (Exception e){
  88. System.out.println("异常备用金");
  89. }
  90. }
  91. }
  92. }
  93. /**
  94. * 根据人员编码查询u8人员信息
  95. * @param id
  96. * @param ds
  97. */
  98. public static String getPerson(String id,String ds){
  99. Properties prop = PropUtil.getProperties("/config.properties");
  100. String to_account = prop.getProperty("to_account");
  101. PersonService par = new PersonService();
  102. String code = "";
  103. try {
  104. JSONObject record = par.get(id, to_account,ds);
  105. if(record.get("errcode").equals("0")){
  106. JSONObject record1 = (JSONObject) record.get("person");
  107. code = record1.get("cdept_num").toString();
  108. }
  109. System.out.println(record);
  110. } catch (OpenAPIException e) {
  111. return code;
  112. }
  113. return code;
  114. }
  115. public static void main(String[] args) throws Exception {
  116. // autoUpdataPetty();
  117. // getPerson("CHK2021001",null);
  118. }
  119. }