123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- package com.kingdee.eas.custom.compensation.service;
- import cn.com.servyou.dto.ApiResponse;
- import cn.com.servyou.dto.declare.Feedback;
- import cn.com.servyou.rmi.client.ClientProxyFactory;
- import cn.com.servyou.service.DeclarationRequest;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.bos.ctrl.swing.StringUtils;
- import com.kingdee.bos.dao.IObjectPK;
- import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
- import com.kingdee.bos.metadata.entity.EntityViewInfo;
- import com.kingdee.bos.metadata.entity.FilterInfo;
- import com.kingdee.bos.metadata.entity.FilterItemInfo;
- import com.kingdee.bos.metadata.entity.SelectorItemCollection;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.bos.util.BOSUuid;
- import com.kingdee.eas.basedata.person.IPerson;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
- import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
- import com.kingdee.eas.custom.shuiyou.task.MessageResult;
- import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.compensation.TaxDeclareStatusEnum;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordFactory;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordInfo;
- import com.kingdee.shr.compensation.app.tax.*;
- import com.kingdee.shr.compensation.app.tax.base.ITaxIncomeItem;
- import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemFactory;
- import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo;
- import com.kingdee.shr.compensation.app.taxCal.ITaxCalConfigDetail;
- import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailCollection;
- import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailFactory;
- import com.kingdee.shr.compensation.app.taxCal.TaxCalConfigDetailInfo;
- import org.apache.log4j.Logger;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.util.*;
- /**
- * @author qingwu
- * @date 2024/9/19
- * @apiNote
- */
- public class SynIncomeTaxDeclareService implements IHRMsfService {
- Logger logger = Logger.getLogger("com.kingdee.eas.custom.compensation.service.SynIncomeTaxDeclareService");
- public Object process(Context context, Map map) throws EASBizException, BOSException {
- //接口日志实体
- LogInfoInfo logInfo = new LogInfoInfo();
- //入口
- logInfo.setEntrance(this.getClass().getName());
- logInfo.setBizDate(new Date());
- Map resMap = new HashMap();
- logger.error("SynIncomeTaxDeclareService----------OSF----Start");
- JSONObject paramData = JSONObject.parseObject((String) map.get("paramData"));
- logger.error("paramData--------" + paramData);
- String requestId = paramData.getString("requestId");
- JSONObject param = paramData.getJSONObject("param");
- logger.error("requestId--------" + requestId);
- logger.error("param--------" + param);
- ObjectMapper mapper = new ObjectMapper();
- try {
- //客户端代理工厂
- ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
- //算税请求接口
- DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest();
- //申报数据反馈 requestId:请求Id reportType:申报所得类型[1:综合所得;2:分类所得;3:非居民所得;4:限售股所得]
- ApiResponse<Feedback> feedback = declarationRequest.getFeedback(requestId, "1");
- logInfo.setInterfaceAddress("/gateway/iit/report/getFeedback");//接口地址
- logInfo.setInterfaceName("getFeedback");//接口名
- logger.error("feedback--------" + mapper.writeValueAsString(feedback));
- String status = feedback.getHead().getStatus();
- Feedback body = null;
- if ("N".equals(status)) {
- //请求失败响应
- String msg = feedback.getHead().getMsg();
- //throw new BOSException(msg);
- logInfo.setStatus("处理中");
- return MessageResult.FAILED(msg);
- } else {
- //调用成功
- //请求id
- body = feedback.getBody();
- logInfo.setOutParameter(mapper.writeValueAsString(body));//回参
- if (body.getDeclarationStateCode().equals("6") || body.getDeclarationStateCode().equals("5")) {
- saveTaxDeclaration(context, param);
- }
- logInfo.setStatus("成功");
- }
- LogInfoFactory.getLocalInstance(context).addnew(logInfo);
- return MessageResult.SUCCESS(mapper.writeValueAsString(body));
- } catch (IOException e) {
- e.printStackTrace();
- logInfo.setErrorInfo(e.getMessage());//错误信息
- logInfo.setStatus("失败");
- LogInfoFactory.getLocalInstance(context).save(logInfo);
- //throw new BOSException(e);
- return MessageResult.ERROR(e.getMessage());
- }
- }
- /**
- * 保存个税申报结果
- *
- * @param param
- */
- public void saveTaxDeclaration(Context ctx, JSONObject param) throws BOSException, EASBizException {
- logger.error("saveTaxDeclaration------------------");
- //个税申报ID
- //String taxDeclarId = param.getString("taxDeclarId");
- //个税申报批次号
- String taxDeclarBatchNo = param.getString("taxDeclarBatchNo");
- IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx);
- IncomeTaxDeclarCollection incomeTaxDeclarCollection = iIncomeTaxDeclar.getIncomeTaxDeclarCollection("where batchNo = '" + taxDeclarBatchNo + "'");
- SelectorItemCollection updateSic = new SelectorItemCollection();
- updateSic.add("declareStatus");
- if (incomeTaxDeclarCollection.size() > 0) {
- IncomeTaxDeclarInfo incomeTaxDeclarInfo = incomeTaxDeclarCollection.get(0);
- incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_SUCCESS);
- iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic);
- }
- ////个税应用+税款计算最终拆分明细表
- //ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
- //TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + taxDeclarBatchNo + "' and state = '20'");
- //for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) {
- // TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i);
- // //员工信息
- // PersonInfo person = taxCalConfigDetailInfo.getPerson();
- //}
- try {
- //个税申报表
- ITaxDeclaration iTaxDeclaration = TaxDeclarationFactory.getLocalInstance(ctx);
- //个税项目
- ITaxIncomeItem iTaxIncomeItem = TaxIncomeItemFactory.getLocalInstance(ctx);
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
- List<Map<String, Object>> taxDeclarationDate = getTaxDeclarationDate(ctx, taxDeclarBatchNo);
- for (int i = 0; i < taxDeclarationDate.size(); i++) {
- Map<String, Object> map = taxDeclarationDate.get(i);
- TaxIncomeItemInfo taxIncomeItemInfo = iTaxIncomeItem.getTaxIncomeItemCollection("where id = '" + map.get("incomeitmemId") + "'").get(0);
- logger.error("taxIncomeItemInfo------------------" + taxIncomeItemInfo);
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.getFilterItems().add(new FilterItemInfo("person", map.get("personId"), CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("taxUnit", map.get("taxunitId"), CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("taxPeriodBegin", map.get("periodbegin"), CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("taxPeriodEnd", map.get("periodend"), CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("proceedItem", taxIncomeItemInfo.getName(), CompareType.EQUALS));
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
- TaxDeclarationCollection taxDeclarationCollection = iTaxDeclaration.getTaxDeclarationCollection(entityViewInfo);
- logger.error("taxDeclarationCollection.size------------------" + taxDeclarationCollection.size());
- if (taxDeclarationCollection.size() <= 0) {
- TaxDeclarationInfo taxDeclarationInfo = new TaxDeclarationInfo();
- //员工
- PersonInfo personInfo = iPerson.getPersonInfo(new ObjectUuidPK((String) map.get("personId")));
- taxDeclarationInfo.setPerson(personInfo);
- //证件号
- taxDeclarationInfo.setIdNO(personInfo.getIdCardNO());
- //证件类型
- TaxPersonRecordInfo taxPersonRecordInfo = TaxPersonRecordFactory.getLocalInstance(ctx).getTaxPersonRecordCollection("where person = '" + personInfo.getId() + "'").get(0);
- String alias = taxPersonRecordInfo.getCardType().getAlias();
- taxDeclarationInfo.setIdType(alias);
- //纳税单位
- TaxUnitInfo taxUnitInfo = new TaxUnitInfo();
- taxUnitInfo.setId(BOSUuid.read((String) map.get("taxunitId")));
- taxDeclarationInfo.setTaxUnit(taxUnitInfo);
- //税款所属期间起始时间
- taxDeclarationInfo.setTaxPeriodBegin((Date) map.get("periodbegin"));
- //税款所属期间截止时间
- taxDeclarationInfo.setTaxPeriodEnd((Date) map.get("periodend"));
- //个税项目
- taxDeclarationInfo.setProceedItem(taxIncomeItemInfo.getName());
- taxDeclarationInfo.setCost((BigDecimal) map.get("t25"));//费用
- taxDeclarationInfo.setIncome((BigDecimal) map.get(" t1"));//收入
- taxDeclarationInfo.setExemptIncome((BigDecimal) map.get("t2"));//免税收入
- taxDeclarationInfo.setBasicPension((BigDecimal) map.get("t3"));//基本养老保险费
- taxDeclarationInfo.setBasicMedical((BigDecimal) map.get("t4"));//基本医疗保险费
- taxDeclarationInfo.setUnemployment((BigDecimal) map.get("t5"));//失业保险费
- taxDeclarationInfo.setHousingFund((BigDecimal) map.get("t6"));//住房公积金
- taxDeclarationInfo.setChildEducateSum((BigDecimal) map.get("t7"));//累计子女教育
- taxDeclarationInfo.setContinueEducateSum((BigDecimal) map.get("t8"));//累计继续教育
- taxDeclarationInfo.setLoanInterestSum((BigDecimal) map.get("t9"));//累计住房贷款利息
- taxDeclarationInfo.setHousingRentSum((BigDecimal) map.get("t10"));//累计住房租金
- taxDeclarationInfo.setOldSupportSum((BigDecimal) map.get("t11"));//累计赡养老人
- taxDeclarationInfo.setIncomeSum((BigDecimal) map.get("t20"));//累计收入额
- taxDeclarationInfo.setDeductionSum((BigDecimal) map.get("t24"));//累计减除费用
- taxDeclarationInfo.setSpecialDeductSum((BigDecimal) map.get("t26"));//累计专项扣除
- taxDeclarationInfo.setOtherDeductionSum((BigDecimal) map.get("t28"));//累计其他扣除
- taxDeclarationInfo.setAllowDonationSum((BigDecimal) map.get("t29"));//累计准予扣除的捐赠
- taxDeclarationInfo.setTaxableIncomeSum((BigDecimal) map.get("t30"));//累计应纳税所得额
- taxDeclarationInfo.setTaxRatio((BigDecimal) map.get("t31"));//税率
- taxDeclarationInfo.setQuickDeduct((BigDecimal) map.get("t32"));//速算扣除数
- taxDeclarationInfo.setTaxPayableSum((BigDecimal) map.get("t33"));//累计应纳税额
- taxDeclarationInfo.setTaxCreditSum((BigDecimal) map.get("t34"));//累计减免税额
- taxDeclarationInfo.setTaxSupOrRefund((BigDecimal) map.get("t38"));//应补/退税额
- taxDeclarationInfo.setInFantSum((BigDecimal) map.get("t45"));//累计婴幼儿照护费用
- taxDeclarationInfo.setPersonalPension((BigDecimal) map.get("t46"));//累计个人养老金
- logger.error("taxDeclarationInfo------------------" + taxDeclarationInfo);
- IObjectPK save = iTaxDeclaration.save(taxDeclarationInfo);
- logger.error("taxDeclarationInfo----------save--------" + save);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (EASBizException e) {
- throw new RuntimeException(e);
- }
- }
- /***
- * 封装个税申报数据
- * @param batchNo
- * @return
- */
- public List<Map<String, Object>> getTaxDeclarationDate(Context ctx, String batchNo) throws BOSException, SQLException {
- List list = new ArrayList();
- String sql = getSql(batchNo);
- logger.error("getTaxDeclarationDate------sql--------" + sql);
- IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
- while (iRowSet.next()) {
- Map map = new HashMap();
- map.put("personId", iRowSet.getString("personId"));//员工Id
- map.put("taxunitId", iRowSet.getString("taxunitId"));//纳税单位Id
- map.put("periodbegin", iRowSet.getDate("periodbegin"));//税款所属期间起始时间
- map.put("periodend", iRowSet.getDate("periodend"));//税款所属期间截止时间
- map.put("incomeitmemId", iRowSet.getString("incomeitmemId"));//个税项目Id
- logger.error("getTaxDeclarationDate------iRowSet.getBigDecimal(t1)--------" + iRowSet.getBigDecimal("t1"));
- map.put("t1", iRowSet.getBigDecimal("t1") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t1"));//本期免税收入
- map.put("t2", iRowSet.getBigDecimal("t2") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t2"));//基本养老保险费
- map.put("t3", iRowSet.getBigDecimal("t3") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t3"));//基本医疗保险费
- map.put("t4", iRowSet.getBigDecimal("t4") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t4"));//失业保险费
- map.put("t5", iRowSet.getBigDecimal("t5") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t5"));//住房公积金
- map.put("t6", iRowSet.getBigDecimal("t6") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t6"));//累计子女教育
- map.put("t7", iRowSet.getBigDecimal("t7") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t7"));//累计继续教育
- map.put("t8", iRowSet.getBigDecimal("t8") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t8"));//累计住房贷款利息
- map.put("t9", iRowSet.getBigDecimal("t9") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t9"));//累计住房租金
- map.put("t10", iRowSet.getBigDecimal("t10") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t10"));//累计赡养老人
- map.put("t25", iRowSet.getBigDecimal("t25") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t25"));//本期收入
- map.put("t11", iRowSet.getBigDecimal("t11") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t11"));//其他
- map.put("t15", iRowSet.getBigDecimal("t15") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t15"));//本期累计收入
- map.put("t20", iRowSet.getBigDecimal("t20") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t20"));//本期累计免税收入
- map.put("t22", iRowSet.getBigDecimal("t22") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t22"));//累计减除费用
- map.put("t24", iRowSet.getBigDecimal("t24") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t24"));//累计专项扣除
- map.put("t26", iRowSet.getBigDecimal("t26") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t26"));//累计其他扣除
- map.put("t28", iRowSet.getBigDecimal("t28") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t28"));//累计准予扣除的捐赠
- map.put("t29", iRowSet.getBigDecimal("t29") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t29"));//累计应纳税所得额
- map.put("t30", iRowSet.getBigDecimal("t30") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t30"));//税率
- map.put("t31", iRowSet.getBigDecimal("t31") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t31"));//速算扣除数
- map.put("t32", iRowSet.getBigDecimal("t32") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t32"));//累计应纳税额
- map.put("t33", iRowSet.getBigDecimal("t33") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t33"));//累计减免税额
- map.put("t34", iRowSet.getBigDecimal("t34") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t34"));//累计应扣缴税额
- map.put("t35", iRowSet.getBigDecimal("t35") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t35"));//累计已预缴税额
- map.put("t36", iRowSet.getBigDecimal("t36") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t36"));//本期应补(退)税额
- map.put("t38", iRowSet.getBigDecimal("t38") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t38"));//备注
- map.put("t41", iRowSet.getBigDecimal("t41") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t41"));//累计婴幼儿照护费用
- map.put("t45", iRowSet.getBigDecimal("t45") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("t45"));//累计个人养老金
- list.add(map);
- }
- return list;
- }
- /**
- * 查询个税申报人员数据
- *
- * @param batchNo
- * @return
- */
- public String getSql(String batchNo) {
- StringBuilder sb = new StringBuilder();
- sb.append("select").append("\n");
- sb.append(" taxCalConfigDetail.FPERSONID as personId,").append("\n");
- sb.append(" taxCalConfigDetail.FTAXUNITID as taxunitId,").append("\n");
- sb.append("taxCalConfigDetail.FPERIODBEGIN as periodbegin,\n").append("\n");
- sb.append("taxCalConfigDetail.FPERIODEND as periodend,\n").append("\n");
- sb.append("taxCalConfigDetail.FINCOMEITEMID as incomeitmemId,\n").append("\n");
- sb.append(" t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t15,t20,t22,t24,t25,t26,t28,t29,t30,t31,t32,t33,t34,t35,t36,t38,t41,t45,t46\n").append("\n");
- sb.append(" from T_HR_STaxCalConfigDetail taxCalConfigDetail\n").append("\n");
- sb.append("where").append("\n");
- sb.append("FBATCHNO = '").append(batchNo).append("'").append("\n");
- return sb.toString();
- }
- }
|