GetASynIndividualIncomeTaxFeedback.java 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. package com.kingdee.eas.custom.shuiyou.taxCal.service;
  2. import cn.com.servyou.dto.ApiResponse;
  3. import cn.com.servyou.dto.Head;
  4. import cn.com.servyou.dto.tax.*;
  5. import cn.com.servyou.rmi.client.ClientProxyFactory;
  6. import cn.com.servyou.service.TaxRequest;
  7. import com.fasterxml.jackson.core.JsonProcessingException;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.kingdee.bos.BOSException;
  10. import com.kingdee.bos.Context;
  11. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  12. import com.kingdee.bos.metadata.entity.*;
  13. import com.kingdee.bos.metadata.query.util.CompareType;
  14. import com.kingdee.eas.common.EASBizException;
  15. import com.kingdee.eas.custom.shuiyou.interfacelog.ILogInfo;
  16. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
  17. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
  18. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  19. import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
  20. import com.kingdee.eas.hr.ats.AtsUtil;
  21. import com.kingdee.eas.hr.ats.util.AtsDateUtils;
  22. import com.kingdee.eas.util.app.DbUtil;
  23. import com.kingdee.jdbc.rowset.IRowSet;
  24. import com.kingdee.shr.compensation.CardTypeEnum;
  25. import com.kingdee.shr.compensation.app.incomeTax.*;
  26. import com.kingdee.shr.compensation.app.tax.base.*;
  27. import com.kingdee.shr.compensation.app.taxCal.*;
  28. import com.kingdee.util.StringUtils;
  29. import org.apache.log4j.Logger;
  30. import java.math.BigDecimal;
  31. import java.sql.SQLException;
  32. import java.text.ParseException;
  33. import java.text.SimpleDateFormat;
  34. import java.util.*;
  35. /**
  36. * @Description 获取异步算税反馈结果
  37. * @Date 2024/9/10 15:26
  38. * @Created by Heyuan
  39. */
  40. public class GetASynIndividualIncomeTaxFeedback implements IHRMsfService {
  41. private static Logger logger = Logger.getLogger(GetASynIndividualIncomeTaxFeedback.class);
  42. private String taxUnitId = null;//纳税单位id
  43. private String period = null;//税款所属期 yyyy-MM
  44. private String creator = null;//创建人id
  45. private String periodBegin = null;//税款所属期起 yyyy-MM-dd
  46. private String periodEnd = null;//税款所属期止 yyyy-MM-dd
  47. private ObjectMapper objectMapper = new ObjectMapper();
  48. //证件类型map
  49. //private static Map<String, String> cardTypeEnumMap = null;
  50. private Map<String, String> incomeItemMap = null;//所有启用的所得项目
  51. private Map<String, String> taxItemInitMap = null;//初算个税项目
  52. private Map<String, String> taxItemConfigMap = null;//明细个税项目
  53. private Map<String, String> taxPersonRecordMap = null;//报送人员信息 key:证件号码+证件类型,value:员工id
  54. @Override
  55. public MessageResult process(Context ctx, Map paramMap) throws EASBizException, BOSException {
  56. ILogInfo iLogInfo = LogInfoFactory.getLocalInstance(ctx);
  57. //接口日志实体
  58. LogInfoInfo logInfo = new LogInfoInfo();
  59. //入口
  60. logInfo.setEntrance(this.getClass().getName());
  61. logInfo.setBizDate(new Date());
  62. try {
  63. logger.info("调用 GetASynIndividualIncomeTaxFeedback, 参数 " + objectMapper.writeValueAsString(paramMap));
  64. MessageResult messageResult = null;
  65. String this_taskId = (String) paramMap.get("this_taskId");//任务id
  66. String paramData = (String) paramMap.get("paramData");
  67. Map<String, String> paramDataMap = objectMapper.readValue(paramData, Map.class);
  68. taxUnitId = paramDataMap.get("TAXUNITID");//纳税单位id
  69. period = paramDataMap.get("PERIOD");//周期yyyy-MM
  70. creator = paramDataMap.get("creator");//创建人id
  71. String requestId = paramDataMap.get("requestId");
  72. StringBuilder errorMsg = new StringBuilder();
  73. if (StringUtils.isEmpty(taxUnitId)) {
  74. errorMsg.append("纳税单位id不能为空!\n");
  75. }
  76. if (StringUtils.isEmpty(period)) {
  77. errorMsg.append("周期yyyy-MM不能为空!\n");
  78. }
  79. if (StringUtils.isEmpty(requestId)) {
  80. errorMsg.append("requestId不能为空!\n");
  81. }
  82. if (errorMsg.length() > 0) {
  83. throw new BOSException(errorMsg.toString());
  84. }
  85. SimpleDateFormat shortsdf = new SimpleDateFormat("yyyy-MM");
  86. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  87. Date parse = shortsdf.parse(period);
  88. periodBegin = sdf.format(AtsDateUtils.getMonthFirstDay(parse));
  89. periodEnd = sdf.format(AtsDateUtils.getMonthLastDay(parse));
  90. //客户端代理工厂
  91. ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
  92. logInfo.setInterfaceAddress("/gateway/iit/calculateTax/getASynIndividualIncomeTaxFeedback");//接口地址
  93. logInfo.setInterfaceName("getASynIndividualIncomeTaxFeedback");//接口名
  94. logInfo.setInParameter("{\"requestId\":\"" + requestId + "\"}");//入参
  95. //算税请求接口
  96. TaxRequest taxRequest = clientProxyFactory.getTaxRequest();
  97. //调用异步算税接口
  98. ApiResponse<CalculateTaxResultRequest> apiResponse = taxRequest.getASynIndividualIncomeTaxFeedback(requestId);
  99. ObjectMapper mapper = new ObjectMapper();
  100. logInfo.setOutParameter(mapper.writeValueAsString(apiResponse));//回参
  101. Head head = apiResponse.getHead();
  102. String status = head.getStatus();
  103. String code = head.getCode();
  104. if ("100004".equals(code)) {
  105. //请求处理中
  106. messageResult = MessageResult.AGAIN(head.getMsg());
  107. logInfo.setErrorInfo(head.getMsg());//错误信息
  108. logInfo.setStatus("处理中");
  109. } else if ("000004".equals(code)) {
  110. //请求失败
  111. messageResult = MessageResult.FAILED(head.getMsg());
  112. logInfo.setErrorInfo(head.getMsg());//错误信息
  113. logInfo.setStatus("失败");
  114. } else if ("00000000".equals(code)) {
  115. logger.info("成功");
  116. //获取所有启用的所得项目
  117. incomeItemMap = getIncomeItemMap(ctx);
  118. logger.info("objectMapper.writeValueAsString(incomeItemMap) " + objectMapper.writeValueAsString(incomeItemMap));
  119. //获取个税项目
  120. getTaxItemMap(ctx);
  121. logger.info("objectMapper.writeValueAsString(taxItemInitMap) " + objectMapper.writeValueAsString(taxItemInitMap));
  122. logger.info("objectMapper.writeValueAsString(taxItemConfigMap) " + objectMapper.writeValueAsString(taxItemConfigMap));
  123. //获取报送人员信息
  124. getTaxPersonRecordMap(ctx);
  125. logger.info("objectMapper.writeValueAsString(taxPersonRecordMap) " + objectMapper.writeValueAsString(taxPersonRecordMap));
  126. //请求成功
  127. CalculateTaxResultRequest body = apiResponse.getBody();
  128. //企业名称
  129. // String qymc = body.getName();
  130. // //税号
  131. // String nsrsbh = body.getTaxNo();
  132. // //部门编号
  133. // String bmbh = body.getDeptNo();
  134. // //部门名称
  135. // String bmmc = body.getDeptName();
  136. // //行政区划代码
  137. // String areaid = body.getArea();
  138. // //税款所属期
  139. // String skssq = body.getMonth();
  140. // //外部业务订单号
  141. // String bizNo = body.getBizNo();
  142. //综合所得
  143. ComplexIncomeResultRequest complexIncomeResult = body.getComplexIncomeResultRequest();
  144. //人员申报失败列表
  145. // List<EmployeeDeclareFeedback> employeeDeclareFeedbacks = complexIncomeResult.getEmployeeDeclareFeedbacks();
  146. // for (int i = 0; employeeDeclareFeedbacks != null && i < employeeDeclareFeedbacks.size(); i++) {
  147. // EmployeeDeclareFeedback employeeDeclareFeedback = employeeDeclareFeedbacks.get(i);
  148. // //姓名
  149. // String name = employeeDeclareFeedback.getName();
  150. // //证件类型名称
  151. // String licenseType = employeeDeclareFeedback.getLicenseType();
  152. // //证件号码
  153. // String licenseNumber = employeeDeclareFeedback.getLicenseNumber();
  154. // //报送状态 1 待报送 2 代报中 3 代报失败 4 代报成功
  155. // String submissionState = employeeDeclareFeedback.getSubmissionState();
  156. // //人员验证状态 0 若是身份证,状态为验证中;其他证件为暂不验证 1 验证通过 2 验证不通过 4 待验证 9 同代码0处理
  157. // String authenticationState = employeeDeclareFeedback.getAuthenticationState();
  158. // //失败原因
  159. // String message = employeeDeclareFeedback.getMessage();
  160. // //专项报送状态 2 代报成功 3 代报失败
  161. // String deductionSubmissionState = employeeDeclareFeedback.getDeductionSubmissionState();
  162. // //专项报送结果原因
  163. // String deductionMessage = employeeDeclareFeedback.getDeductionMessage();
  164. // }
  165. logger.info("正常工资薪金算税结果对象");
  166. //正常工资薪金算税结果对象
  167. ComplexTaxCalculateResult normalSalarySpecIncome = complexIncomeResult.getNormalSalarySpecIncome();
  168. handleComplexTaxCalculateResult(ctx, normalSalarySpecIncome);
  169. logger.info("全年一次性奖金收入算税结果对象");
  170. //全年一次性奖金收入算税结果对象
  171. ComplexTaxCalculateResult annualOneTimeBonusIncome = complexIncomeResult.getAnnualOneTimeBonusIncome();
  172. handleComplexTaxCalculateResult(ctx, annualOneTimeBonusIncome);
  173. logger.info("一般劳务报酬算税结果对象");
  174. //一般劳务报酬算税结果对象
  175. ComplexTaxCalculateResult laborRemunerationIncome = complexIncomeResult.getLaborRemunerationIncome();
  176. handleComplexTaxCalculateResult(ctx, laborRemunerationIncome);
  177. logger.info("解除劳动合同一次性补偿金算税结果对象");
  178. //解除劳动合同一次性补偿金算税结果对象
  179. ComplexTaxCalculateResult compensateIncome = complexIncomeResult.getCompensateIncome();
  180. handleComplexTaxCalculateResult(ctx, compensateIncome);
  181. messageResult = MessageResult.SUCCESS();
  182. }
  183. logger.info("保存日志对象");
  184. iLogInfo.addnew(logInfo);
  185. logger.info("返回结果");
  186. return messageResult;
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. logInfo.setErrorInfo(e.getMessage());//错误信息
  190. iLogInfo.addnew(logInfo);
  191. return MessageResult.ERROR(e.getMessage());
  192. }
  193. }
  194. /**
  195. * 处理所得项目算税结果
  196. *
  197. * @param ctx
  198. * @param normalSalarySpecIncome
  199. * @throws BOSException
  200. */
  201. private void handleComplexTaxCalculateResult(
  202. Context ctx,
  203. ComplexTaxCalculateResult normalSalarySpecIncome)
  204. throws BOSException, JsonProcessingException {
  205. logger.info("handleComplexTaxCalculateResult:" + objectMapper.writeValueAsString(normalSalarySpecIncome));
  206. if (normalSalarySpecIncome != null) {
  207. //算税总人数
  208. Integer totalPeople = normalSalarySpecIncome.getTotalPeople();
  209. //算税失败人数
  210. Integer failedPeople = normalSalarySpecIncome.getFailedPeople();
  211. //年金上限
  212. BigDecimal annuityLimit = normalSalarySpecIncome.getAnnuityLimit();
  213. //公积金上限
  214. BigDecimal houseProvidentFundLimit = normalSalarySpecIncome.getHouseProvidentFundLimit();
  215. //年平均工资
  216. BigDecimal averageAnnual = normalSalarySpecIncome.getAverageAnnual();
  217. //企业在电子税务局上月是否已申报(仅正常工资薪金有效) 0:上月未申报 1:上月已申报 2:上上月未申报
  218. String etaxDeclaredLastMonth = normalSalarySpecIncome.getEtaxDeclaredLastMonth();
  219. //综合算税成功列表
  220. List<ComplexIncome> successComplexIncomes = normalSalarySpecIncome.getSuccessComplexIncomes();
  221. handleSuccessComplexIncome(ctx, successComplexIncomes);
  222. //综合算税失败薪资列表
  223. List<ComplexIncome> failedComplexIncomes = normalSalarySpecIncome.getFailedComplexIncomes();
  224. //handleFailedComplexIncome(failedComplexIncomes);
  225. //失败算税原因列表
  226. List<CheckTaxCalResult> failedCheckTaxCalResult = normalSalarySpecIncome.getFailedCheckTaxCalResult();
  227. handleFailedCheckTaxCalResult(ctx, failedCheckTaxCalResult);
  228. }
  229. }
  230. /**
  231. * 处理综合算税成功列表
  232. */
  233. private void handleSuccessComplexIncome(Context ctx, List<ComplexIncome> successComplexIncomes) throws BOSException {
  234. if (successComplexIncomes != null) {
  235. //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  236. StringBuilder updateSql = new StringBuilder();
  237. updateSql.append("/*dialect*/update T_HR_STaxCalInitDetail set FSTATE = '40',FERRORINFO = '成功', ");
  238. for (String key : taxItemInitMap.keySet()) {
  239. String tableField = taxItemInitMap.get(key);
  240. updateSql.append(tableField).append("=?, ");
  241. }
  242. updateSql.deleteCharAt(updateSql.lastIndexOf(","));
  243. updateSql.append(" where fpersonId = ? ");
  244. updateSql.append(" and FTAXUNITID=? and to_char(FPERIODBEGIN,'yyyy-mm-dd') >= ? and to_char(FPERIODEND,'yyyy-mm-dd') <= ? and FINCOMEITEMID=? and FSTATE =30");
  245. List<Object[]> sqlParams = new ArrayList<>();
  246. Set<String> personIds = new HashSet<>();
  247. Set<String> incomeitemIds = new HashSet<>();
  248. for (int i = 0; successComplexIncomes != null && i < successComplexIncomes.size(); i++) {
  249. ComplexIncome complexIncome = successComplexIncomes.get(i);
  250. Map incomeDataMap = new HashMap();
  251. List updateList = new ArrayList();
  252. //姓名
  253. String name = complexIncome.getName();
  254. //证件类型名称
  255. String licenseType = complexIncome.getLicenseType();
  256. //String cardTypeValue = cardTypeEnumMap.get(licenseType);
  257. //证件号码
  258. String licenseNumber = complexIncome.getLicenseNumber();
  259. //员工id
  260. String personId = taxPersonRecordMap.get(licenseNumber + licenseType);
  261. if (StringUtils.isEmpty(personId)) {
  262. logger.error("未匹配到人员 证件号: " + licenseNumber + " 证件类型: " + licenseType);
  263. continue;
  264. }
  265. //受雇日期
  266. //String employedDate = complexIncome.getEmployedDate();
  267. //离职日期
  268. //String resignDate = complexIncome.getResignDate();
  269. //是否明细申报
  270. //String isDetailedDeclaration = complexIncome.getIsDetailedDeclaration();
  271. //当期收入额
  272. BigDecimal income = complexIncome.getIncome();
  273. incomeDataMap.put("sre", income);
  274. //免税收入
  275. BigDecimal exemptIncome = complexIncome.getExemptIncome();
  276. incomeDataMap.put("mssd", exemptIncome);
  277. //基本养老保险
  278. BigDecimal endowmentInsurance = complexIncome.getEndowmentInsurance();
  279. incomeDataMap.put("jbylaobxf", endowmentInsurance);
  280. //基本医疗保险
  281. BigDecimal medicalInsurance = complexIncome.getMedicalInsurance();
  282. incomeDataMap.put("jbylbxf", medicalInsurance);
  283. //失业保险
  284. BigDecimal unemploymentInsurance = complexIncome.getUnemploymentInsurance();
  285. incomeDataMap.put("sybxf", unemploymentInsurance);
  286. //住房公积金
  287. BigDecimal houseProvidentFund = complexIncome.getHouseProvidentFund();
  288. incomeDataMap.put("zfgjj", houseProvidentFund);
  289. //原始住房公积金
  290. BigDecimal originalHouseProvidentFund = complexIncome.getOriginalHouseProvidentFund();
  291. //子女教育支出
  292. BigDecimal childEducationExpenditure = complexIncome.getChildEducationExpenditure();
  293. incomeDataMap.put("znjyzc_ex", childEducationExpenditure);
  294. //赡养老人支出
  295. BigDecimal supportElderExpenditure = complexIncome.getSupportElderExpenditure();
  296. incomeDataMap.put("sylrzc_ex", supportElderExpenditure);
  297. //住房租金支出
  298. BigDecimal houseRentExpenditure = complexIncome.getHouseRentExpenditure();
  299. incomeDataMap.put("zfzjzc_ex", houseRentExpenditure);
  300. //房屋贷款支出
  301. BigDecimal houseLoanExpenditure = complexIncome.getHouseLoanExpenditure();
  302. incomeDataMap.put("zfdklxzc_ex", houseLoanExpenditure);
  303. //继续教育支出
  304. BigDecimal continueEducationExpenditure = complexIncome.getContinueEducationExpenditure();
  305. incomeDataMap.put("jxjyzc_ex", continueEducationExpenditure);
  306. //非学历继续教育支出
  307. BigDecimal unDegreeContinueEducationExpenditure = complexIncome.getUnDegreeContinueEducationExpenditure();
  308. incomeDataMap.put("fxljxjyzc_ex", unDegreeContinueEducationExpenditure);
  309. //婴幼儿照护支出
  310. BigDecimal babyCareExpenditure = complexIncome.getBabyCareExpenditure();
  311. incomeDataMap.put("yyezhzc_ex", babyCareExpenditure);
  312. //企业年金/职业年金
  313. BigDecimal annuity = complexIncome.getAnnuity();
  314. incomeDataMap.put("nj", annuity);
  315. //商业健康保险
  316. BigDecimal commercialHealthInsurance = complexIncome.getCommercialHealthInsurance();
  317. incomeDataMap.put("syjkbx", commercialHealthInsurance);
  318. //税延养老保险
  319. BigDecimal extensionEndowmentInsurance = complexIncome.getExtensionEndowmentInsurance();
  320. incomeDataMap.put("syylbx", extensionEndowmentInsurance);
  321. //其他
  322. BigDecimal other = complexIncome.getOther();
  323. incomeDataMap.put("qt", other);
  324. //减免税额
  325. BigDecimal taxDeduction = complexIncome.getTaxDeduction();
  326. incomeDataMap.put("jmse", taxDeduction);
  327. //备注 根据政策要求,填写【其他】项,一定在备注中写明具体扣除项目名称
  328. String remark = complexIncome.getRemark();
  329. incomeDataMap.put("bz", remark);
  330. //减除费用
  331. BigDecimal deductionAmount = complexIncome.getDeductionAmount();
  332. incomeDataMap.put("qzd", deductionAmount);
  333. //其他扣除合计
  334. BigDecimal otherDeductionSum = complexIncome.getOtherDeductionSum();
  335. incomeDataMap.put("qtckhj", otherDeductionSum);
  336. //应纳税所得额
  337. BigDecimal taxableIncome = complexIncome.getTaxableIncome();
  338. incomeDataMap.put("ynssde", taxableIncome);
  339. //应纳税额
  340. BigDecimal payableAmount = complexIncome.getPayableAmount();
  341. //已缴税额
  342. BigDecimal paidAmount = complexIncome.getPaidAmount();
  343. //应扣缴税额
  344. BigDecimal withholdingAmount = complexIncome.getWithholdingAmount();
  345. //税率
  346. BigDecimal taxRate = complexIncome.getTaxRate();
  347. incomeDataMap.put("sl", taxRate);
  348. //速算扣除数
  349. BigDecimal quickDeduction = complexIncome.getQuickDeduction();
  350. incomeDataMap.put("sskcs", quickDeduction);
  351. //所得项目名称
  352. String incomeItemName = complexIncome.getIncomeItemName();
  353. if (!incomeItemMap.containsKey(incomeItemName)) {
  354. logger.error("未匹配到所得项目 名称为: " + incomeItemName);
  355. continue;
  356. }
  357. String incomeItemId = incomeItemMap.get(incomeItemName);
  358. incomeDataMap.put("sdxm", incomeItemId);
  359. //应补退税额 累计应扣缴税额-累计已缴税额
  360. BigDecimal refundTax = complexIncome.getRefundTax();
  361. incomeDataMap.put("bqybtse", refundTax);
  362. //累计收入额 本年累计收入=本期所有的工资薪金所得收入之和+往期工资薪金所得收入之和(见税款计算)
  363. BigDecimal accumulatedIncome = complexIncome.getAccumulatedIncome();
  364. incomeDataMap.put("bqljsre", accumulatedIncome);
  365. //累计免税收入额
  366. BigDecimal accumulatedExemptIncome = complexIncome.getAccumulatedExemptIncome();
  367. incomeDataMap.put("bqljmssr", accumulatedExemptIncome);
  368. //累计专项扣除额
  369. BigDecimal accumulatedSpecDeduction = complexIncome.getAccumulatedSpecDeduction();
  370. incomeDataMap.put("zxkchj", accumulatedSpecDeduction);
  371. //累计专项(附加)扣除额
  372. BigDecimal accumulatedSpecAttachDeduction = complexIncome.getAccumulatedSpecAttachDeduction();
  373. incomeDataMap.put("zxfjkchj", accumulatedSpecAttachDeduction);
  374. //累计其他扣除额
  375. BigDecimal accumulatedOtherDeduction = complexIncome.getAccumulatedOtherDeduction();
  376. incomeDataMap.put("qtckhj", accumulatedOtherDeduction);
  377. //累计减免税额
  378. BigDecimal accumulatedTaxDeduction = complexIncome.getAccumulatedTaxDeduction();
  379. incomeDataMap.put("ljjmse", accumulatedTaxDeduction);
  380. //累计减除费用额
  381. BigDecimal accumulatedDeductionAmount = complexIncome.getAccumulatedDeductionAmount();
  382. incomeDataMap.put("jcfy", accumulatedDeductionAmount);
  383. //todo 累计月减除费用
  384. BigDecimal accumulatedMonthDeduction = complexIncome.getAccumulatedMonthDeduction();
  385. //累计应纳税所得额
  386. BigDecimal accumulatedTaxableIncome = complexIncome.getAccumulatedTaxableIncome();
  387. incomeDataMap.put("ljynssde", accumulatedTaxableIncome);
  388. //累计应纳税额
  389. BigDecimal accumulatedPayableAmount = complexIncome.getAccumulatedPayableAmount();
  390. incomeDataMap.put("ljynse", accumulatedPayableAmount);
  391. //累计应扣缴税额 累计应纳税额 - 累计减免税额
  392. BigDecimal accumulatedWithholdingAmount = complexIncome.getAccumulatedWithholdingAmount();
  393. incomeDataMap.put("ljyingkjse", accumulatedWithholdingAmount);
  394. //累计子女教育支出
  395. BigDecimal accumulatedChildEducation = complexIncome.getAccumulatedChildEducation();
  396. incomeDataMap.put("znjyzc", accumulatedChildEducation);
  397. //累计继续教育支出
  398. BigDecimal accumulatedContinueEducation = complexIncome.getAccumulatedContinueEducation();
  399. incomeDataMap.put("jxjyzc", accumulatedContinueEducation);
  400. //累计学历继续教育支出
  401. BigDecimal accumulatedDegreeContinueEducationLimit = complexIncome.getAccumulatedDegreeContinueEducationLimit();
  402. incomeDataMap.put("ljxljxjyzc_ex", accumulatedDegreeContinueEducationLimit);
  403. //累计非学历继续教育支出
  404. BigDecimal accumulatedUnDegreeContinueEducationLimit = complexIncome.getAccumulatedUnDegreeContinueEducationLimit();
  405. incomeDataMap.put("ljfxljxjyzc_ex", accumulatedUnDegreeContinueEducationLimit);
  406. //累计住房租金支出
  407. BigDecimal accumulatedHouseRent = complexIncome.getAccumulatedHouseRent();
  408. incomeDataMap.put("zfzjzc", accumulatedHouseRent);
  409. //累计房屋贷款支出
  410. BigDecimal accumulatedHouseLoan = complexIncome.getAccumulatedHouseLoan();
  411. incomeDataMap.put("zfdklxzc", accumulatedHouseLoan);
  412. //累计赡养老人支出
  413. BigDecimal accumulatedSupportElder = complexIncome.getAccumulatedSupportElder();
  414. incomeDataMap.put("sylrzc", accumulatedSupportElder);
  415. //todo 累计3岁以下婴幼儿照护支出
  416. BigDecimal accumulatedBabyCare = complexIncome.getAccumulatedBabyCare();
  417. incomeDataMap.put("ljyyezhzc_ex", accumulatedBabyCare);
  418. //累计准予扣除的捐赠额
  419. BigDecimal accumulatedDeductibleDonation = complexIncome.getAccumulatedDeductibleDonation();
  420. incomeDataMap.put("ljzykcdjze", accumulatedDeductibleDonation);
  421. //累计个人养老金
  422. BigDecimal accumulatedPersonalPension = complexIncome.getAccumulatedPersonalPension();
  423. incomeDataMap.put("grylj", accumulatedPersonalPension);
  424. //todo 累计个人养老金校验码
  425. String accumulatedPersonalPensionCheckCode = complexIncome.getAccumulatedPersonalPensionCheckCode();
  426. //准予扣除的捐赠额
  427. BigDecimal deductibleDonation = complexIncome.getDeductibleDonation();
  428. incomeDataMap.put("zykcjze", deductibleDonation);
  429. //累计已缴税额
  430. BigDecimal accumulatedPaidAmount = complexIncome.getAccumulatedPaidAmount();
  431. //incomeDataMap.put("ykjse", accumulatedPaidAmount);
  432. //企业上月是否已申报
  433. String etaxDeclaredLastMonth = complexIncome.getEtaxDeclaredLastMonth();
  434. //员工在税局累计已扣缴的税额
  435. BigDecimal etaxAccumulatedPaidAmount = complexIncome.getEtaxAccumulatedPaidAmount();
  436. //incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  437. //本月已累计扣除税额
  438. BigDecimal monthAccumulatedWithholdingAmount = complexIncome.getMonthAccumulatedWithholdingAmount();
  439. incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  440. //本次应扣缴税额
  441. BigDecimal currentWithholdingAmount = complexIncome.getCurrentWithholdingAmount();
  442. incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  443. //允许扣除的税费
  444. BigDecimal taxDeductible = complexIncome.getTaxDeductible();
  445. incomeDataMap.put("yxkcsf", taxDeductible);
  446. //展业成本
  447. BigDecimal exhibitionCost = complexIncome.getExhibitionCost();
  448. incomeDataMap.put("zycb", exhibitionCost);
  449. //月减除费用
  450. BigDecimal monthDeduction = complexIncome.getMonthDeduction();
  451. incomeDataMap.put("qzd", monthDeduction);
  452. //分摊年度数
  453. Integer apportionYears = complexIncome.getApportionYears();
  454. //年减除费用 默认为60000
  455. BigDecimal yearDeduction = complexIncome.getYearDeduction();
  456. //封装更新参数
  457. for (String key : taxItemInitMap.keySet()) {
  458. updateList.add(incomeDataMap.get(key));
  459. }
  460. updateList.add(personId);
  461. updateList.add(taxUnitId);
  462. updateList.add(periodBegin);
  463. updateList.add(periodEnd);
  464. updateList.add(incomeItemId);
  465. sqlParams.add(updateList.toArray());
  466. if (!personIds.contains(personId)) {
  467. personIds.add(personId);
  468. }
  469. if (!incomeitemIds.contains(incomeItemId)) {
  470. incomeitemIds.add(incomeItemId);
  471. }
  472. }
  473. try {
  474. logger.info("updateSql: " + updateSql);
  475. logger.info("处理综合算税成功列表 sqlParams " + objectMapper.writeValueAsString(sqlParams));
  476. if (!sqlParams.isEmpty()) {
  477. DbUtil.executeBatch(ctx, updateSql.toString(), sqlParams);
  478. }
  479. } catch (Exception e) {
  480. e.printStackTrace();
  481. throw new BOSException("处理处理综合算税成功列表,更新初算数据报错:" + e.getMessage());
  482. }
  483. //生成个税应用+税款计算最终拆分明细表
  484. try {
  485. logger.info("处理综合算税成功列表 personIds " + objectMapper.writeValueAsString(personIds));
  486. logger.info("处理综合算税成功列表 incomeitemIds " + objectMapper.writeValueAsString(incomeitemIds));
  487. if (!personIds.isEmpty() && !incomeitemIds.isEmpty()) {
  488. generateOrUpdateTaxCalConfigDetail(ctx, personIds, incomeitemIds);
  489. }
  490. } catch (Exception e) {
  491. e.printStackTrace();
  492. throw new BOSException("处理处理综合算税成功列表,生成个税应用+税款计算最终拆分明细表报错:" + e.getMessage());
  493. }
  494. }
  495. }
  496. /**
  497. * 处理综合算税失败薪资列表
  498. *
  499. * @param failedComplexIncomes
  500. */
  501. private void handleFailedComplexIncome(List<ComplexIncome> failedComplexIncomes) {
  502. for (int i = 0; failedComplexIncomes != null && i < failedComplexIncomes.size(); i++) {
  503. ComplexIncome complexIncome = failedComplexIncomes.get(i);
  504. //姓名
  505. String name = complexIncome.getName();
  506. //证件类型名称
  507. String licenseType = complexIncome.getLicenseType();
  508. //证件号码
  509. String licenseNumber = complexIncome.getLicenseNumber();
  510. //受雇日期
  511. String employedDate = complexIncome.getEmployedDate();
  512. //离职日期
  513. String resignDate = complexIncome.getResignDate();
  514. //是否明细申报
  515. String isDetailedDeclaration = complexIncome.getIsDetailedDeclaration();
  516. //当期收入额
  517. BigDecimal income = complexIncome.getIncome();
  518. //免税收入
  519. BigDecimal exemptIncome = complexIncome.getExemptIncome();
  520. //基本养老保险
  521. BigDecimal endowmentInsurance = complexIncome.getEndowmentInsurance();
  522. //基本医疗保险
  523. BigDecimal medicalInsurance = complexIncome.getMedicalInsurance();
  524. //失业保险
  525. BigDecimal unemploymentInsurance = complexIncome.getUnemploymentInsurance();
  526. //住房公积金
  527. BigDecimal houseProvidentFund = complexIncome.getHouseProvidentFund();
  528. //原始住房公积金
  529. //BigDecimal originalHouseProvidentFund = complexIncome.getOriginalHouseProvidentFund();
  530. //子女教育支出
  531. BigDecimal childEducationExpenditure = complexIncome.getChildEducationExpenditure();
  532. //赡养老人支出
  533. BigDecimal supportElderExpenditure = complexIncome.getSupportElderExpenditure();
  534. //住房租金支出
  535. BigDecimal houseRentExpenditure = complexIncome.getHouseRentExpenditure();
  536. //房屋贷款支出
  537. BigDecimal houseLoanExpenditure = complexIncome.getHouseLoanExpenditure();
  538. //继续教育支出
  539. BigDecimal continueEducationExpenditure = complexIncome.getContinueEducationExpenditure();
  540. //非学历继续教育支出
  541. BigDecimal unDegreeContinueEducationExpenditure = complexIncome.getUnDegreeContinueEducationExpenditure();
  542. //婴幼儿照护支出
  543. BigDecimal babyCareExpenditure = complexIncome.getBabyCareExpenditure();
  544. //企业年金/职业年金
  545. BigDecimal annuity = complexIncome.getAnnuity();
  546. //商业健康保险
  547. BigDecimal commercialHealthInsurance = complexIncome.getCommercialHealthInsurance();
  548. //税延养老保险
  549. BigDecimal extensionEndowmentInsurance = complexIncome.getExtensionEndowmentInsurance();
  550. //其他
  551. BigDecimal other = complexIncome.getOther();
  552. //减免税额
  553. BigDecimal taxDeduction = complexIncome.getTaxDeduction();
  554. //备注
  555. String remark = complexIncome.getRemark();
  556. //减除费用
  557. BigDecimal deductionAmount = complexIncome.getDeductionAmount();
  558. //其他扣除合计
  559. BigDecimal otherDeductionSum = complexIncome.getOtherDeductionSum();
  560. //应纳税所得额
  561. BigDecimal taxableIncome = complexIncome.getTaxableIncome();
  562. //应纳税额
  563. BigDecimal payableAmount = complexIncome.getPayableAmount();
  564. //已缴税额
  565. BigDecimal paidAmount = complexIncome.getPaidAmount();
  566. //应扣缴税额
  567. BigDecimal withholdingAmount = complexIncome.getWithholdingAmount();
  568. //税率
  569. BigDecimal taxRate = complexIncome.getTaxRate();
  570. //速算扣除数
  571. BigDecimal quickDeduction = complexIncome.getQuickDeduction();
  572. //所得项目名称
  573. String incomeItemName = complexIncome.getIncomeItemName();
  574. //应补退税额
  575. BigDecimal refundTax = complexIncome.getRefundTax();
  576. //累计收入额
  577. BigDecimal accumulatedIncome = complexIncome.getAccumulatedIncome();
  578. //累计免税收入额
  579. BigDecimal accumulatedExemptIncome = complexIncome.getAccumulatedExemptIncome();
  580. //累计专项扣除额
  581. BigDecimal accumulatedSpecDeduction = complexIncome.getAccumulatedSpecDeduction();
  582. //累计专项(附加)扣除额
  583. BigDecimal accumulatedSpecAttachDeduction = complexIncome.getAccumulatedSpecAttachDeduction();
  584. //累计其他扣除额
  585. BigDecimal accumulatedOtherDeduction = complexIncome.getAccumulatedOtherDeduction();
  586. //累计减免税额
  587. BigDecimal accumulatedTaxDeduction = complexIncome.getAccumulatedTaxDeduction();
  588. //累计减除费用额
  589. BigDecimal accumulatedDeductionAmount = complexIncome.getAccumulatedDeductionAmount();
  590. //累计月减除费用
  591. BigDecimal accumulatedMonthDeduction = complexIncome.getAccumulatedMonthDeduction();
  592. //累计应纳税所得额
  593. BigDecimal accumulatedTaxableIncome = complexIncome.getAccumulatedTaxableIncome();
  594. //累计应纳税额
  595. BigDecimal accumulatedPayableAmount = complexIncome.getAccumulatedPayableAmount();
  596. //累计应扣缴税额
  597. BigDecimal accumulatedWithholdingAmount = complexIncome.getAccumulatedWithholdingAmount();
  598. //累计子女教育支出
  599. BigDecimal accumulatedChildEducation = complexIncome.getAccumulatedChildEducation();
  600. //累计继续教育支出
  601. BigDecimal accumulatedContinueEducation = complexIncome.getAccumulatedContinueEducation();
  602. //累计学历继续教育支出
  603. BigDecimal accumulatedDegreeContinueEducationLimit = complexIncome.getAccumulatedDegreeContinueEducationLimit();
  604. //累计非学历继续教育支出
  605. BigDecimal accumulatedUnDegreeContinueEducationLimit = complexIncome.getAccumulatedUnDegreeContinueEducationLimit();
  606. //累计住房租金支出
  607. BigDecimal accumulatedHouseRent = complexIncome.getAccumulatedHouseRent();
  608. //累计房屋贷款支出
  609. BigDecimal accumulatedHouseLoan = complexIncome.getAccumulatedHouseLoan();
  610. //累计赡养老人支出
  611. BigDecimal accumulatedSupportElder = complexIncome.getAccumulatedSupportElder();
  612. //累计3岁以下婴幼儿照护支出
  613. BigDecimal accumulatedBabyCare = complexIncome.getAccumulatedBabyCare();
  614. //累计准予扣除的捐赠额
  615. BigDecimal accumulatedDeductibleDonation = complexIncome.getAccumulatedDeductibleDonation();
  616. //累计个人养老金
  617. BigDecimal accumulatedPersonalPension = complexIncome.getAccumulatedPersonalPension();
  618. //累计个人养老金校验码
  619. String accumulatedPersonalPensionCheckCode = complexIncome.getAccumulatedPersonalPensionCheckCode();
  620. //准予扣除的捐赠额
  621. BigDecimal deductibleDonation = complexIncome.getDeductibleDonation();
  622. //累计已缴税额
  623. BigDecimal accumulatedPaidAmount = complexIncome.getAccumulatedPaidAmount();
  624. //企业上月是否已申报:
  625. String etaxDeclaredLastMonth = complexIncome.getEtaxDeclaredLastMonth();
  626. //员工在税局累计已扣缴的税额
  627. BigDecimal etaxAccumulatedPaidAmount = complexIncome.getEtaxAccumulatedPaidAmount();
  628. //本月已累计扣除税额
  629. BigDecimal monthAccumulatedWithholdingAmount = complexIncome.getMonthAccumulatedWithholdingAmount();
  630. //本次应扣缴税额
  631. BigDecimal currentWithholdingAmount = complexIncome.getCurrentWithholdingAmount();
  632. //允许扣除的税费
  633. BigDecimal taxDeductible = complexIncome.getTaxDeductible();
  634. //展业成本
  635. BigDecimal exhibitionCost = complexIncome.getExhibitionCost();
  636. //月减除费用
  637. BigDecimal monthDeduction = complexIncome.getMonthDeduction();
  638. //分摊年度数
  639. Integer apportionYears = complexIncome.getApportionYears();
  640. //年减除费用 默认为60000
  641. BigDecimal yearDeduction = complexIncome.getYearDeduction();
  642. }
  643. }
  644. /**
  645. * 处理失败算税原因列表
  646. *
  647. * @param failedCheckTaxCalResult
  648. */
  649. private void handleFailedCheckTaxCalResult(
  650. Context ctx,
  651. List<CheckTaxCalResult> failedCheckTaxCalResult)
  652. throws BOSException, JsonProcessingException {
  653. logger.info("handleFailedCheckTaxCalResult:" + objectMapper.writeValueAsString(failedCheckTaxCalResult));
  654. if (failedCheckTaxCalResult != null) {
  655. String updateSql = "/*dialect*/update T_HR_STaxCalInitDetail set FERRORINFO = ?,FSTATE = '50' " +
  656. "where fpersonId = ? " +
  657. "and FTAXUNITID=? and to_char(FPERIODBEGIN,'yyyy-mm-dd') >= ? and to_char(FPERIODEND,'yyyy-mm-dd') <= ? and FINCOMEITEMID=? and FSTATE =30";
  658. List<Object[]> udpateParameter = new ArrayList<>();
  659. for (int i = 0; failedCheckTaxCalResult != null && i < failedCheckTaxCalResult.size(); i++) {
  660. List list = new ArrayList();
  661. CheckTaxCalResult checkTaxCalResult = failedCheckTaxCalResult.get(i);
  662. //证件类型名称
  663. String licenseType = checkTaxCalResult.getLicenseType();
  664. //String cardTypeValue = cardTypeEnumMap.get(licenseType);
  665. //证件号码
  666. String licenseNumber = checkTaxCalResult.getLicenseNumber();
  667. //员工id
  668. String personId = taxPersonRecordMap.get(licenseNumber + licenseType);
  669. if (StringUtils.isEmpty(personId)) {
  670. logger.error("未匹配到人员 证件号: " + licenseNumber + " 证件类型: " + licenseType);
  671. continue;
  672. }
  673. //人员id
  674. Long employeeId = checkTaxCalResult.getEmployeeId();
  675. //人员名称
  676. String employeeName = checkTaxCalResult.getEmployeeName();
  677. //错误码
  678. String errorCode = checkTaxCalResult.getErrorCode();
  679. //错误信息
  680. String errorMessage = checkTaxCalResult.getErrorMessage();
  681. //所得税表的code
  682. String incomeItemCode = checkTaxCalResult.getIncomeItemCode();
  683. //所得税表的name
  684. String incomeItemName = checkTaxCalResult.getIncomeItemName();
  685. if (!incomeItemMap.containsKey(incomeItemName)) {
  686. logger.error("未匹配到所得项目 名称为: " + incomeItemName);
  687. continue;
  688. }
  689. String incomeItemId = incomeItemMap.get(incomeItemName);
  690. list.add(errorMessage);
  691. list.add(personId);
  692. list.add(taxUnitId);
  693. list.add(periodBegin);
  694. list.add(periodEnd);
  695. list.add(incomeItemId);
  696. udpateParameter.add(list.toArray());
  697. }
  698. try {
  699. logger.error("处理失败算税原因列表 updateSql " + updateSql);
  700. logger.error("处理失败算税原因列表 udpateParameter " + objectMapper.writeValueAsString(udpateParameter));
  701. if (!udpateParameter.isEmpty()) {
  702. DbUtil.executeBatch(ctx, updateSql, udpateParameter);
  703. }
  704. } catch (BOSException e) {
  705. e.printStackTrace();
  706. throw new BOSException("更新处理失败算税原因列表报错: " + e.getMessage());
  707. }
  708. }
  709. }
  710. /**
  711. * 生成个税应用+税款计算最终拆分明细表
  712. * 先新增再更新
  713. */
  714. private void generateOrUpdateTaxCalConfigDetail(Context ctx,
  715. Set<String> personIds,
  716. Set<String> incomeitemIds) throws BOSException, SQLException, ParseException, JsonProcessingException {
  717. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  718. Date periodBeginDate = sdf.parse(periodBegin);
  719. Date periodEndDate = sdf.parse(periodEnd);
  720. //先查出计算成功的初算数据(人员、纳税单位id、周期、所得项目、状态=成功)
  721. ITaxCalConfigDetail iTaxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
  722. StringBuilder querySql = new StringBuilder();
  723. querySql.append("SELECT fid,fpersonId,fincomeitemid,FCALSCHEMEID,FCMPCALTABLEID,FTAXUNITID from T_HR_STaxCalInitDetail where").append("\n");
  724. querySql.append(" fpersonId in(").append(AtsUtil.convertSetToString(personIds)).append(")").append("\n");
  725. querySql.append(" and to_char(FPERIODBEGIN, 'yyyy-mm-dd') >= '").append(periodBegin).append("'").append("\n");
  726. querySql.append(" and to_char(FPERIODEND, 'yyyy-mm-dd') <= '").append(periodEnd).append("'").append("\n");
  727. querySql.append(" and FINCOMEITEMID in(").append(AtsUtil.convertSetToString(incomeitemIds)).append(")").append("\n");
  728. querySql.append(" and FTAXUNITID = '").append(taxUnitId).append("'").append("\n");
  729. querySql.append(" and FSTATE = '40'").append("\n");
  730. logger.info("generateOrUpdateTaxCalConfigDetail.sql: " + querySql);
  731. IRowSet iRowSet = DbUtil.executeQuery(ctx, querySql.toString());
  732. List<Map<String, String>> list = new ArrayList<>();
  733. while (iRowSet.next()) {
  734. Map<String, String> map = new HashMap<>();
  735. map.put("initId", iRowSet.getString("fid"));
  736. map.put("personId", iRowSet.getString("fpersonId"));
  737. map.put("incomeitemid", iRowSet.getString("FINCOMEITEMID"));
  738. map.put("calSchemeId", iRowSet.getString("FCALSCHEMEID"));
  739. map.put("cmpCalTableId", iRowSet.getString("FCMPCALTABLEID"));
  740. map.put("taxUnitId", iRowSet.getString("FTAXUNITID"));
  741. list.add(map);
  742. }
  743. //用初算数据生成明细表(需要判断明细表数据是否已经生成过)
  744. Set<String> initIds = new HashSet<>();
  745. Set<String> configIds = new HashSet<>();
  746. for (int i = 0; i < list.size(); i++) {
  747. try {
  748. String detailId = null;
  749. Map<String, String> map = list.get(i);
  750. String initId = map.get("initId");//初算id
  751. String personId = map.get("personId");
  752. String taxUnitId = map.get("taxUnitId");
  753. String incomeitemid = map.get("incomeitemid");
  754. String calSchemeId = map.get("calSchemeId");
  755. String cmpCalTableId = map.get("cmpCalTableId");
  756. FilterInfo filterInfo = new FilterInfo();
  757. FilterItemCollection filterItems = filterInfo.getFilterItems();
  758. filterItems.add(new FilterItemInfo("person", personId));
  759. filterItems.add(new FilterItemInfo("taxUnit", taxUnitId));
  760. filterItems.add(new FilterItemInfo("periodBegin", periodBeginDate, CompareType.GREATER_EQUALS));
  761. filterItems.add(new FilterItemInfo("periodEnd", periodEndDate, CompareType.LESS_EQUALS));
  762. filterItems.add(new FilterItemInfo("incomeItem", incomeitemid));
  763. filterItems.add(new FilterItemInfo("calScheme", calSchemeId));
  764. filterItems.add(new FilterItemInfo("cmpCalTable", cmpCalTableId));
  765. SelectorItemCollection sic = new SelectorItemCollection();
  766. sic.add("state");
  767. EntityViewInfo instance = EntityViewInfo.getInstance(filterInfo, sic, null);
  768. logger.info("instance: " + instance.toString());
  769. TaxCalConfigDetailCollection taxCalConfigDetailCol = iTaxCalConfigDetail.getTaxCalConfigDetailCollection(instance);
  770. if (taxCalConfigDetailCol.size() > 0) {
  771. TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCol.get(0);
  772. if (TaxResultStateEnum.UN_CONFIRM.equals(taxCalConfigDetailInfo.getState())) {
  773. //未确认,更新数据
  774. detailId = taxCalConfigDetailInfo.getId().toString();
  775. configIds.add(detailId);
  776. } else {
  777. //已确认,不能更新
  778. logger.error("更新明细表数据 已确认,不能更新");
  779. continue;
  780. }
  781. } else {
  782. //没有找到明细数据,创建数据
  783. //个税应用+税款计算最终拆分明细表
  784. TaxCalConfigDetailInfo taxCalConfigDetailInfo = new TaxCalConfigDetailInfo();
  785. //计算规则
  786. taxCalConfigDetailInfo.put("calScheme", map.get("calSchemeId"));
  787. //核算表id
  788. taxCalConfigDetailInfo.put("cmpCalTable", map.get("cmpCalTableId"));
  789. //状态
  790. taxCalConfigDetailInfo.setState(TaxResultStateEnum.UN_CONFIRM);
  791. //依赖id
  792. //taxCalConfigDetailInfo.setRelay();
  793. //是否最后一条
  794. taxCalConfigDetailInfo.setIsLast(true);
  795. //是否生成个税申报
  796. taxCalConfigDetailInfo.setIsGenerateTaxDeclare(false);
  797. //申报批次号
  798. //taxCalConfigDetailInfo.setBatchNo();
  799. //员工
  800. taxCalConfigDetailInfo.put("person", map.get("personId"));
  801. //纳税单位
  802. taxCalConfigDetailInfo.put("taxUnit", map.get("taxUnitId"));
  803. //税款所属期间起
  804. taxCalConfigDetailInfo.setPeriodBegin(periodBeginDate);
  805. //税款所属期间止
  806. taxCalConfigDetailInfo.setPeriodEnd(periodEndDate);
  807. //所得项目
  808. taxCalConfigDetailInfo.put("incomeItem", map.get("incomeitemid"));
  809. detailId = iTaxCalConfigDetail.addnew(taxCalConfigDetailInfo).toString();
  810. configIds.add(detailId);
  811. }
  812. initIds.add(initId);
  813. } catch (Exception e) {
  814. e.printStackTrace();
  815. }
  816. }
  817. logger.info("configIds: " + objectMapper.writeValueAsString(configIds));
  818. logger.info("initIds " + objectMapper.writeValueAsString(initIds));
  819. if (!configIds.isEmpty() && !initIds.isEmpty()) {
  820. //更新明细表数据
  821. StringBuilder updateSql = new StringBuilder();
  822. StringBuilder querySqlForUpdate = new StringBuilder();
  823. updateSql.append("update T_HR_STaxCalConfigDetail config set (").append("\n");
  824. for (String key : taxItemConfigMap.keySet()) {
  825. updateSql.append(taxItemConfigMap.get(key)).append(",").append("\n");
  826. querySqlForUpdate.append(taxItemConfigMap.get(key)).append(",").append("\n");
  827. }
  828. updateSql.deleteCharAt(updateSql.lastIndexOf(","));
  829. querySqlForUpdate.deleteCharAt(querySqlForUpdate.lastIndexOf(","));
  830. updateSql.append(") = (select ").append(querySqlForUpdate).append("\n");
  831. updateSql.append(" from T_HR_STaxCalInitDetail ").append("\n");
  832. updateSql.append(" where fid in (").append(AtsUtil.convertSetToString(initIds)).append(")").append("\n");
  833. updateSql.append(" and config.fpersonId = fpersonId").append("\n");
  834. updateSql.append(" and config.fCmpCalTableId = fCmpCalTableId").append("\n");
  835. updateSql.append(" and config.fIncomeItemId = fIncomeItemId").append("\n");
  836. updateSql.append(" and config.FPERIODBEGIN = FPERIODBEGIN").append("\n");
  837. updateSql.append(" and config.FPERIODEND = FPERIODEND)").append("\n");
  838. updateSql.append(" where config.fstate = '10'").append("\n");
  839. updateSql.append(" and config.fid in(").append(AtsUtil.convertSetToString(configIds)).append(")").append("\n");
  840. logger.info("更新明细表sql: " + updateSql);
  841. DbUtil.execute(ctx, updateSql.toString());
  842. }
  843. }
  844. /**
  845. * 获取证件map
  846. *
  847. * @return
  848. */
  849. // private static Map<String, String> getCardTypeEnumMap() {
  850. // Map<String, String> cardTypeEnumMap = new HashMap<>();
  851. // List<Map<String, String>> enumList = CardTypeEnum.getEnumList();
  852. // for (int i = 0; i < enumList.size(); i++) {
  853. // CardTypeEnum cardTypeEnum = (CardTypeEnum) enumList.get(i);
  854. // String value = cardTypeEnum.getValue();
  855. // String alias = cardTypeEnum.getAlias();
  856. // cardTypeEnumMap.put(alias, value);
  857. // }
  858. // return cardTypeEnumMap;
  859. // }
  860. /**
  861. * 获取所得项目
  862. *
  863. * @param ctx
  864. * @return
  865. * @throws BOSException
  866. */
  867. private Map<String, String> getIncomeItemMap(Context ctx) throws BOSException {
  868. Map<String, String> incomeItemMap = new HashMap<>();
  869. try {
  870. TaxIncomeItemCollection taxIncomeItemCollection = TaxIncomeItemFactory.getLocalInstance(ctx).getTaxIncomeItemCollection("where state = 1");
  871. for (int i = 0; i < taxIncomeItemCollection.size(); i++) {
  872. TaxIncomeItemInfo taxIncomeItemInfo = taxIncomeItemCollection.get(i);
  873. String taxIncomeItemId = taxIncomeItemInfo.getId().toString();
  874. String name = taxIncomeItemInfo.getName();
  875. incomeItemMap.put(name, taxIncomeItemId);
  876. }
  877. return incomeItemMap;
  878. } catch (BOSException e) {
  879. e.printStackTrace();
  880. throw new BOSException("获取所得项目数据报错: " + e.getMessage());
  881. }
  882. }
  883. /**
  884. * 获取报送人员信息
  885. *
  886. * @param ctx
  887. * @throws BOSException
  888. */
  889. private void getTaxPersonRecordMap(Context ctx) throws BOSException {
  890. if (taxPersonRecordMap == null) {
  891. taxPersonRecordMap = new HashMap<>();
  892. }
  893. String oql = "select bill.person.id,bill.cardType,bill.cardNumber where submitStatus='2'";
  894. TaxPersonRecordEntryCollection taxPersonRecordEntryCollection =
  895. TaxPersonRecordEntryFactory.getLocalInstance(ctx).getTaxPersonRecordEntryCollection(oql);
  896. for (int i = 0; i < taxPersonRecordEntryCollection.size(); i++) {
  897. TaxPersonRecordInfo taxPersonRecordInfo = taxPersonRecordEntryCollection.get(i).getBill();
  898. if (taxPersonRecordInfo != null) {
  899. String personId = taxPersonRecordInfo.getPerson().getId().toString();
  900. CardTypeEnum cardType = taxPersonRecordInfo.getCardType();
  901. if (cardType == null) {
  902. logger.error("获取报送人员信息 人员id[" + personId + "] 的证件类型为空!");
  903. continue;
  904. }
  905. String cardTypeName = cardType.getAlias();
  906. String cardNumber = taxPersonRecordInfo.getCardNumber();
  907. taxPersonRecordMap.put(cardNumber + cardTypeName, personId);
  908. }
  909. }
  910. }
  911. /**
  912. * 获取个税项目
  913. *
  914. * @param ctx
  915. * @return
  916. * @throws BOSException
  917. */
  918. private void getTaxItemMap(Context ctx) throws BOSException {
  919. if (taxItemInitMap == null) {
  920. taxItemInitMap = new HashMap<>();
  921. }
  922. if (taxItemConfigMap == null) {
  923. taxItemConfigMap = new HashMap<>();
  924. }
  925. //获取所有个税项目
  926. Set initSet = new HashSet();
  927. initSet.add("jmse");//减免税额
  928. initSet.add("qzd");//减除费用
  929. initSet.add("ynssde");//应纳税所得额
  930. initSet.add("sl");//税率
  931. initSet.add("sskcs");//速算扣除数
  932. initSet.add("bqybtse");//应补退税额
  933. initSet.add("bqljsre");//累计收入额
  934. initSet.add("bqljmssr");///累计免税收入额
  935. initSet.add("zxkchj");//累计专项扣除额
  936. initSet.add("zxfjkchj");//累计专项(附加)扣除额
  937. initSet.add("qtckhj");//累计其他扣除额
  938. initSet.add("ljjmse");//累计减免税额
  939. initSet.add("jcfy");//累计减除费用额
  940. initSet.add("ljynssde");//累计应纳税所得额
  941. initSet.add("ljynse");//累计应纳税额
  942. initSet.add("ljyingkjse");//累计应扣缴税额
  943. initSet.add("znjyzc");//累计子女教育支出
  944. initSet.add("jxjyzc");//累计继续教育支出
  945. initSet.add("ljxljxjyzc_ex");//累计学历继续教育支出
  946. initSet.add("ljfxljxjyzc_ex");//累计非学历继续教育支出
  947. initSet.add("zfzjzc");//累计住房租金支出
  948. initSet.add("zfdklxzc");//累计房屋贷款支出
  949. initSet.add("sylrzc");//累计赡养老人支出
  950. initSet.add("ljzykcdjze");//累计准予扣除的捐赠额
  951. initSet.add("grylj"); //累计个人养老金
  952. initSet.add("zykcjze");//准予扣除的捐赠额
  953. initSet.add("ykjse");//本月已累计扣除税额
  954. initSet.add("yxkcsf");//允许扣除的税费
  955. initSet.add("zycb");//展业成本
  956. initSet.add("qzd");//月减除费用
  957. //最终拆分明细表个税项目
  958. Set configSet = new HashSet();
  959. configSet.add("sre");//本期收入
  960. configSet.add("mssd");// 本期免税收入
  961. configSet.add("jbylaobxf");// 基本养老保险费
  962. configSet.add("jbylbxf");// 基本医疗保险费
  963. configSet.add("sybxf");// 失业保险费
  964. configSet.add("zfgjj");// 住房公积金
  965. configSet.add("znjyzc");// 累计子女教育
  966. configSet.add("jxjyzc");// 累计继续教育
  967. configSet.add("zfdklxzc");// 累计住房贷款利息");
  968. configSet.add("zfzjzc");// 累计住房租金");
  969. configSet.add("nj");// 企业(职业)年金");
  970. configSet.add("syjkbx");// 商业健康保险");
  971. configSet.add("syylbx");// 税延养老保险");
  972. configSet.add("qt");// 其他");
  973. configSet.add("zykcjze");// 准予扣除的捐赠额");
  974. configSet.add("jmse");// 减免税额");
  975. configSet.add("yxkcsf");// 允许扣除的税费");
  976. configSet.add("ljsre");// 上期累计收入");
  977. configSet.add("bqljsre");// 本期累计收入");
  978. configSet.add("ljmssd");// 上期累计免税收入");
  979. configSet.add("bqljmssr");// 本期累计免税收入");
  980. configSet.add("qzd");// 减除费用");
  981. configSet.add("jcfy");// 累计减除费用");
  982. configSet.add("fy");// 本期费用");
  983. configSet.add("zxkchj");// 累计专项扣除");
  984. configSet.add("zxfjkchj");// 累计专项附加扣除合计");
  985. configSet.add("qtckhj");// 累计其他扣除");
  986. configSet.add("ljzykcdjze");// 累计准予扣除的捐赠
  987. configSet.add("ljynssde");// 累计应纳税所得额
  988. configSet.add("sl");// 税率
  989. configSet.add("sskcs");// 速算扣除数
  990. configSet.add("ljynse");// 累计应纳税额
  991. configSet.add("ljjmse");// 累计减免税额
  992. configSet.add("ljyingkjse");// 累计应扣缴税额
  993. configSet.add("ykjse");// 累计已预缴税额
  994. configSet.add("ybtse");// 累计应补(退)税额
  995. configSet.add("ycxbc");// 一次性补偿
  996. configSet.add("zycb");// 展业成本
  997. configSet.add("bz");// 备注
  998. configSet.add("ccyz");// 财产原值
  999. configSet.add("jsbl");// 减按计税比例
  1000. configSet.add("ynssde");// 应纳税所得额
  1001. configSet.add("bqybtse");// 本期应补(退)税额
  1002. configSet.add("sylrzc");// 累计赡养老人
  1003. configSet.add("yyezhfzc");// 累计婴幼儿照护费用
  1004. configSet.add("grylj");// 累计个人养老金
  1005. configSet.add("ljfxljxjyzc_ex");// 累计非学历继续教育支出
  1006. configSet.add("ljxljxjyzc_ex");// 累计学历继续教育支出
  1007. configSet.add("znjyzc_ex");// 子女教育支出
  1008. configSet.add("sylrzc_ex");// 赡养老人支出
  1009. configSet.add("zfdklxzc_ex");// 住房贷款利息支出
  1010. configSet.add("zfzjzc_ex");// 住房租金支出
  1011. configSet.add("jxjyzc_ex");// 继续教育支出
  1012. configSet.add("fxljxjyzc_ex");// 非学历继续教育支出
  1013. configSet.add("yyezhzc_ex");// 婴幼儿照护支出
  1014. try {
  1015. TaxItemCollection itemColl = TaxItemFactory.getLocalInstance(ctx)
  1016. .getTaxItemCollection("where state = 1");
  1017. for (int i = 0; i < itemColl.size(); ++i) {
  1018. TaxItemInfo info = itemColl.get(i);
  1019. String number = info.getNumber();
  1020. if (initSet.contains(number)) {
  1021. taxItemInitMap.put(number, "T" + info.getFieldSn());
  1022. }
  1023. if (configSet.contains(number)) {
  1024. taxItemConfigMap.put(number, "T" + info.getFieldSn());
  1025. }
  1026. }
  1027. } catch (BOSException var5) {
  1028. var5.printStackTrace();
  1029. throw new BOSException("获取个税项目报错: " + var5.getMessage());
  1030. }
  1031. }
  1032. }