GetCompanyIncomesService.java 22 KB

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