GetCompanyIncomesService.java 17 KB

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