GetCompanyIncomesService.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package com.kingdee.eas.custom.shuiyou.six.osf;
  2. import cn.hutool.core.util.StrUtil;
  3. import cn.hutool.json.JSONArray;
  4. import cn.hutool.json.JSONObject;
  5. import cn.hutool.json.JSONUtil;
  6. import com.google.common.collect.Maps;
  7. import com.kingdee.bos.BOSException;
  8. import com.kingdee.bos.Context;
  9. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  10. import com.kingdee.bos.metadata.entity.*;
  11. import com.kingdee.bos.metadata.query.util.CompareType;
  12. import com.kingdee.eas.basedata.person.*;
  13. import com.kingdee.eas.common.EASBizException;
  14. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  15. import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade;
  16. import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory;
  17. import com.kingdee.eas.custom.shuiyou.uitls.URLConfigEnum;
  18. import com.kingdee.eas.framework.CoreBaseCollection;
  19. import com.kingdee.shr.compensation.app.tax.*;
  20. import com.kingdee.shr.compensation.util.Base64Utils;
  21. import com.kingdee.shr.dydeploy.web.executeSql.ExceptionUtils;
  22. import java.math.BigDecimal;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Calendar;
  25. import java.util.Map;
  26. /**
  27. * description: GetCompanyIncomes <br>
  28. * date: 2024/9/13 19:02 <br>
  29. * author: lhbj <br>
  30. * version: 1.0 <br>
  31. */
  32. public class GetCompanyIncomesService implements IHRMsfService {
  33. @Override
  34. public Object process(Context context, Map map) throws EASBizException, BOSException {
  35. String this_taskid = (String) map.get("this_taskId");
  36. String param = (String) map.get("paramData");
  37. ISYUtilsFacade facade = SYUtilsFacadeFactory.getLocalInstance(context);
  38. Map<String, String> config = facade.getConfig();
  39. ITaxUnit taxUnit = TaxUnitFactory.getLocalInstance(context);
  40. String skssq = (String) map.get("skssq");
  41. MessageResult messageResult = null;
  42. try {
  43. JSONObject parJSONMap = null;
  44. if (StrUtil.isNotBlank(param)) {
  45. parJSONMap = JSONUtil.parseObj(param);
  46. if (StrUtil.isBlank(skssq)) {
  47. skssq = (String) parJSONMap.getStr("skssq");
  48. }
  49. }
  50. BigDecimal ZERO = BigDecimal.ZERO;
  51. EntityViewInfo viewInfo = new EntityViewInfo();
  52. SelectorItemCollection sc = new SelectorItemCollection();
  53. sc.add(new SelectorItemInfo("id"));
  54. sc.add(new SelectorItemInfo("number"));
  55. sc.add(new SelectorItemInfo("name"));
  56. sc.add(new SelectorItemInfo("realPassword"));//实名密码
  57. sc.add(new SelectorItemInfo("declPassword"));//申报密码
  58. sc.add(new SelectorItemInfo("areaCode"));//行政区划代码
  59. sc.add(new SelectorItemInfo("regNumber"));//登记号
  60. sc.add(new SelectorItemInfo("taxNumber"));//扣缴单位纳税人识别号
  61. sc.add(new SelectorItemInfo("state"));
  62. viewInfo.setSelector(sc);
  63. FilterInfo filterInfo = new FilterInfo();
  64. filterInfo.getFilterItems().add(new FilterItemInfo("state", "1", CompareType.EQUALS));
  65. viewInfo.setFilter(filterInfo);
  66. TaxUnitCollection taxUnitCollection = taxUnit.getTaxUnitCollection(viewInfo);
  67. ITaxDeclaration taxDeclaration = TaxDeclarationFactory.getLocalInstance(context);
  68. IPerson iPerson = PersonFactory.getLocalInstance(context);
  69. EntityViewInfo personViewInfo = new EntityViewInfo();
  70. SelectorItemCollection personSc = new SelectorItemCollection();
  71. personSc.add(new SelectorItemInfo("id"));
  72. personViewInfo.setSelector(personSc);
  73. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  74. System.out.println("GetCompanyIncomesService:" + taxUnitCollection.toString());
  75. for (int i = 0; i < taxUnitCollection.size(); i++) {
  76. TaxUnitInfo taxUnitInfo = taxUnitCollection.get(i);
  77. String declPassword = taxUnitInfo.getDeclPassword();
  78. String areaid = taxUnitInfo.getAreaCode();
  79. String name = taxUnitInfo.getName();
  80. String djxhid = taxUnitInfo.getRegNumber();
  81. String nsrsbh = taxUnitInfo.getTaxNumber();
  82. if (StrUtil.isNotBlank(nsrsbh) && StrUtil.isNotBlank(djxhid) &&
  83. StrUtil.isNotBlank(name) && StrUtil.isNotBlank(areaid) &&
  84. StrUtil.isNotBlank(declPassword)) {
  85. Map<String, Object> paramMap = Maps.newHashMap();
  86. paramMap.put("bizNo", facade.getBizNo());
  87. paramMap.put("qymc", name);
  88. paramMap.put("nsrsbh", nsrsbh);
  89. paramMap.put("areaid", areaid);
  90. paramMap.put("skssq", skssq);
  91. paramMap.put("sbmm", Base64Utils.decode(declPassword));
  92. paramMap.put("reportType", "1");
  93. int pageNo = 1;
  94. int pageSize = 4999;
  95. paramMap.put("pageSize", pageSize);
  96. if (StrUtil.isNotBlank(param)) {
  97. JSONObject jsonObject = JSONUtil.parseObj(param);
  98. for (Map.Entry entry : jsonObject.entrySet()) {
  99. paramMap.put((String) entry.getKey(), entry.getValue());
  100. }
  101. }
  102. boolean next = false;
  103. do {
  104. paramMap.put("pageNo", pageNo);
  105. next = false;
  106. param = JSONUtil.toJsonStr(paramMap);
  107. System.out.println("GetCompanyIncomesService:result:" + param.toString());
  108. String result = facade.post(config.get("ip") + URLConfigEnum.GETCOMPANYINCOMES_VALUE, param);
  109. System.out.println("GetCompanyIncomesService:result:" + result.toString());
  110. TaxDeclarationInfo info = new TaxDeclarationInfo();
  111. JSONObject resultMap = JSONUtil.parseObj(result);
  112. JSONObject head = resultMap.getJSONObject("head");
  113. JSONObject body = resultMap.getJSONObject("body");
  114. String code = head.getStr("code");
  115. if ("00000000".equals(code)) {
  116. String total = body.getStr("total");
  117. Integer totalInt = Integer.valueOf(total);
  118. if (totalInt.compareTo(0) > 0) {
  119. if (totalInt.compareTo(pageSize + pageNo) > 0) {
  120. pageNo = pageNo + 1;
  121. next = true;
  122. }
  123. JSONArray sfmx = body.getJSONArray("sfmx");
  124. CoreBaseCollection collection = new CoreBaseCollection();
  125. CoreBaseCollection upCollection = new CoreBaseCollection();
  126. for (int j = 0; j < sfmx.size(); j++) {
  127. TaxDeclarationInfo declaration = new TaxDeclarationInfo();
  128. JSONObject sfm = sfmx.getJSONObject(j);
  129. String zjhm = sfm.getStr("zjhm");
  130. FilterInfo personfilterInfo = new FilterInfo();
  131. personfilterInfo.getFilterItems().add(new FilterItemInfo("idCardNO", zjhm, CompareType.EQUALS));
  132. FilterInfo personfilterInfo2 = new FilterInfo();
  133. personfilterInfo2.getFilterItems().add(new FilterItemInfo("passportNO", zjhm, CompareType.EQUALS));
  134. personfilterInfo.mergeFilter(personfilterInfo2, "or");
  135. personViewInfo.setFilter(personfilterInfo);
  136. PersonCollection perc = iPerson.getPersonCollection(personViewInfo);
  137. PersonInfo personInfo = null;
  138. if (null != perc) {
  139. personInfo = perc.get(0);
  140. }
  141. if (null == personInfo) {
  142. continue;
  143. }
  144. declaration.setPerson(personInfo);
  145. Integer year = Integer.valueOf(skssq.substring(0, 4));
  146. Integer month = Integer.valueOf(skssq.substring(4, 6));
  147. declaration.setPeriodYear(year);
  148. declaration.setPeriodMonth(month);
  149. FilterInfo filterInfo1 = new FilterInfo();
  150. filterInfo1.getFilterItems().add(new FilterItemInfo("person.id", personInfo.getId().toString(), CompareType.EQUALS));
  151. filterInfo1.getFilterItems().add(new FilterItemInfo("periodYear", year, CompareType.EQUALS));
  152. filterInfo1.getFilterItems().add(new FilterItemInfo("periodMonth", month, CompareType.EQUALS));
  153. Calendar begin = Calendar.getInstance();
  154. begin.set(year, month, 1);
  155. declaration.setTaxPeriodBegin(begin.getTime());
  156. begin.add(Calendar.MONTH, 1);
  157. begin.add(Calendar.DAY_OF_MONTH, -1);
  158. declaration.setTaxPeriodEnd(begin.getTime());
  159. declaration.setTaxUnit(taxUnitInfo);
  160. declaration.setIdType(sfm.getStr("zjlx"));//证件类型
  161. declaration.setIdNO(zjhm);
  162. declaration.setTaxPayerNum(sfm.getStr(nsrsbh));
  163. declaration.setIsPersonal(("1".equals(sfm.getStr("sffjm"))) ? false : true);//非居民个人;1:否 2:是
  164. declaration.setProceedItem(sfm.getStr("sdxmmc"));//所得项目名称
  165. String income = sfm.getStr("sre");
  166. declaration.setIncome(StrUtil.isNotBlank(income) ? new BigDecimal(income) : ZERO);
  167. String cost = sfm.getStr("fy");
  168. declaration.setIncome(StrUtil.isNotBlank(cost) ? new BigDecimal(cost) : ZERO);
  169. String exemptIncome = sfm.getStr("mssr");
  170. declaration.setExemptIncome(StrUtil.isNotBlank(exemptIncome) ? new BigDecimal(exemptIncome) : ZERO);
  171. String deductions = sfm.getStr("jcfy");
  172. declaration.setDeductions(StrUtil.isNotBlank(deductions) ? new BigDecimal(deductions) : ZERO);
  173. String basicPension = sfm.getStr("jbylaobxf");
  174. declaration.setBasicPension(StrUtil.isNotBlank(basicPension) ? new BigDecimal(basicPension) : ZERO);
  175. String basicMedical = sfm.getStr("jbylbxf");
  176. declaration.setBasicMedical(StrUtil.isNotBlank(basicMedical) ? new BigDecimal(basicMedical) : ZERO);
  177. String unemployment = sfm.getStr("sybxf");
  178. declaration.setUnemployment(StrUtil.isNotBlank(unemployment) ? new BigDecimal(unemployment) : ZERO);
  179. String housingFund = sfm.getStr("zfgjj");
  180. declaration.setHousingFund(StrUtil.isNotBlank(housingFund) ? new BigDecimal(housingFund) : ZERO);
  181. String annuity = sfm.getStr("nj");
  182. declaration.setAnnuity(StrUtil.isNotBlank(annuity) ? new BigDecimal(annuity) : ZERO);
  183. String comHelath = sfm.getStr("syjkbx");
  184. declaration.setComHelath(StrUtil.isNotBlank(comHelath) ? new BigDecimal(comHelath) : ZERO);
  185. String taxDeferred = sfm.getStr("syylbx");
  186. declaration.setTaxDeferred(StrUtil.isNotBlank(taxDeferred) ? new BigDecimal(taxDeferred) : ZERO);
  187. String originalValue = sfm.getStr("ccyz");
  188. declaration.setOriginalValue(StrUtil.isNotBlank(originalValue) ? new BigDecimal(originalValue) : ZERO);
  189. String taxAllowReduct = sfm.getStr("yxkcsf");
  190. declaration.setTaxAllowReduct(StrUtil.isNotBlank(taxAllowReduct) ? new BigDecimal(taxAllowReduct) : ZERO);
  191. String otherDeductions = sfm.getStr("qt");
  192. declaration.setOtherDeductions(StrUtil.isNotBlank(otherDeductions) ? new BigDecimal(otherDeductions) : ZERO);
  193. String incomeSum = sfm.getStr("ljsre");
  194. declaration.setIncomeSum(StrUtil.isNotBlank(incomeSum) ? new BigDecimal(incomeSum) : ZERO);
  195. String deductionSum = sfm.getStr("ljjcfy");
  196. declaration.setDeductionSum(StrUtil.isNotBlank(deductionSum) ? new BigDecimal(deductionSum) : ZERO);
  197. String specialDeductSum = sfm.getStr("ljzxkc");
  198. declaration.setSpecialDeductSum(StrUtil.isNotBlank(specialDeductSum) ? new BigDecimal(specialDeductSum) : ZERO);
  199. String ChildEducateSum = sfm.getStr("ljznjy");
  200. declaration.setChildEducateSum(StrUtil.isNotBlank(ChildEducateSum) ?
  201. new BigDecimal(ChildEducateSum) : ZERO);
  202. String OldSupportSum = sfm.getStr("ljsylr");
  203. declaration.setOldSupportSum(StrUtil.isNotBlank(OldSupportSum) ?
  204. new BigDecimal(OldSupportSum) : ZERO);
  205. String LoanInterestSum = sfm.getStr("ljzfdklx");
  206. declaration.setLoanInterestSum(StrUtil.isNotBlank(LoanInterestSum) ?
  207. new BigDecimal(LoanInterestSum) : ZERO);
  208. String HousingRentSum = sfm.getStr("ljzfzj");
  209. declaration.setHousingRentSum(StrUtil.isNotBlank(HousingRentSum) ?
  210. new BigDecimal(HousingRentSum) : ZERO);
  211. String ContinueEducateSum = sfm.getStr("ljjxjy");
  212. declaration.setContinueEducateSum(StrUtil.isNotBlank(ContinueEducateSum) ?
  213. new BigDecimal(ContinueEducateSum) : ZERO);
  214. String OtherDeductionSum = sfm.getStr("ljqtkc");
  215. declaration.setOtherDeductionSum(StrUtil.isNotBlank(OtherDeductionSum) ?
  216. new BigDecimal(OtherDeductionSum) : ZERO);
  217. String TaxableRatio = sfm.getStr("jjbl");
  218. declaration.setTaxableRatio(StrUtil.isNotBlank(TaxableRatio) ?
  219. new BigDecimal(TaxableRatio) : ZERO);
  220. String AllowDonationSum = sfm.getStr("zykcjze");
  221. declaration.setAllowDonationSum(StrUtil.isNotBlank(AllowDonationSum) ?
  222. new BigDecimal(AllowDonationSum) : ZERO);
  223. String TaxableIncomeSum = sfm.getStr("ynssde");
  224. declaration.setTaxableIncomeSum(StrUtil.isNotBlank(TaxableIncomeSum) ?
  225. new BigDecimal(TaxableIncomeSum) : ZERO);
  226. String TaxRatio = sfm.getStr("sl");
  227. declaration.setTaxRatio(StrUtil.isNotBlank(TaxRatio) ?
  228. new BigDecimal(TaxRatio) : ZERO);
  229. String QuickDeduct = sfm.getStr("sskcs");
  230. declaration.setQuickDeduct(StrUtil.isNotBlank(QuickDeduct) ?
  231. new BigDecimal(QuickDeduct) : ZERO);
  232. String TaxPayableSum = sfm.getStr("ynse");
  233. declaration.setTaxPayableSum(StrUtil.isNotBlank(TaxPayableSum) ?
  234. new BigDecimal(TaxPayableSum) : ZERO);
  235. String TaxCreditSum = sfm.getStr("jmse");
  236. declaration.setTaxCreditSum(StrUtil.isNotBlank(TaxCreditSum) ?
  237. new BigDecimal(TaxCreditSum) : ZERO);
  238. String TaxPaidSum = sfm.getStr("ykjse");
  239. declaration.setTaxPaidSum(StrUtil.isNotBlank(TaxPaidSum) ?
  240. new BigDecimal(TaxPaidSum) : ZERO);
  241. String TaxSupOrRefund = sfm.getStr("ybtse");
  242. declaration.setTaxSupOrRefund(StrUtil.isNotBlank(TaxSupOrRefund) ?
  243. new BigDecimal(TaxSupOrRefund) : ZERO);
  244. declaration.setSourceType(SourceType.outer);
  245. declaration.setItemDefine(ItemDefine.NormalSalary);
  246. declaration.setReportName(sfm.getStr("xm"));
  247. String InFantSum = sfm.getStr("ljyyezhzc");
  248. declaration.setInFantSum(StrUtil.isNotBlank(InFantSum) ?
  249. new BigDecimal(InFantSum) : ZERO);
  250. String PersonalPension = sfm.getStr("ljgrylj");
  251. declaration.setPersonalPension(StrUtil.isNotBlank(PersonalPension) ?
  252. new BigDecimal(PersonalPension) : ZERO);
  253. if (taxDeclaration.exists(filterInfo1)) {
  254. collection.add(declaration);
  255. } else {
  256. upCollection.add(declaration);
  257. }
  258. }
  259. if(collection.size()>0){
  260. taxDeclaration.addnewBatchData(collection);
  261. }
  262. if(upCollection.size()>0) {
  263. //taxDeclaration.updateBatchData(upCollection);
  264. }
  265. }
  266. }
  267. } while (next);
  268. }
  269. }
  270. messageResult = MessageResult.SUCCESS();
  271. } catch (Exception e) {
  272. e.printStackTrace();
  273. messageResult = MessageResult.ERROR(ExceptionUtils.getStackTrace(e));
  274. }
  275. return messageResult;
  276. }
  277. }