GetASynIndividualIncomeTaxFeedback.java 56 KB

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