GetASynIndividualIncomeTaxFeedback.java 55 KB

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