SynIndividualIncomeTaxService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package com.kingdee.eas.custom.compensation.service;
  2. import cn.com.servyou.dto.ApiResponse;
  3. import cn.com.servyou.dto.tax.CalculateTaxResultRequest;
  4. import cn.com.servyou.dto.tax.ComplexIncome;
  5. import cn.com.servyou.dto.tax.ComplexIncomeResultRequest;
  6. import cn.com.servyou.dto.tax.ComplexTaxCalculateResult;
  7. import cn.com.servyou.rmi.client.ClientProxyFactory;
  8. import cn.com.servyou.service.TaxRequest;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  11. import com.fasterxml.jackson.core.JsonProcessingException;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import com.kingdee.bos.BOSException;
  14. import com.kingdee.bos.Context;
  15. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  16. import com.kingdee.bos.dao.IObjectPK;
  17. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  18. import com.kingdee.bos.metadata.entity.EntityViewInfo;
  19. import com.kingdee.bos.metadata.entity.FilterInfo;
  20. import com.kingdee.bos.metadata.entity.FilterItemInfo;
  21. import com.kingdee.bos.metadata.query.util.CompareType;
  22. import com.kingdee.eas.basedata.person.IPerson;
  23. import com.kingdee.eas.basedata.person.PersonCollection;
  24. import com.kingdee.eas.basedata.person.PersonFactory;
  25. import com.kingdee.eas.basedata.person.PersonInfo;
  26. import com.kingdee.eas.common.EASBizException;
  27. import com.kingdee.eas.custom.individualback.*;
  28. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
  29. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
  30. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  31. import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
  32. import com.kingdee.eas.util.app.DbUtil;
  33. import com.kingdee.jdbc.rowset.IRowSet;
  34. import com.kingdee.shr.compensation.CalSchemeFactory;
  35. import com.kingdee.util.StringUtils;
  36. import org.apache.log4j.Logger;
  37. import java.io.IOException;
  38. import java.math.BigDecimal;
  39. import java.sql.SQLException;
  40. import java.util.Date;
  41. import java.util.HashMap;
  42. import java.util.List;
  43. import java.util.Map;
  44. /**
  45. * @author qingwu
  46. * @date 2024/9/9
  47. * @apiNote
  48. */
  49. public class SynIndividualIncomeTaxService implements IHRMsfService {
  50. Logger logger = Logger.getLogger("com.kingdee.eas.custom.compensation.service.SynIndividualIncomeTaxService");
  51. @Override
  52. public Object process(Context context, Map map) throws EASBizException, BOSException {
  53. //接口日志实体
  54. LogInfoInfo logInfo = new LogInfoInfo();
  55. //入口
  56. logInfo.setEntrance(this.getClass().getName());
  57. logInfo.setBizDate(new Date());
  58. Map resMap = new HashMap();
  59. logger.error("SynIndividualIncomeTaxService----------OSF----Start");
  60. JSONObject paramData = JSONObject.parseObject((String) map.get("paramData"));
  61. logger.error("paramData--------" + paramData);
  62. String requestId = paramData.getString("requestId");
  63. JSONObject param = paramData.getJSONObject("param");
  64. logger.error("requestId--------" + requestId);
  65. logger.error("param--------" + param);
  66. try {
  67. ObjectMapper mapper = new ObjectMapper();
  68. //客户端代理工厂
  69. ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
  70. //算税请求接口
  71. TaxRequest taxRequest = clientProxyFactory.getTaxRequest();
  72. ApiResponse<CalculateTaxResultRequest> aSynIndividualIncomeTaxFeedback = taxRequest.getReverseASynIndividualIncomeTaxFeedback(requestId);
  73. logger.error("aSynIndividualIncomeTaxFeedback--------" + mapper.writeValueAsString(aSynIndividualIncomeTaxFeedback));
  74. String status = aSynIndividualIncomeTaxFeedback.getHead().getStatus();
  75. logInfo.setInterfaceAddress("/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback");//接口地址
  76. logInfo.setInterfaceName("getASynIndividualIncomeTaxFeedback");//接口名
  77. logInfo.setInParameter(mapper.writeValueAsString(aSynIndividualIncomeTaxFeedback));//入参
  78. CalculateTaxResultRequest body = null;
  79. if ("N".equals(status)) {
  80. //请求失败响应
  81. String msg = aSynIndividualIncomeTaxFeedback.getHead().getMsg();
  82. logInfo.setStatus("处理中");
  83. //throw new BOSException(msg);
  84. return MessageResult.FAILED(msg);
  85. } else {
  86. //调用成功
  87. //请求id
  88. body = aSynIndividualIncomeTaxFeedback.getBody();
  89. logger.error("SynIndividualIncomeTaxService----------body---" + mapper.writeValueAsString(body));
  90. logInfo.setOutParameter(mapper.writeValueAsString(body));//回参
  91. //if (body.getEmployeeDeclareFeedbackList() != null) {
  92. logInfo.setStatus("成功");
  93. disposeTaxPaymentBackCalculate(context, body, param);
  94. //} else {
  95. // logInfo.setStatus("人员报错");
  96. //}
  97. }
  98. LogInfoFactory.getLocalInstance(context).addnew(logInfo);
  99. return MessageResult.SUCCESS(mapper.writeValueAsString(body));
  100. } catch (IOException e) {
  101. e.printStackTrace();
  102. logInfo.setErrorInfo(e.getMessage());//错误信息
  103. logInfo.setStatus("失败");
  104. LogInfoFactory.getLocalInstance(context).save(logInfo);
  105. logger.error("SynIndividualIncomeTaxService----------error---" + e.getMessage());
  106. //throw new BOSException(e);
  107. return MessageResult.ERROR(e.getMessage());
  108. }
  109. }
  110. /**
  111. * 处理个税反算数据
  112. *
  113. * @param resBody 查询反算反馈结果接口返回结果
  114. * @param param 员工ID
  115. * @return
  116. */
  117. public void disposeTaxPaymentBackCalculate(Context ctx, CalculateTaxResultRequest
  118. resBody, com.alibaba.fastjson.JSONObject param) throws BOSException, EASBizException, JsonProcessingException {
  119. logger.error("addTaxPaymentBackCalculate============Start===============");
  120. ObjectMapper mapper = new ObjectMapper();
  121. ITaxPaymentBackCalculate iTaxPaymentBackCalculate = TaxPaymentBackCalculateFactory.getLocalInstance(ctx);
  122. String taxItemPlanNumber = param.getString("taxItemPlanNumber");//个税项目方案
  123. logger.error("taxItemPlanNumber============" + taxItemPlanNumber);
  124. ComplexTaxCalculateResult complexTaxCalculateResult = null;
  125. //zhsd 综合所得
  126. ComplexIncomeResultRequest complexIncomeResultRequest = resBody.getComplexIncomeResultRequest();
  127. logger.error("complexIncomeResultRequest============" + mapper.writeValueAsString(complexIncomeResultRequest));
  128. //全年一次性奖金
  129. //if ("2024083001".equals(taxItemPlanNumber)) {
  130. if ("GS003".equals(taxItemPlanNumber)) {
  131. //qnycxjjsslb 全年一次性奖金
  132. complexTaxCalculateResult = complexIncomeResultRequest.getAnnualOneTimeBonusIncome();
  133. }
  134. //一般劳务报酬所得列表
  135. if ("GS002".equals(taxItemPlanNumber)) {
  136. //lwbclb 一般劳务报酬所得列表
  137. complexTaxCalculateResult = complexIncomeResultRequest.getLaborRemunerationIncome();
  138. }
  139. //正常工资薪金对象
  140. if ("GS001".equals(taxItemPlanNumber)) {
  141. //zcgzxj 正常工资薪金对象
  142. complexTaxCalculateResult = complexIncomeResultRequest.getNormalSalarySpecIncome();
  143. }
  144. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  145. List<ComplexIncome> successComplexIncomes = complexTaxCalculateResult.getSuccessComplexIncomes();
  146. for (ComplexIncome complexIncome : successComplexIncomes) {
  147. //证件类型
  148. String licenseType = complexIncome.getLicenseType();
  149. PersonInfo personInfo = null;
  150. if ("居民身份证".equals(licenseType)) {
  151. //证件号码
  152. String licenseNumber = complexIncome.getLicenseNumber();
  153. PersonCollection personCollection = iPerson.getPersonCollection("where idCardNO = '" + licenseNumber + "'");
  154. if (personCollection.size() > 0) {
  155. personInfo = personCollection.get(0);
  156. }
  157. }
  158. if ("中国护照".equals(licenseType)) {
  159. //证件号码
  160. String licenseNumber = complexIncome.getLicenseNumber();
  161. PersonCollection personCollection = iPerson.getPersonCollection("where passportNO = '" + licenseNumber + "'");
  162. if (personCollection.size() > 0) {
  163. personInfo = personCollection.get(0);
  164. }
  165. }
  166. param.put("personId", personInfo.getId());
  167. saveTaxPaymentBackCalculateCollection(ctx, param, complexIncome);
  168. }
  169. logger.error("addTaxPaymentBackCalculate============end===============");
  170. }
  171. public String getParamContent(String requestId) {
  172. return "select CFParamContent as paramContent from CT_TK_TaskRequestParam where CFTaskID in (select FID from CT_TK_Task where CFRequestId = '" + requestId + "')";
  173. }
  174. public TaxPaymentBackCalculateCollection saveTaxPaymentBackCalculateCollection(Context ctx, JSONObject
  175. param, ComplexIncome complexIncome) throws BOSException, EASBizException {
  176. TaxPaymentBackCalculateInfo taxPaymentBackCalculateInfo = new TaxPaymentBackCalculateInfo();
  177. String personId = param.getString("personId");//员工ID
  178. String periodYear = param.getString("periodYear");//统计年
  179. String periodMonth = param.getString("periodMonth");//统计月
  180. String cmpschemeid = param.getString("cmpschemeid");//计算规则ID
  181. String taxItemPlanName = param.getString("taxItemPlanName");//个税项目方案
  182. String taxItemPlanNumber = param.getString("taxItemPlanNumber");//个税项目方案
  183. FilterInfo filterInfo = new FilterInfo();
  184. filterInfo.getFilterItems().add(new FilterItemInfo("person", personId, CompareType.EQUALS));
  185. filterInfo.getFilterItems().add(new FilterItemInfo("periodMonth", periodMonth, CompareType.EQUALS));
  186. filterInfo.getFilterItems().add(new FilterItemInfo("periodYear", periodYear, CompareType.EQUALS));
  187. filterInfo.getFilterItems().add(new FilterItemInfo("cmpscheme", cmpschemeid, CompareType.EQUALS));
  188. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  189. ////查询税款反算表是否存在该数据
  190. ITaxPaymentBackCalculate iTaxPaymentBackCalculate = TaxPaymentBackCalculateFactory.getLocalInstance(ctx);
  191. TaxPaymentBackCalculateCollection taxPaymentBackCalculateCollection = iTaxPaymentBackCalculate.getTaxPaymentBackCalculateCollection(entityViewInfo);
  192. if (taxPaymentBackCalculateCollection.size() > 0) {
  193. taxPaymentBackCalculateInfo = taxPaymentBackCalculateCollection.get(0);
  194. taxPaymentBackCalculateInfo.setId(taxPaymentBackCalculateCollection.get(0).getId());
  195. }
  196. //员工
  197. taxPaymentBackCalculateInfo.setPerson(PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(personId)));
  198. //统计年
  199. taxPaymentBackCalculateInfo.setPeriodYear(periodYear);
  200. //统计月
  201. taxPaymentBackCalculateInfo.setPeriodMonth(periodMonth);
  202. //计算规则
  203. taxPaymentBackCalculateInfo.setCmpscheme(CalSchemeFactory.getLocalInstance(ctx).getCalSchemeInfo(new ObjectUuidPK(cmpschemeid)));
  204. //个税项目方案
  205. taxPaymentBackCalculateInfo.setTaxItemPlan(taxItemPlanName);
  206. //sre 收入额
  207. BigDecimal income = complexIncome.getIncome();
  208. taxPaymentBackCalculateInfo.setSalarySum(income);
  209. //ybtse refundTax 应补退税额
  210. BigDecimal refundTax = complexIncome.getRefundTax();
  211. taxPaymentBackCalculateInfo.setIndividual(refundTax);
  212. IObjectPK save = iTaxPaymentBackCalculate.save(taxPaymentBackCalculateInfo);
  213. logger.error("saveTaxPaymentBackCalculateCollection----------save---" + save);
  214. return taxPaymentBackCalculateCollection;
  215. }
  216. }