SynIncomeTaxDeclareService.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package com.kingdee.eas.custom.compensation.service;
  2. import cn.com.servyou.dto.ApiResponse;
  3. import cn.com.servyou.dto.declare.Feedback;
  4. import cn.com.servyou.rmi.client.ClientProxyFactory;
  5. import cn.com.servyou.service.DeclarationRequest;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fasterxml.jackson.databind.ObjectMapper;
  8. import com.kingdee.bos.BOSException;
  9. import com.kingdee.bos.Context;
  10. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  11. import com.kingdee.bos.ctrl.swing.StringUtils;
  12. import com.kingdee.bos.dao.IObjectPK;
  13. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  14. import com.kingdee.bos.metadata.entity.EntityViewInfo;
  15. import com.kingdee.bos.metadata.entity.FilterInfo;
  16. import com.kingdee.bos.metadata.entity.FilterItemInfo;
  17. import com.kingdee.bos.metadata.entity.SelectorItemCollection;
  18. import com.kingdee.bos.metadata.query.util.CompareType;
  19. import com.kingdee.bos.util.BOSUuid;
  20. import com.kingdee.eas.basedata.person.IPerson;
  21. import com.kingdee.eas.basedata.person.PersonFactory;
  22. import com.kingdee.eas.basedata.person.PersonInfo;
  23. import com.kingdee.eas.common.EASBizException;
  24. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
  25. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
  26. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  27. import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
  28. import com.kingdee.eas.util.app.DbUtil;
  29. import com.kingdee.jdbc.rowset.IRowSet;
  30. import com.kingdee.shr.compensation.TaxDeclareStatusEnum;
  31. import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordFactory;
  32. import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordInfo;
  33. import com.kingdee.shr.compensation.app.tax.*;
  34. import com.kingdee.shr.compensation.app.tax.base.ITaxIncomeItem;
  35. import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemFactory;
  36. import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo;
  37. import com.kingdee.shr.compensation.app.taxCal.ITaxCalConfigDetail;
  38. import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailCollection;
  39. import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailFactory;
  40. import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailInfo;
  41. import org.apache.log4j.Logger;
  42. import java.io.IOException;
  43. import java.math.BigDecimal;
  44. import java.sql.SQLException;
  45. import java.util.*;
  46. /**
  47. * @author qingwu
  48. * @date 2024/9/19
  49. * @apiNote
  50. */
  51. public class SynIncomeTaxDeclareService implements IHRMsfService {
  52. Logger logger = Logger.getLogger("com.kingdee.eas.custom.compensation.service.SynIncomeTaxDeclareService");
  53. public Object process(Context context, Map map) throws EASBizException, BOSException {
  54. //接口日志实体
  55. LogInfoInfo logInfo = new LogInfoInfo();
  56. //入口
  57. logInfo.setEntrance(this.getClass().getName());
  58. logInfo.setBizDate(new Date());
  59. Map resMap = new HashMap();
  60. logger.error("SynIncomeTaxDeclareService----------OSF----Start");
  61. JSONObject paramData = JSONObject.parseObject((String) map.get("paramData"));
  62. logger.error("paramData--------" + paramData);
  63. String requestId = paramData.getString("requestId");
  64. JSONObject param = paramData.getJSONObject("param");
  65. logger.error("requestId--------" + requestId);
  66. logger.error("param--------" + param);
  67. ObjectMapper mapper = new ObjectMapper();
  68. try {
  69. //客户端代理工厂
  70. ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
  71. //算税请求接口
  72. DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest();
  73. //申报数据反馈 requestId:请求Id reportType:申报所得类型[1:综合所得;2:分类所得;3:非居民所得;4:限售股所得]
  74. ApiResponse<Feedback> feedback = declarationRequest.getFeedback(requestId, "1");
  75. logInfo.setInterfaceAddress("/gateway/iit/report/getFeedback");//接口地址
  76. logInfo.setInterfaceName("getFeedback");//接口名
  77. logger.error("feedback--------" + mapper.writeValueAsString(feedback));
  78. String status = feedback.getHead().getStatus();
  79. Feedback body = null;
  80. if ("N".equals(status)) {
  81. //请求失败响应
  82. String msg = feedback.getHead().getMsg();
  83. //throw new BOSException(msg);
  84. logInfo.setStatus("处理中");
  85. return MessageResult.FAILED(msg);
  86. } else {
  87. //调用成功
  88. //请求id
  89. body = feedback.getBody();
  90. logInfo.setOutParameter(mapper.writeValueAsString(body));//回参
  91. if (body.getDeclarationStateCode().equals("6") || body.getDeclarationStateCode().equals("5")) {
  92. saveTaxDeclaration(context, param);
  93. }
  94. logInfo.setStatus("成功");
  95. }
  96. LogInfoFactory.getLocalInstance(context).addnew(logInfo);
  97. return MessageResult.SUCCESS(mapper.writeValueAsString(body));
  98. } catch (IOException e) {
  99. e.printStackTrace();
  100. logInfo.setErrorInfo(e.getMessage());//错误信息
  101. logInfo.setStatus("失败");
  102. LogInfoFactory.getLocalInstance(context).save(logInfo);
  103. //throw new BOSException(e);
  104. return MessageResult.ERROR(e.getMessage());
  105. }
  106. }
  107. /**
  108. * 保存个税申报结果
  109. *
  110. * @param param
  111. */
  112. public void saveTaxDeclaration(Context ctx, JSONObject param) throws BOSException, EASBizException {
  113. logger.error("saveTaxDeclaration------------------");
  114. //个税申报ID
  115. //String taxDeclarId = param.getString("taxDeclarId");
  116. //个税申报批次号
  117. String taxDeclarBatchNo = param.getString("taxDeclarBatchNo");
  118. IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx);
  119. IncomeTaxDeclarCollection incomeTaxDeclarCollection = iIncomeTaxDeclar.getIncomeTaxDeclarCollection("where batchNo = '" + taxDeclarBatchNo + "'");
  120. SelectorItemCollection updateSic = new SelectorItemCollection();
  121. updateSic.add("declareStatus");
  122. if (incomeTaxDeclarCollection.size() > 0) {
  123. IncomeTaxDeclarInfo incomeTaxDeclarInfo = incomeTaxDeclarCollection.get(0);
  124. incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_SUCCESS);
  125. iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic);
  126. }
  127. ////个税应用+税款计算最终拆分明细表
  128. //ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
  129. //TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + taxDeclarBatchNo + "' and state = '20'");
  130. //for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) {
  131. // TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i);
  132. // //员工信息
  133. // PersonInfo person = taxCalConfigDetailInfo.getPerson();
  134. //}
  135. try {
  136. //个税申报表
  137. ITaxDeclaration iTaxDeclaration = TaxDeclarationFactory.getLocalInstance(ctx);
  138. //个税项目
  139. ITaxIncomeItem iTaxIncomeItem = TaxIncomeItemFactory.getLocalInstance(ctx);
  140. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  141. List<Map<String, Object>> taxDeclarationDate = getTaxDeclarationDate(ctx, taxDeclarBatchNo);
  142. for (int i = 0; i < taxDeclarationDate.size(); i++) {
  143. Map<String, Object> map = taxDeclarationDate.get(i);
  144. TaxIncomeItemInfo taxIncomeItemInfo = iTaxIncomeItem.getTaxIncomeItemCollection("where id = '" + map.get("incomeitmemId") + "'").get(0);
  145. logger.error("taxIncomeItemInfo------------------" + taxIncomeItemInfo);
  146. FilterInfo filterInfo = new FilterInfo();
  147. filterInfo.getFilterItems().add(new FilterItemInfo("person", map.get("personId"), CompareType.EQUALS));
  148. filterInfo.getFilterItems().add(new FilterItemInfo("taxUnit", map.get("taxunitId"), CompareType.EQUALS));
  149. filterInfo.getFilterItems().add(new FilterItemInfo("taxPeriodBegin", map.get("periodbegin"), CompareType.EQUALS));
  150. filterInfo.getFilterItems().add(new FilterItemInfo("taxPeriodEnd", map.get("periodend"), CompareType.EQUALS));
  151. filterInfo.getFilterItems().add(new FilterItemInfo("proceedItem", taxIncomeItemInfo.getName(), CompareType.EQUALS));
  152. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  153. TaxDeclarationCollection taxDeclarationCollection = iTaxDeclaration.getTaxDeclarationCollection(entityViewInfo);
  154. logger.error("taxDeclarationCollection.size------------------" + taxDeclarationCollection.size());
  155. if (taxDeclarationCollection.size() <= 0) {
  156. TaxDeclarationInfo taxDeclarationInfo = new TaxDeclarationInfo();
  157. //员工
  158. PersonInfo personInfo = iPerson.getPersonInfo(new ObjectUuidPK((String) map.get("personId")));
  159. taxDeclarationInfo.setPerson(personInfo);
  160. //证件号
  161. taxDeclarationInfo.setIdNO(personInfo.getIdCardNO());
  162. //证件类型
  163. TaxPersonRecordInfo taxPersonRecordInfo = TaxPersonRecordFactory.getLocalInstance(ctx).getTaxPersonRecordCollection("where person = '" + personInfo.getId() + "'").get(0);
  164. String alias = taxPersonRecordInfo.getCardType().getAlias();
  165. taxDeclarationInfo.setIdType(alias);
  166. //纳税单位
  167. TaxUnitInfo taxUnitInfo = new TaxUnitInfo();
  168. taxUnitInfo.setId(BOSUuid.read((String) map.get("taxunitId")));
  169. taxDeclarationInfo.setTaxUnit(taxUnitInfo);
  170. //税款所属期间起始时间
  171. taxDeclarationInfo.setTaxPeriodBegin((Date) map.get("periodbegin"));
  172. //税款所属期间截止时间
  173. taxDeclarationInfo.setTaxPeriodEnd((Date) map.get("periodend"));
  174. //个税项目
  175. taxDeclarationInfo.setProceedItem(taxIncomeItemInfo.getName());
  176. taxDeclarationInfo.setCost((BigDecimal) map.get("t25"));//费用
  177. taxDeclarationInfo.setIncome((BigDecimal) map.get(" t1"));//收入
  178. taxDeclarationInfo.setExemptIncome((BigDecimal) map.get("t2"));//免税收入
  179. taxDeclarationInfo.setBasicPension((BigDecimal) map.get("t3"));//基本养老保险费
  180. taxDeclarationInfo.setBasicMedical((BigDecimal) map.get("t4"));//基本医疗保险费
  181. taxDeclarationInfo.setUnemployment((BigDecimal) map.get("t5"));//失业保险费
  182. taxDeclarationInfo.setHousingFund((BigDecimal) map.get("t6"));//住房公积金
  183. taxDeclarationInfo.setChildEducateSum((BigDecimal) map.get("t7"));//累计子女教育
  184. taxDeclarationInfo.setContinueEducateSum((BigDecimal) map.get("t8"));//累计继续教育
  185. taxDeclarationInfo.setLoanInterestSum((BigDecimal) map.get("t9"));//累计住房贷款利息
  186. taxDeclarationInfo.setHousingRentSum((BigDecimal) map.get("t10"));//累计住房租金
  187. taxDeclarationInfo.setOldSupportSum((BigDecimal) map.get("t11"));//累计赡养老人
  188. taxDeclarationInfo.setIncomeSum((BigDecimal) map.get("t20"));//累计收入额
  189. taxDeclarationInfo.setDeductionSum((BigDecimal) map.get("t24"));//累计减除费用
  190. taxDeclarationInfo.setSpecialDeductSum((BigDecimal) map.get("t26"));//累计专项扣除
  191. taxDeclarationInfo.setOtherDeductionSum((BigDecimal) map.get("t28"));//累计其他扣除
  192. taxDeclarationInfo.setAllowDonationSum((BigDecimal) map.get("t29"));//累计准予扣除的捐赠
  193. taxDeclarationInfo.setTaxableIncomeSum((BigDecimal) map.get("t30"));//累计应纳税所得额
  194. taxDeclarationInfo.setTaxRatio((BigDecimal) map.get("t31"));//税率
  195. taxDeclarationInfo.setQuickDeduct((BigDecimal) map.get("t32"));//速算扣除数
  196. taxDeclarationInfo.setTaxPayableSum((BigDecimal) map.get("t33"));//累计应纳税额
  197. taxDeclarationInfo.setTaxCreditSum((BigDecimal) map.get("t34"));//累计减免税额
  198. taxDeclarationInfo.setTaxSupOrRefund((BigDecimal) map.get("t38"));//应补/退税额
  199. taxDeclarationInfo.setInFantSum((BigDecimal) map.get("t45"));//累计婴幼儿照护费用
  200. taxDeclarationInfo.setPersonalPension((BigDecimal) map.get("t46"));//累计个人养老金
  201. logger.error("taxDeclarationInfo------------------" + taxDeclarationInfo);
  202. IObjectPK save = iTaxDeclaration.save(taxDeclarationInfo);
  203. logger.error("taxDeclarationInfo----------save--------" + save);
  204. }
  205. }
  206. } catch (SQLException e) {
  207. e.printStackTrace();
  208. throw new RuntimeException(e);
  209. } catch (EASBizException e) {
  210. throw new RuntimeException(e);
  211. }
  212. }
  213. /***
  214. * 封装个税申报数据
  215. * @param batchNo
  216. * @return
  217. */
  218. public List<Map<String, Object>> getTaxDeclarationDate(Context ctx, String batchNo) throws BOSException, SQLException {
  219. List list = new ArrayList();
  220. String sql = getSql(batchNo);
  221. logger.error("getTaxDeclarationDate------sql--------" + sql);
  222. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  223. while (iRowSet.next()) {
  224. Map map = new HashMap();
  225. map.put("personId", iRowSet.getString("personId"));//员工Id
  226. map.put("taxunitId", iRowSet.getString("taxunitId"));//纳税单位Id
  227. map.put("periodbegin", iRowSet.getDate("periodbegin"));//税款所属期间起始时间
  228. map.put("periodend", iRowSet.getDate("periodend"));//税款所属期间截止时间
  229. map.put("incomeitmemId", iRowSet.getString("incomeitmemId"));//个税项目Id
  230. logger.error("getTaxDeclarationDate------iRowSet.getBigDecimal(t1)--------" + iRowSet.getBigDecimal("t1"));
  231. map.put("t1", iRowSet.getBigDecimal("t1") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t1"));//本期免税收入
  232. map.put("t2", iRowSet.getBigDecimal("t2") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t2"));//基本养老保险费
  233. map.put("t3", iRowSet.getBigDecimal("t3") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t3"));//基本医疗保险费
  234. map.put("t4", iRowSet.getBigDecimal("t4") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t4"));//失业保险费
  235. map.put("t5", iRowSet.getBigDecimal("t5") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t5"));//住房公积金
  236. map.put("t6", iRowSet.getBigDecimal("t6") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t6"));//累计子女教育
  237. map.put("t7", iRowSet.getBigDecimal("t7") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t7"));//累计继续教育
  238. map.put("t8", iRowSet.getBigDecimal("t8") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t8"));//累计住房贷款利息
  239. map.put("t9", iRowSet.getBigDecimal("t9") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t9"));//累计住房租金
  240. map.put("t10", iRowSet.getBigDecimal("t10") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t10"));//累计赡养老人
  241. map.put("t25", iRowSet.getBigDecimal("t25") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t25"));//本期收入
  242. map.put("t11", iRowSet.getBigDecimal("t11") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t11"));//其他
  243. map.put("t15", iRowSet.getBigDecimal("t15") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t15"));//本期累计收入
  244. map.put("t20", iRowSet.getBigDecimal("t20") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t20"));//本期累计免税收入
  245. map.put("t22", iRowSet.getBigDecimal("t22") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t22"));//累计减除费用
  246. map.put("t24", iRowSet.getBigDecimal("t24") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t24"));//累计专项扣除
  247. map.put("t26", iRowSet.getBigDecimal("t26") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t26"));//累计其他扣除
  248. map.put("t28", iRowSet.getBigDecimal("t28") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t28"));//累计准予扣除的捐赠
  249. map.put("t29", iRowSet.getBigDecimal("t29") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t29"));//累计应纳税所得额
  250. map.put("t30", iRowSet.getBigDecimal("t30") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t30"));//税率
  251. map.put("t31", iRowSet.getBigDecimal("t31") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t31"));//速算扣除数
  252. map.put("t32", iRowSet.getBigDecimal("t32") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t32"));//累计应纳税额
  253. map.put("t33", iRowSet.getBigDecimal("t33") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t33"));//累计减免税额
  254. map.put("t34", iRowSet.getBigDecimal("t34") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t34"));//累计应扣缴税额
  255. map.put("t35", iRowSet.getBigDecimal("t35") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t35"));//累计已预缴税额
  256. map.put("t36", iRowSet.getBigDecimal("t36") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t36"));//本期应补(退)税额
  257. map.put("t38", iRowSet.getBigDecimal("t38") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t38"));//备注
  258. map.put("t41", iRowSet.getBigDecimal("t41") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t41"));//累计婴幼儿照护费用
  259. map.put("t45", iRowSet.getBigDecimal("t45") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t45"));//累计个人养老金
  260. list.add(map);
  261. }
  262. return list;
  263. }
  264. /**
  265. * 查询个税申报人员数据
  266. *
  267. * @param batchNo
  268. * @return
  269. */
  270. public String getSql(String batchNo) {
  271. StringBuilder sb = new StringBuilder();
  272. sb.append("select").append("\n");
  273. sb.append(" taxCalConfigDetail.FPERSONID as personId,").append("\n");
  274. sb.append(" taxCalConfigDetail.FTAXUNITID as taxunitId,").append("\n");
  275. sb.append("taxCalConfigDetail.FPERIODBEGIN as periodbegin,\n").append("\n");
  276. sb.append("taxCalConfigDetail.FPERIODEND as periodend,\n").append("\n");
  277. sb.append("taxCalConfigDetail.FINCOMEITEMID as incomeitmemId,\n").append("\n");
  278. sb.append(" t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t15,t20,t22,t24,t25,t26,t28,t29,t30,t31,t32,t33,t34,t35,t36,t38,t41,t45,t46\n").append("\n");
  279. sb.append(" from T_HR_STaxCalConfigDetail taxCalConfigDetail\n").append("\n");
  280. sb.append("where").append("\n");
  281. sb.append("FBATCHNO = '").append(batchNo).append("'").append("\n");
  282. return sb.toString();
  283. }
  284. }