package com.kingdee.eas.custom.compensation.handler; import cn.com.servyou.dto.ApiResponse; import cn.com.servyou.dto.AsyncResult; import cn.com.servyou.dto.declare.CompanyDeclareRequest; import cn.com.servyou.dto.declare.DeclareCancelRequest; import cn.com.servyou.dto.declare.DeclareCorrectRequest; import cn.com.servyou.dto.tax.*; import cn.com.servyou.rmi.client.ClientProxyFactory; import cn.com.servyou.service.DeclarationRequest; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.dao.ormapping.impl.ImplUtils; import com.kingdee.bos.metadata.entity.*; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.bos.util.EASResource; import com.kingdee.eas.basedata.hraux.NationalityInfo; import com.kingdee.eas.basedata.person.PersonCollection; 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.task.TaskCatalogEnum; import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade; import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory; import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils; import com.kingdee.eas.util.app.DbUtil; import com.kingdee.jdbc.rowset.IRowSet; import com.kingdee.jdbc.rowset.IRowSetMetaData; import com.kingdee.shr.base.syssetting.context.SHRContext; import com.kingdee.shr.base.syssetting.exception.SHRWebException; import com.kingdee.shr.base.syssetting.exception.ShrWebBizException; import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil; import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5; import com.kingdee.shr.base.syssetting.web.json.JSONUtils; import com.kingdee.shr.base.syssetting.web.util.UserUtil; import com.kingdee.shr.compensation.TaxDeclareStatusEnum; import com.kingdee.shr.compensation.TbTypeEnum; import com.kingdee.shr.compensation.app.incomeTax.ITaxPersonRecordEntry; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryCollection; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryFactory; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryInfo; import com.kingdee.shr.compensation.app.tax.*; import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo; import com.kingdee.shr.compensation.app.taxCal.*; import com.kingdee.shr.compensation.helper.CmpConstants; import com.kingdee.shr.compensation.taxCal.util.TaxCalcFileUtils; import com.kingdee.shr.compensation.util.*; import com.kingdee.shr.compensation.web.handler.tax.IncomeTaxDeclareListHandler; import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclarExcelRowDTO; import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclareDTO; import com.kingdee.util.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.*; import org.springframework.ui.ModelMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Type; import java.math.BigDecimal; import java.net.URLEncoder; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.*; /** * @author qingwu * @date 2024/9/18 * @apiNote 个税申报扩展 */ public class IncomeTaxDeclareListHandlerEx extends IncomeTaxDeclareListHandler { private static final Logger LOG = Logger.getLogger(IncomeTaxDeclareListHandlerEx.class); private Context ctx = SHRContext.getInstance().getContext(); private ObjectMapper mapper = new ObjectMapper(); /** * 个税申报 * * @param request * @param response * @param modelMap */ @Override public void taxDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, SHRWebException { LOG.error("taxDeclareAction-----------start-----------"); Context ctx = SHRContext.getInstance().getContext(); try { boolean isHaveTaxService = CmpTaxUtil.isHaveTaxService(ctx); if (!isHaveTaxService) { throw new ShrWebBizException(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label136", ctx.getLocale())); } else { String selectedId = request.getParameter("selectedId"); Map resultMap = new HashMap(); Map declareData = this.getDeclareData(ctx, selectedId); Map paramMap = new HashMap(); paramMap.put("declaData", declareData.get("WATI_TO_DECLARE")); LOG.error("paramMap-----------" + paramMap); try { //纳税单位 List advanceDeclareInfo = (List) declareData.get("advanceDeclareInfo"); LOG.error("advanceDeclareInfo------------" + advanceDeclareInfo); if (!advanceDeclareInfo.isEmpty()) { throw new ShrWebBizException(this.combineError(advanceDeclareInfo)); } //个税审批 审批状态=审批通过的数据 List waitToDeclareList = (List) paramMap.get("declaData"); if (waitToDeclareList.size() <= 0) { resultMap.put("success", false); resultMap.put("excel", ""); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", true); resultMap.put("info", "不可重复声申报!!"); JSONUtils.SUCCESS(resultMap); return; } //检查纳税申报数据 Map checkResultMap = this.checkTaxDeclareData(ctx, request, waitToDeclareList); Boolean hasErr = (Boolean) checkResultMap.get("hasErrData"); if (hasErr != null && hasErr) { resultMap.put("success", false); resultMap.put("excel", checkResultMap.get("excel")); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", true); resultMap.put("info", ""); JSONUtils.SUCCESS(resultMap); return; } String errMsg = this.checkTaxCalStatus(ctx, waitToDeclareList); if (null != errMsg) { resultMap.put("success", false); resultMap.put("dataError", true); resultMap.put("errMsg", errMsg); JSONUtils.SUCCESS(resultMap); return; } checkResultMap = this.checkIncomeTaxIssue(ctx, waitToDeclareList); if (checkResultMap != null) { checkResultMap.put("success", false); JSONUtils.SUCCESS(checkResultMap); return; } //errMsg = this.checkReductionItems(ctx, waitToDeclareList); //if (null != errMsg) { // resultMap.put("success", false); // resultMap.put("reductionError", true); // resultMap.put("errMsg", errMsg); // JSONUtils.SUCCESS(resultMap); // return; //} //Map taxDeclareResult = IncomeTaxDeclareFacadeFactory.getLocalInstance(ctx).taxDeclare(paramMap); //调佣税友纳税申报 Map taxDeclareResult = callShuiYouTaxDeclare(paramMap); Boolean isSuccess = (Boolean) taxDeclareResult.get("success"); resultMap.put("success", isSuccess); resultMap.put("excel", ""); resultMap.put("hasErrData", !isSuccess); resultMap.put("hasCheckDataErr", false); resultMap.put("info", declareData.get("info")); } catch (Exception var17) { var17.printStackTrace(); LOG.error(var17.getMessage(), var17); resultMap.put("success", false); resultMap.put("excel", ""); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", false); resultMap.put("info", declareData.get("info")); resultMap.put("errorMsg", var17.getMessage()); } LOG.error("taxDeclareAction-----------end-----------"); JSONUtils.SUCCESS(resultMap); } } catch (JsonProcessingException e) { e.printStackTrace(); throw new RuntimeException(e); } } /** * 调佣税友纳税申报 * * @param paramMap * @return */ public Map callShuiYouTaxDeclare(Map paramMap) { LOG.error("callShuiYouTaxDeclare--------------------paramMap" + paramMap); Map resultMap = new HashMap(); resultMap.put("success", true); resultMap.put("msg", ""); List waitToDeclareList = (List) paramMap.get("declaData"); Map requestParamMap = new HashMap(); List paramList = new ArrayList(); try { if (waitToDeclareList != null && waitToDeclareList.size() > 0) { for (int i = 0; i < waitToDeclareList.size(); i++) { IncomeTaxDeclarInfo taxDeclarInfo = waitToDeclareList.get(i); JSONObject param = new JSONObject(); param.put("taxDeclarId", taxDeclarInfo.getId()); param.put("taxDeclarBatchNo", taxDeclarInfo.getBatchNo()); //纳税单位 TaxUnitInfo taxUnitInfo = taxDeclarInfo.getTaxUnit(); //客户端代理工厂 ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory(); //算税请求接口 DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest(); //获取请求参数 CompanyDeclareRequest declareRequestParameter = getDeclareRequestParameter(taxUnitInfo, taxDeclarInfo); LOG.error("declareRequestParameter-----------------" + mapper.writeValueAsString(declareRequestParameter)); ApiResponse apiResponse = declarationRequest.send(declareRequestParameter); LOG.error("asyncResultApiResponse-----getCode-------" + apiResponse.getHead().getCode()); LOG.error("asyncResultApiResponse-----getMsg--------" + apiResponse.getHead().getMsg()); resultMap.put("msg", mapper.writeValueAsString(declareRequestParameter)); if (apiResponse.getHead().getCode().equals("00000000")) { AsyncResult body = apiResponse.getBody(); String requestId = body.getRequestId(); LOG.error("requestId-----" + requestId); LOG.error("apiResponse-----" + mapper.writeValueAsString(apiResponse)); //查询反算反馈结果 ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx); //backTask(url,requestId,回调osf服务,自定义参数,任务类型) //isyUtilsFacade.backTask(isyUtilsFacade.getConfig().get("ip") + "/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback", requestId, "synIndividualIncomeTaxService", jsonObject.toString(), TaskCatalogEnum.CAL_GET); JSONObject json = new JSONObject(); json.put("requestId", requestId); json.put("param", param.toString()); isyUtilsFacade.addTask("synIncomeTaxDeclareService", json.toJSONString(), TaskCatalogEnum.TAX, ""); } } } } catch (Exception e) { e.printStackTrace(); resultMap.put("success", false); resultMap.put("msg", e.getMessage()); return resultMap; } return resultMap; } /** * 获取请求参数 * 注意: * 1.解除劳动合同一次性补偿金、全年一次性奖金所得,不能单独申报,需要同正常工资薪金一起申报。 * 2.解除劳动合同一次性补偿金、稿酬所得,由于税务规则需要,解除劳动合同一次性补偿金、稿酬所得必须填写免税附表。 * * @param taxUnitInfo * @param taxDeclarInfo * @return */ private CompanyDeclareRequest getDeclareRequestParameter(TaxUnitInfo taxUnitInfo, IncomeTaxDeclarInfo taxDeclarInfo ) throws BOSException, JsonProcessingException, EASBizException, SQLException { LOG.error("getDeclareRequestParameter-----------taxDeclarInfo-----" + taxDeclarInfo); CompanyDeclareRequest declareRequestPara = new CompanyDeclareRequest(); Map requestParamMap = new HashMap(); //随机id String bizNo = UUID.randomUUID().toString(); LOG.error("bizNo:" + bizNo); //外部业务订单号* declareRequestPara.setBizNo(bizNo); //企业名称* declareRequestPara.setName(taxUnitInfo.getName()); //税号* declareRequestPara.setTaxNo(taxUnitInfo.getTaxNumber()); //行政区划代码* declareRequestPara.setArea(taxUnitInfo.getAreaCode()); //登记序号 declareRequestPara.setRegistrationNumber(taxUnitInfo.getRegNumber()); String declPassword = taxUnitInfo.getDeclPassword(); if (StringUtils.isEmpty(declPassword)) { throw new BOSException("申报密码不能为空!"); } declareRequestPara.setDeclarePassword(Base64Utils.decode(declPassword)); //所得月份 String yearMonth = taxDeclarInfo.getYearMonth(); String replaceYearMonth = yearMonth.replace("-", ""); LOG.error("replaceYearMonth----------------" + replaceYearMonth); //税款所属期YYYYMM* declareRequestPara.setMonth(replaceYearMonth); //总金额 //BigDecimal totalMoney = taxDeclarInfo.getTotalMoney(); //应退税额 //BigDecimal taxRebate = taxDeclarInfo.getTaxRebate(); //总人数 //long totalPerson = taxDeclarInfo.getTotalPerson(); //申报表分类 1=预扣预缴申报表 2=分类所得申报表 3=非居民所得申报表 //String tbTble = taxDeclarInfo.getTbType().getValue(); //纳税单位ID //String taxUnitId = taxUnitInfo.getId().toString(); //Map tbTypeMap = new HashMap(); //if (totalMoney.compareTo(BigDecimal.ZERO) == 0) { // tbTypeMap.put("zje", 0.0); //} else { // tbTypeMap.put("zje", totalMoney); //} // //if (taxRebate.compareTo(BigDecimal.ZERO) == 0) { // tbTypeMap.put("ynse", 0.0); //} else { // tbTypeMap.put("ynse", taxRebate); //} //tbTypeMap.put("zrs", totalPerson); //Map dataMap = new HashMap(); //if ("1".equals(tbTble)) { // dataMap.put("ykyj", tbTypeMap); //} else if ("2".equals(tbTble)) { // dataMap.put("flsd", tbTypeMap); //} else if ("3".equals(tbTble)) { // dataMap.put("fjm", tbTypeMap); //} //密码类型* declareRequestPara.setPasswordType("0"); //离职日期处理策略 1、不传或传1,代表离职日期自动清空,即人员状态由“非正常”变更为“正常”时,离职日期字段自动清空,默认逻辑。 //2、传2离职日期不自动清空,即人员状态由“非正常”变更为“正常”时,离职日期不自动清空,客户如需清空需对离职日期字段传入空字符串。 //declareRequestPara.setResignDateStrategy(); //批次号 String batchNo = taxDeclarInfo.getBatchNo(); LOG.error("taxCalConfigDetailCollection--------taxDeclarInfo---------" + taxDeclarInfo); //个税应用+税款计算最终拆分明细表 ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx); TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + batchNo + "' and state = '20'"); LOG.error("taxCalConfigDetailCollection-----------------" + taxCalConfigDetailCollection.size()); //员工信息ID Set personIds = new HashSet(); //综合所得对象 ComplexIncomeRequest complexIncomeRequest = new ComplexIncomeRequest(); //正常工资薪金对象 NormalSalarySpecIncome normalSalarySpecIncome = new NormalSalarySpecIncome(); //正常工资薪金列表 List normalSalarySpec = new ArrayList(); //全年一次性奖金收入 List annualOneTimeBonusIncome = new ArrayList(); //全年一次性奖金收入 List laborRemunerationIncome = new ArrayList(); if (taxCalConfigDetailCollection.size() > 0) { for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) { TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i); //员工信息 PersonInfo personInfo = taxCalConfigDetailInfo.getPerson(); personIds.add(personInfo.getId().toString()); //所得项目 TaxIncomeItemInfo incomeItem = taxCalConfigDetailInfo.getIncomeItem(); //本期收入 Integer sre = null; String getSreSql = "select t1 from T_HR_STaxCalConfigDetail where fid ='" + taxCalConfigDetailInfo.getId().toString() + "'"; IRowSet iRowSet = DbUtil.executeQuery(ctx, getSreSql); while (iRowSet.next()) { sre = iRowSet.getInt("t1"); } LOG.error("incomeItem-----------------" + incomeItem); //所属项目名称 String incomeItemName = incomeItem.getName(); //所属项目编码 String incomeItemNumber = incomeItem.getNumber(); //正常工资薪金 if ("zcgzxjlb".equals(incomeItemNumber)) { //getComplexIncome(员工信息对象 ,所属项目,本期收入) normalSalarySpec.add(getComplexIncome(personInfo, incomeItemName, sre)); //正常工资薪金列表 保存数据 normalSalarySpecIncome.setNormalSalarySpec(normalSalarySpec); LOG.error("normalSalarySpecIncome-----------------" + mapper.writeValueAsString(normalSalarySpecIncome)); complexIncomeRequest.setNormalSalarySpecIncome(normalSalarySpecIncome); } //全年一次性奖金收入 if ("qnycxjjlb".equals(incomeItemNumber)) { annualOneTimeBonusIncome.add(getComplexIncome(personInfo, incomeItemName, sre)); LOG.error("annualOneTimeBonusIncome-----------------" + mapper.writeValueAsString(annualOneTimeBonusIncome)); LOG.error("annualOneTimeBonusIncome-----------------" + annualOneTimeBonusIncome); LOG.error("annualOneTimeBonusIncome.size()-----------------" + annualOneTimeBonusIncome.size()); //全年一次性奖金收入 保存数据 complexIncomeRequest.setAnnualOneTimeBonusIncome(annualOneTimeBonusIncome); } //一般劳务报酬所得 if ("lwbclb".equals(incomeItemNumber)) { laborRemunerationIncome.add(getComplexIncome(personInfo, incomeItemName, sre)); LOG.error("laborRemunerationIncome-----------------" + mapper.writeValueAsString(laborRemunerationIncome)); //一般劳务报酬所得 保存数据 complexIncomeRequest.setLaborRemunerationIncome(laborRemunerationIncome); } } } //综合所得 declareRequestPara.setComplexIncomeRequest(complexIncomeRequest); //企业员工列表 List companyEmployeeList = getCompanyEmployeeList(personIds); declareRequestPara.setCompanyEmployeeList(companyEmployeeList); LOG.error("companyEmployeeList-----------------" + mapper.writeValueAsString(companyEmployeeList)); return declareRequestPara; } /*** * 员工 * @return */ private ComplexIncome getComplexIncome(PersonInfo personInfo, String incomeItemName, Integer sre) { ComplexIncome complexIncome = new ComplexIncome(); //姓名 complexIncome.setName(personInfo.getName()); //居民身份证 if (personInfo.getIdCardNO() != null) { //证照号码 complexIncome.setLicenseNumber(personInfo.getIdCardNO()); //证照类型 complexIncome.setLicenseType("居民身份证"); } //中国护照不 if (personInfo.getPassportNO() != null) { //证照类型 complexIncome.setLicenseType("中国护照"); //证照号码 complexIncome.setLicenseNumber(personInfo.getPassportNO()); } //收入额 complexIncome.setIncome(new BigDecimal(sre)); complexIncome.setIncomeItemName(incomeItemName); return complexIncome; } /** * 企业员工列表* * * @return */ private List getCompanyEmployeeList(Set personIds) throws BOSException, EASBizException { List companyEmployeeList = new ArrayList(); SelectorItemCollection sic = new SelectorItemCollection(); sic.add("*"); FilterInfo filterInfo = new FilterInfo(); filterInfo.getFilterItems().add(new FilterItemInfo("id", personIds, CompareType.INCLUDE)); EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null); //获取人员数据 PersonCollection personCollection = PersonFactory.getLocalInstance(ctx).getPersonCollection(entityViewInfo); if (personCollection.size() > 0) { for (int i = 0; i < personCollection.size(); i++) { PersonInfo personInfo = personCollection.get(i); companyEmployeeList.add(getDetailCompanyEmployee(personInfo)); } } return companyEmployeeList; } /** * 人员 * * @return */ public DetailCompanyEmployee getDetailCompanyEmployee(PersonInfo personInfo) throws BOSException, EASBizException { //人员对象 DetailCompanyEmployee detailCompanyEmployee = new DetailCompanyEmployee(); ////姓名 //detailCompanyEmployee.setName("何云"); ////证件类型 //detailCompanyEmployee.setLicenseType("居民身份证"); ////证照号码 //detailCompanyEmployee.setLicenseNumber("429004198601085125"); //姓名 detailCompanyEmployee.setName(personInfo.getName()); //complexIncome.setName("何云"); //居民身份证 if (personInfo.getIdCardNO() != null) { //证照号码 detailCompanyEmployee.setLicenseNumber(personInfo.getIdCardNO()); //证照类型 detailCompanyEmployee.setLicenseType("居民身份证"); //人员地区 detailCompanyEmployee.setArea("境内"); } //中国护照 if (personInfo.getPassportNO() != null) { //证照类型 detailCompanyEmployee.setLicenseType("中国护照"); //证照号码 detailCompanyEmployee.setLicenseNumber(personInfo.getPassportNO()); //人员地区 detailCompanyEmployee.setArea("境外"); } //电话号码 detailCompanyEmployee.setPhone(personInfo.getCell()); //人员状态 detailCompanyEmployee.setState(personInfo.getEmployeeType().getName()); //人员报税信息->任职受雇从业信息 ITaxPersonRecordEntry iTaxPersonRecordEntry = TaxPersonRecordEntryFactory.getLocalInstance(ctx); TaxPersonRecordEntryCollection taxPersonRecordEntryCollection = iTaxPersonRecordEntry.getTaxPersonRecordEntryCollection("where person.id = '" + personInfo.getId() + "'"); TaxPersonRecordEntryInfo taxPersonRecordEntryInfo = taxPersonRecordEntryCollection.get(0); //任职受雇类型 可选择雇员、保险营销员、证券经纪人、其他、实习学生(全日制学历教育) //detailCompanyEmployee.setIsEmployee("其他"); detailCompanyEmployee.setIsEmployee(taxPersonRecordEntryInfo.getEmployedType().getAlias()); //受雇日期 YYYY-MM-DD,不能大于当前时间,任职受雇类型选择雇员、保险营销员、证券经纪人时必录 SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); detailCompanyEmployee.setEmployedDate(inputFormat.format(taxPersonRecordEntryInfo.getEmployedDate())); //性别 detailCompanyEmployee.setGender(personInfo.getGender().getAlias()); //出生日期 detailCompanyEmployee.setBirthday(inputFormat.format(personInfo.getBirthday())); //国籍 nationality NationalityInfo nationality = personInfo.getNationality(); detailCompanyEmployee.setNationality(nationality.getName()); return detailCompanyEmployee; } private String getCheckSqlByType(Map incomeIdMap, String taxUnitId, String yearMonth, TbTypeEnum typeEnum) { StringBuilder sqlBuf = new StringBuilder(); sqlBuf.append(" SELECT distinct tx.FTAXUNITID,t1.Fname_l2 as TAXNAME,p1.FNUMBER,p1.Fname_l2 as PERSONNAME, ti.fIncomeCode "); sqlBuf.append(" FROM T_HR_STaxCalConfigDetail tx "); sqlBuf.append(" left join T_HR_TAXUNIT as t1 on t1.fid = tx.FTaxUnitID "); sqlBuf.append(" left join T_BD_PERSON as p1 on p1.fid = tx.FPersonId "); sqlBuf.append(" left join t_hr_sTaxIncomeItem as ti on tx.fIncomeItemId = ti.fid "); String dateFilter = CmpSQLUtil.generateSqlDateFilter("tx.FPeriodBegin", "tx.FPeriodEnd", yearMonth); sqlBuf.append(" where ").append(dateFilter); sqlBuf.append(" and tx.FTAXUNITID='").append(taxUnitId).append("'"); sqlBuf.append(" and tx.FSTATE=10"); sqlBuf.append(" and tx.FIsLast=1"); sqlBuf.append(" and tx.FIncomeItemId in ").append(incomeIdMap.get(typeEnum.getValue())); return sqlBuf.toString(); } //private Map checkTaxDeclareData(Context ctx, List waitToDeclareList) throws BOSException { // Map checkDataResultMap = new HashMap(); // return null; //} private Map checkTaxDeclareData(Context ctx, HttpServletRequest request, List waitToDeclareList) throws BOSException, SQLException, ShrWebBizException { Map checkDataResultMap = new HashMap(); boolean hasErrData = false; if (waitToDeclareList != null && waitToDeclareList.size() > 0) { List preCheckSql = new ArrayList(); List specCheckForPre = new ArrayList(); List notPersonCheckSql = new ArrayList(); List classifyCheckSql = new ArrayList(); Map incomeIdMap = new HashMap(); incomeIdMap.put("1", CmpTaxUtil.genIncomeItemId(ctx, "1")); incomeIdMap.put("2", CmpTaxUtil.genIncomeItemId(ctx, "2")); incomeIdMap.put("3", CmpTaxUtil.genIncomeItemId(ctx, "3")); Iterator i$ = waitToDeclareList.iterator(); String yearMonth; while (i$.hasNext()) { IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next(); TbTypeEnum tbType = declareInfo.getTbType(); String taxUnitId = declareInfo.getTaxUnit().getId().toString(); yearMonth = declareInfo.getYearMonth(); if (tbType != null) { if ("1".equals(tbType.getValue())) { preCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0701)); specCheckForPre.add(this.getPreCheckSql(declareInfo)); } else if ("3".equals(tbType.getValue())) { notPersonCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0703)); } else { classifyCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0702)); } } } Map reasonOperaMap = new HashMap(); reasonOperaMap.put("noCalDataReson", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label140", ctx.getLocale())); reasonOperaMap.put("noCalDataOper", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label141", ctx.getLocale())); reasonOperaMap.put("preDataReason", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label142", ctx.getLocale())); reasonOperaMap.put("preDataOpera", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label143", ctx.getLocale())); List taxDeclareExcelRowDTOS = new ArrayList(); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, preCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0701)); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, classifyCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0702)); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, notPersonCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0703)); String filePath = ""; if (taxDeclareExcelRowDTOS.size() > 0) { hasErrData = true; HSSFWorkbook workbook = new HSSFWorkbook(); yearMonth = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label144", ctx.getLocale()); this.fillTitle(ctx, workbook, yearMonth.split(",")); this.fillWorkdBookData(workbook, taxDeclareExcelRowDTOS); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); File dir = new File(UserUtil.getUserTempDirAbsolutePath(request.getSession())); if (!dir.exists()) { dir.mkdirs(); } String fileName = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label145", ctx.getLocale()) + "_" + format.format(new Date()) + ".xls"; String realFileName = MD5.md5Hash(fileName); File file = new File(dir, realFileName); FileOutputStream out = null; try { out = new FileOutputStream(file); workbook.write(out); out.flush(); } catch (FileNotFoundException var33) { LOG.error(var33.getMessage(), var33); } catch (IOException var34) { LOG.error(var34.getMessage(), var34); } finally { if (out != null) { try { out.close(); } catch (IOException var32) { LOG.error(var32.getMessage(), var32); } } } Map params = new HashMap(); params.put("method", "tmp"); params.put("file", realFileName); params.put("filename", fileName); filePath = DynamicUtil.assembleUrl("/downloadfile.do", params); } checkDataResultMap.put("excel", filePath); } checkDataResultMap.put("hasErrData", hasErrData); return checkDataResultMap; } private void fillTitle(Context ctx, HSSFWorkbook workbook, String[] titleArr) { HSSFSheet sheet = workbook.createSheet(); HSSFRow createRow = sheet.createRow(0); HSSFCell infoCell = createRow.createCell(0); infoCell.setCellValue(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label146", ctx.getLocale())); sheet.setColumnWidth(0, 12800); createRow = sheet.createRow(1); HSSFFont font = workbook.createFont(); font.setColor((short) 8); font.setFontHeightInPoints((short) 12); font.setBoldweight((short) 700); HSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); style.setAlignment((short) 2); style.setVerticalAlignment((short) 1); if (titleArr != null && titleArr.length > 0) { for (int i = 0; i < titleArr.length; ++i) { HSSFCell cell = createRow.createCell(i); cell.setCellStyle(style); cell.setCellValue(titleArr[i]); if (i > 3) { sheet.setColumnWidth(i, 15360); } else { sheet.setColumnWidth(i, 7680); } } } } private void fillWorkdBookData(HSSFWorkbook workbook, List dataList) { HSSFSheet sheet = workbook.getSheetAt(0); if (dataList != null && dataList.size() > 0) { for (int i = 0; i < dataList.size(); ++i) { HSSFRow row = sheet.createRow(i + 2); TaxDeclarExcelRowDTO excelRowDTO = (TaxDeclarExcelRowDTO) dataList.get(i); HSSFCell cell = row.createCell(0); cell.setCellValue(excelRowDTO.getPersonNum()); cell = row.createCell(1); cell.setCellValue(excelRowDTO.getPersonName()); cell = row.createCell(2); cell.setCellValue(excelRowDTO.getTaxName()); cell = row.createCell(3); cell.setCellValue(excelRowDTO.getDeclarType()); cell = row.createCell(4); cell.setCellValue(excelRowDTO.getReason()); cell = row.createCell(5); cell.setCellValue(excelRowDTO.getOperation()); } } } private String getSqlDateFilterLqDate(String dateStr) { String[] beginDateArr = dateStr.split("-"); Calendar calendar = Calendar.getInstance(); calendar.set(Integer.parseInt(beginDateArr[0]), Integer.parseInt(beginDateArr[1]) - 1, 1, 0, 0, 0); Date beginDate = calendar.getTime(); return CmpDateUtil.toKSqlDate(beginDate); } private List getExceptData(Context ctx, List preCheckSql, List specCheckForPre, Map noCalDataOper, TbTypeEnum typeEnum) throws BOSException, SQLException, ShrWebBizException { List taxDeclarExcelRowDTOS = new ArrayList(); Iterator i$; String s; IRowSet rowSet; TaxDeclarExcelRowDTO taxDeclareExcelRow; if (preCheckSql != null && preCheckSql.size() > 0) { i$ = preCheckSql.iterator(); while (i$.hasNext()) { s = (String) i$.next(); rowSet = DbUtil.executeQuery(ctx, s); while (rowSet.next()) { taxDeclareExcelRow = new TaxDeclarExcelRowDTO(); taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER")); taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME")); String taxUnitName = rowSet.getString("TAXNAME"); taxDeclareExcelRow.setTaxName(taxUnitName); taxDeclareExcelRow.setDeclarType(typeEnum.getAlias()); taxDeclareExcelRow.setReason((String) noCalDataOper.get("noCalDataReson")); taxDeclareExcelRow.setOperation((String) noCalDataOper.get("noCalDataOper")); String incomeCode = (String) noCalDataOper.get("fIncomeCode"); taxDeclarExcelRowDTOS.add(taxDeclareExcelRow); } } } if ("1".equals(typeEnum.getValue()) && specCheckForPre != null && specCheckForPre.size() > 0) { i$ = specCheckForPre.iterator(); while (i$.hasNext()) { s = (String) i$.next(); rowSet = DbUtil.executeQuery(ctx, s); while (rowSet.next()) { taxDeclareExcelRow = new TaxDeclarExcelRowDTO(); taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER")); taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME")); taxDeclareExcelRow.setTaxName(rowSet.getString("TAXNAME")); taxDeclareExcelRow.setDeclarType(typeEnum.getAlias()); taxDeclareExcelRow.setReason((String) noCalDataOper.get("preDataReason")); taxDeclareExcelRow.setOperation((String) noCalDataOper.get("preDataOpera")); taxDeclarExcelRowDTOS.add(taxDeclareExcelRow); } } } return taxDeclarExcelRowDTOS; } private String getPreCheckSql(IncomeTaxDeclarInfo incomeTaxDeclarInfo) { StringBuilder sqlBuf = new StringBuilder(); String yearMonth = incomeTaxDeclarInfo.getYearMonth(); String taxUnitId = incomeTaxDeclarInfo.getTaxUnit().getId().toString(); String sql = "select FPersonID from T_HR_STaxCalConfigDetail where FTaxUnitId='" + taxUnitId + "' and FPeriodBegin = " + CmpDateUtil.toKSqlDate(incomeTaxDeclarInfo.getYearMonthDate()); sqlBuf.append(" SELECT distinct ent.FTAXUNITID, t.Fname_l2 as TAXNAME, p.FNUMBER, p.Fname_l2 as PERSONNAME "); sqlBuf.append(" FROM T_HR_STaxPersonRecordEntry ent "); sqlBuf.append(" left join T_HR_TAXUNIT as t on t.fid = ent.FTaxUnitID "); sqlBuf.append(" left join T_BD_PERSON as p on p.fid = ent.FPersonId "); sqlBuf.append(" where ent.FSubmitStatus='2' and ent.FPersonStatus='1' "); sqlBuf.append(" and ent.FTaxUnitID='").append(taxUnitId).append("'"); sqlBuf.append(" and ent.FENDDATE <=").append(this.getSqlDateFilterLqDate(yearMonth)); sqlBuf.append(" and ent.FPersonID not in ( ").append(sql).append(" )"); return sqlBuf.toString(); } private Map checkIncomeTaxIssue(Context ctx, List waitToDeclareList) throws BOSException { StringBuilder taxUnitIds = new StringBuilder(); IncomeTaxDeclarInfo declareInfo; for (Iterator i$ = waitToDeclareList.iterator(); i$.hasNext(); taxUnitIds.append(declareInfo.getTaxUnit().getId().toString())) { declareInfo = (IncomeTaxDeclarInfo) i$.next(); if (taxUnitIds.length() > 0) { taxUnitIds.append(","); } } String oql = "select person.person.name where taxUnit.id in " + CmpStrUtil.buildInSql(taxUnitIds.toString()) + " and result = " + 1 + " and status = " + 2 + " and inviteStatus = " + 0; IncomeTaxIssueCollection collection = IncomeTaxIssueFactory.getLocalInstance(ctx).getIncomeTaxIssueCollection(oql); if (collection != null && !collection.isEmpty()) { StringBuilder errMsg = new StringBuilder(); for (int i = 0; i < collection.size() && i != 5; ++i) { if (errMsg.length() > 0) { errMsg.append(","); } errMsg.append("[").append(collection.get(i).getPerson().getPerson().getName()).append("]"); } Map map = new HashMap(); map.put("errMsg", "以下员工存在申诉属实争议,且未进行邀请确认,需要进行发送邀请确认后才可进行个税申报或者进行非正常人员报送(更新人员报税信息中的人员状态为非正常,并进行人员报送成功),员工姓名:" + errMsg.toString() + ",选择[是]则跳转到[申诉争议-申诉属实人员]列表,选择[否]则跳转到[人员报税信息]列表。"); map.put("issueError", true); return map; } else { return null; } } private String checkTaxCalStatus(Context ctx, List waitToDeclareList) throws SHRWebException { String sql = "select t.fState, u.fName_l2 taxUnitName, d.fIncomeItemId from t_hr_sTaxCalConfigDetail d left join t_hr_sTaxCalInitDetail t on d.fCmpCalTableId = t.fCmpCalTableId and d.fIncomeItemId = t.fIncomeItemId left join t_hr_taxUnit u on d.fTaxUnitId = u.fid where d.fTaxUnitId = ? and d.fPeriodBegin = ?"; try { Iterator i$ = waitToDeclareList.iterator(); boolean isTaxCalFinished; String taxUnitName; do { if (!i$.hasNext()) { return null; } IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next(); String taxUnitId = declareInfo.getTaxUnit().getId().toString(); Date periodDate = declareInfo.getYearMonthDate(); Object[] param = new Object[]{taxUnitId, CmpDateUtil.toSqlDate(periodDate)}; IRowSet rs = DbUtil.executeQuery(ctx, sql, param); boolean havingSalaryIncome = false; isTaxCalFinished = true; taxUnitName = ""; while (rs.next()) { int state = rs.getInt("fState"); taxUnitName = rs.getString("taxUnitName"); String incomeItemId = rs.getString("fIncomeItemId"); if (state != 40) { isTaxCalFinished = false; } if ("8r0AAABCg2PDiOoP".equals(incomeItemId)) { havingSalaryIncome = true; } } TbTypeEnum typeEnum = declareInfo.getTbType(); if (!havingSalaryIncome && typeEnum == TbTypeEnum.SB0701) { return "纳税单位[" + taxUnitName + "]当期预扣预缴申报表未包含所得项目为正常工资薪金所得的员工,不允许申报,请确认"; } } while (isTaxCalFinished); return "纳税单位【" + taxUnitName + "】存在接口算税未完成的数据,请确认"; } catch (Exception var15) { LOG.error("checkTaxCalStatus error: ", var15); throw new SHRWebException(var15.getMessage()); } } /** * 异常提醒 * * @param advanceDeclareInfo * @return */ private String combineError(List advanceDeclareInfo) { StringBuilder error = new StringBuilder(); error.append("以下纳税单位尚未到申报时间,请不要提前申报:"); Iterator i$ = advanceDeclareInfo.iterator(); while (i$.hasNext()) { String taxUnitInfo = (String) i$.next(); if (advanceDeclareInfo.indexOf(taxUnitInfo) == 5) { error.append("..."); break; } if (advanceDeclareInfo.indexOf(taxUnitInfo) > 0) { error.append(","); } String[] arr = taxUnitInfo.split("_"); error.append(arr[0]).append("【").append(arr[1]).append("】"); } return error.toString(); } /** * 获取个税申报审批通过数据 * * @param ctx * @param selectedId * @return * @throws BOSException */ private Map getDeclareData(Context ctx, String selectedId) throws BOSException, JsonProcessingException { Map resultMap = new HashMap(); List declaredList = new ArrayList(); List waitToDeclareList = new ArrayList(); String sqlInString = CmpUtils.spiltToSqlString(selectedId); if (StringUtils.isEmpty(sqlInString)) { sqlInString = "''"; } String currentYearMonth = CmpDateUtil.getDateStr(new Date(), "yyyy-MM"); String oqlBuffer = "select id,yearMonth,totalPerson,totalMoney,taxRebate,declareStatus,versionCode,yearMonthDate,tbType,taxUnit.id,taxUnit.name,taxUnit.taxNumber,taxUnit.regNumber,taxUnit.areaCode,taxUnit.declPassword, batchNo where id in ( " + sqlInString + " )"; LOG.error("getDeclareData----------oqlBuffer------" + oqlBuffer); IncomeTaxDeclarCollection declareCollection = IncomeTaxDeclarFactory.getLocalInstance(ctx).getIncomeTaxDeclarCollection(oqlBuffer); LOG.error("getDeclareData----------declareCollection------" + declareCollection.size()); String ms1 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label137", ctx.getLocale()); String ms2 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label138", ctx.getLocale()); String ms3 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label139", ctx.getLocale()); List taxUnitInfo = new ArrayList(); if (declareCollection != null && declareCollection.size() > 0) { for (int i = 0; i < declareCollection.size(); ++i) { IncomeTaxDeclarInfo declareInfo = declareCollection.get(i); String declareStatus = declareInfo.getDeclareStatus().getValue(); LOG.error("getDeclareData----------declareStatus------" + declareStatus); String taxUnitName = declareInfo.getTaxUnit().getName(); String tbTypeAlia = declareInfo.getTbType().getAlias(); if (currentYearMonth.compareTo(declareInfo.getYearMonth()) <= 0) { taxUnitInfo.add(declareInfo.getTaxUnit().getName() + "_" + declareInfo.getYearMonth()); } if (!"1".equals(declareStatus) && !"2".equals(declareStatus)) { waitToDeclareList.add(declareInfo); LOG.error("getDeclareData----------waitToDeclareList------" + waitToDeclareList); } else { TaxDeclareDTO dto = new TaxDeclareDTO(taxUnitName, tbTypeAlia); declaredList.add(dto); } } if (declaredList.size() == declareCollection.size()) { resultMap.put("info", ms1); } else if (declaredList.size() == 0) { resultMap.put("info", ms2); } else { resultMap.put("info", ms3); } } LOG.error("getDeclareData----------resultMap------" + resultMap); resultMap.put("DECLARED", declaredList); resultMap.put("advanceDeclareInfo", taxUnitInfo); resultMap.put("WATI_TO_DECLARE", waitToDeclareList); return resultMap; } private void updateOrCancel(HttpServletRequest request, HttpServletResponse response, TaskCatalogEnum catalog) throws SHRWebException { Context ctx = SHRContext.getInstance().getContext(); String selectedId = request.getParameter("selectedId"); String oql = "select id, tbType, yearMonth, yearMonthDate, taxUnit.id, taxUnit.name, taxUnit.areaCode, taxUnit.taxNumber, taxUnit.regNumber, taxUnit.declPassword, taxUnit.realPassword, acceptId where id = '" + selectedId + "'"; try { IncomeTaxDeclarCollection collection = IncomeTaxDeclarFactory.getLocalInstance(ctx) .getIncomeTaxDeclarCollection(oql); if (null != collection && collection.size() != 0) { IncomeTaxDeclarInfo incomeTaxDeclare = collection.get(0); if (TaskCatalogEnum.TaxDeclareUpdate == catalog) { //更新 updateDeclare(ctx,incomeTaxDeclare); } else { //更新以外的 if (TaskCatalogEnum.CancelTaxDeclare != catalog) { //撤销更正 System.out.print("撤销更正找到方法"); cancelUpdate( ctx ,incomeTaxDeclare); return; } //撤销申报 System.out.print("作废申报找到方法"); cancelDeclare(ctx,incomeTaxDeclare); System.out.print("作废申报完成"); } String templateId = "4i4AAAAS76+Vh943"; String columnSQL = "select t.fieldsn, f.FPROPNAME,f.fname_l2,f.fcustomfield from T_BS_SHRFileTemplateFields f left join t_HR_sTaxItem t on f.FPROPNAME = t.FNUMBER where f.fcmpimporttempid = '" + templateId + "' order by f.fsortsn "; IRowSet columnSet = DbUtil.executeQuery(ctx, columnSQL); StringBuilder tmpSQL = new StringBuilder(); tmpSQL.append("select "); String dynamicFieldPrefix = "t"; String local = SHRContext.getInstance().getContext().getLocale().getDisplayLanguage(); int columnSize = columnSet.size(); while (columnSet.next()) { int index = columnSet.getInt(1); String propName = columnSet.getString(2); int isCustom = columnSet.getInt(4); if (isCustom == 1 && index > 0) { tmpSQL.append(dynamicFieldPrefix).append(index).append(","); } else if (propName.endsWith("_")) { tmpSQL.append(propName).append(local).append(","); } else { tmpSQL.append(propName).append(","); } } String sql = tmpSQL.substring(0, tmpSQL.length() - 1); Date date = incomeTaxDeclare.getYearMonthDate(); String taxUnitId = incomeTaxDeclare.getTaxUnit().getId().toString(); TbTypeEnum tbType = incomeTaxDeclare.getTbType(); String personType = CmpConstants.getPayerTypeByTbType(tbType.getValue()); String dataSQL = sql + " from t_hr_sTaxCalConfigDetail t left join T_BD_Person person on t.fPersonId = person.fid left join T_HR_STaxPersonRecord taxPersonRec on t.fPersonId = taxPersonRec.fPersonId left join T_HR_TaxUnit taxUnit on t.fTaxUnitId = taxUnit.fid left join T_HR_STaxIncomeItem item on t.fIncomeItemId = item.fid left join T_HR_STaxPersonRecordEntry pEntry on taxPersonRec.fid = pEntry.fBillId where t.fPeriodBegin = " + CmpDateUtil.toKSqlDate(date) + " and t.fTaxUnitId = '" + taxUnitId + "' and pEntry.fTaxUnitId = '" + taxUnitId + "' and pEntry.fPayerType = '" + personType + "'"; IRowSet dataSet = DbUtil.executeQuery(ctx, dataSQL); List> dataList = new ArrayList(); IRowSetMetaData metaData = dataSet.getRowSetMetaData(); for (int rowIndex = 1; dataSet.next(); ++rowIndex) { List row = new ArrayList(); row.add(rowIndex); for (int i = 1; i <= columnSize; ++i) { int dataType = metaData.getColumnType(i); row.add(ImplUtils.getDataFromDr(dataType, dataSet, i)); } dataList.add(row); } String template = request.getSession().getServletContext().getRealPath("/") + "addon/compensation/web/resource/incomeTaxSbbExportTemplate.xlsx"; String taxUnitName = incomeTaxDeclare.getTaxUnit().getName(); String tbTypeName = incomeTaxDeclare.getTbType().getAlias(); String period = TaxCalcFileUtils.getCnPeriod1(incomeTaxDeclare.getYearMonthDate()); String timestamp = TaxCalcFileUtils.getTimestamp(new Date()); String userTempDirAbsolutePath = UserUtil.getUserTempDirAbsolutePath(request.getSession()); userTempDirAbsolutePath = userTempDirAbsolutePath + "/exportExcel"; File dir = new File(userTempDirAbsolutePath); if (!dir.exists()) { dir.mkdirs(); } String fileName = "个税申报表_" + taxUnitName + "_" + tbTypeName + "_" + period + "_" + timestamp + ".xlsx"; String path = dir.getAbsolutePath() + File.separator + fileName; Map params = new HashMap(); params.put("startAndEnd", TaxCalcFileUtils.getCnPeriod2(incomeTaxDeclare.getYearMonthDate())); params.put("taxUnitName", taxUnitName); params.put("taxUnitNumber", incomeTaxDeclare.getTaxUnit().getTaxNumber()); CmpExcelUtil.writeData2Template(dataList, template, 8, path, params); String headerStr = "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"); response.setHeader("Content-disposition", headerStr); response.getOutputStream().write(TaxCalcFileUtils.file2ByteArray(new File(path))); response.getOutputStream().flush(); return; } else { throw new SHRWebException("没有找到申报记录"); } } catch (Exception var37) { LOG.error("updateDeclareAction error: ", var37); throw new SHRWebException(var37.getMessage()); } } protected Map cancelUpdate(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException { try { String sql = "select t.fAccept_id as acceptId from t_hr_sIncomeTaxDeclar d left join t_hr_sTaskIncomeTaxRelation r on d.fid = r.fBizId left join t_hr_sTaxCalTask t on r.fTaskId = t.fid where d.fid = '" + taxDeclare.getId().toString() + "' and t.fCatalog = " + 120; IRowSet rowSet = DbUtil.executeQuery(ctx, sql); if (rowSet.size() == 0) { throw new BOSException("找不到更正申报任务受理id"); } else { while (rowSet.next()) { taxDeclare.setAcceptId(rowSet.getString("acceptId")); } return updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.CancelTaxUpdate); } } catch (SQLException var5) { LOG.error("_cancelUpdate error: ", var5); throw new BOSException(var5.getMessage()); } } private Map updateOrCancel(Context ctx, IncomeTaxDeclarInfo taxDeclare, TaskCatalogEnum catalog) throws BOSException { JSONObject param = new JSONObject(); String billId = StringUtils.cnulls(taxDeclare.getId()); param.put("taxDeclarId", billId); param.put("taxDeclarBatchNo", StringUtils.cnulls(taxDeclare.getBatchNo()) ); Map paramMap = new HashMap(); DeclareCancelRequest requestObj = new DeclareCancelRequest(); TaxUnitInfo taxUnit = taxDeclare.getTaxUnit(); /// bizNo 外部业务编号 String(64) 是 外部业务编号,唯一,幂等需要,最长64位,建议使用UUID String bizNo = UUID.randomUUID().toString(); paramMap.put("bizNo" , bizNo); requestObj.setBizNo(bizNo); //qymc 企业名称 String(64) 是 代报企业全称 System.out.print("企业名称为:"+taxUnit.getName()); paramMap.put("qymc" , taxUnit.getName() ); requestObj.setName(taxUnit.getName()); //djxhid 登记序号 String(64) 条件必填 存在多个登记序号时,需要指定传入一个.例:10117440105249764755 paramMap.put("djxhid" , taxUnit.getRegNumber()); requestObj.setRegistrationNumber(taxUnit.getRegNumber()); //nsrsbh 税号 String(64) 是 扣缴单位纳税人识别号 paramMap.put("nsrsbh" , taxUnit.getTaxNumber()); requestObj.setTaxNo(taxUnit.getTaxNumber()); //areaid 地区编号 String(64) 是 6位行政区划代码,精确到市级,例如:440100,参考省市区编码 paramMap.put("areaid" , taxUnit.getAreaCode()); requestObj.setArea(taxUnit.getAreaCode()); //bmbh 部门编号 String(64) 条件必填 分部门代报时必传 //bmmc 部门名称 String(64) 否 //skssq 所属期 String(64) 是 格式YYYYMM。为空时, 根据任职受雇日期判断: String period = taxDeclare.getYearMonth(); period = period.contains("-") ? period.replace("-", "") : period; period = period.substring(0, 6); requestObj.setMonth(period); paramMap.put("skssq" , period); //sblx 申报类型 String(64) 必填 1:综合所得;2:分类所得;3:非居民所得;4:限售股所得 paramMap.put("sblx" , "1"); requestObj.setDeclarationType("1"); //sfqksd 是否清空所得数据 String(64) 否 0:不清空 1 清空, 默认为0, 作废申报的同时清空数据 requestObj.setCancelImportDataOption("0"); //jmsmmm 加密实名密码 String(64) 否 默认不传则设置为0,0表示不加密;1表示加密 paramMap.put("jmsbmm" , "0"); requestObj.setEncryptedRealNamePassword("0"); if (!StringUtils.isEmpty(taxUnit.getRealPassword())) { //mmlx 密码类型 String(64) 否 默认不传则设置为0, 0表示申报密码;2表示实名账号实名密码 paramMap.put("mmlx" , "2"); requestObj.setPasswordType("2"); //smzh 实名账号 String(64) 条件必填 当mmlx=2时,必填。 paramMap.put("smzh", false); requestObj.setRealNameAccount(""); //smmm 实名密码 String(64) 条件必填 当mmlx=2时,必填 paramMap.put("smmm", Base64Utils.decode(taxUnit.getRealPassword())); requestObj.setRealNamePassword(Base64Utils.decode(taxUnit.getRealPassword())); } if (!StringUtils.isEmpty(taxUnit.getDeclPassword())) { //sbmm 申报密码 String(64) 条件必填 当mmlx=0时,必填 paramMap.put("sbmm", Base64Utils.decode(taxUnit.getDeclPassword())); requestObj.setDeclarePassword(Base64Utils.decode(taxUnit.getDeclPassword())); //mmlx 密码类型 String(64) 否 默认不传则设置为0, 0表示申报密码;2表示实名账号实名密码 paramMap.put("mmlx" , "0"); requestObj.setPasswordType("0"); } //客户端代理工厂 try { ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory(); //算税请求接口 DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest(); //获取请求参数 if( catalog.equals(TaskCatalogEnum.CancelTaxDeclare) ) { // Gson gson = new Gson(); // Type personType = new TypeToken(){}.getType(); // DeclareCancelRequest newObj = gson.fromJson(gson.toJson(requestObj), personType); LOG.error("撤销申报执行参数:"+mapper.writeValueAsString(requestObj)); //CancelTaxDeclare 作废申报 140 ApiResponse apiResponse = declarationRequest.cancel (requestObj); LOG.error("撤销申报执行结果"+apiResponse.getHead().getMsg()); if (apiResponse.getHead().getCode().equals("00000000")) { AsyncResult body = apiResponse.getBody(); String requestId = body.getRequestId(); LOG.error("requestId-----" + requestId); ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx); //backTask(url,requestId,回调osf服务,自定义参数,任务类型) JSONObject json = new JSONObject(); json.put("requestId", requestId); json.put("reportType", "1"); // // JSONObject paramJson = new JSONObject(); // paramJson.put("taxDeclarId", taxDeclare.getId().toString()); // paramJson.put("taxDeclarBatchNo", taxDeclare.getBatchNo()); json.put("param", param ); LOG.error("撤销申报执行调用后台开始"+param); isyUtilsFacade.addTask("CancelDeclareService", json.toJSONString(), TaskCatalogEnum.CancelTaxDeclare, ""); LOG.error("撤销申报执行调用后台完成"); } }else if(catalog.equals(TaskCatalogEnum.TaxDeclareUpdate)) { //更正申报 120 // Gson gson = new Gson(); // Type personType = new TypeToken(){}.getType(); // DeclareCorrectRequest newObj = gson.fromJson(gson.toJson(paramMap), personType); ObjectMapper mapper = new ObjectMapper(); DeclareCorrectRequest newObj = mapper.convertValue(paramMap, DeclareCorrectRequest.class); LOG.error("更正申报执行参数:"+mapper.writeValueAsString(newObj)); ApiResponse apiResponse = declarationRequest.correct (newObj); LOG.error("更正申报执行结果"+apiResponse.getHead().getMsg()); if (apiResponse.getHead().getCode().equals("00000000")) { //同步接口; //个税申报批次号 String taxDeclarBatchNo = taxDeclare.getBatchNo(); IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx); IncomeTaxDeclarInfo incomeTaxDeclarInfo = iIncomeTaxDeclar.getIncomeTaxDeclarInfo(new ObjectUuidPK(billId)); SelectorItemCollection updateSic = new SelectorItemCollection(); updateSic.add("declareStatus"); if (null != incomeTaxDeclarInfo) { incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_NO); iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic); } } }else if(catalog.equals(TaskCatalogEnum.CancelTaxUpdate )) { System.out.print("撤销更正执行"); //撤销更正申报 // Gson gson = new Gson(); // Type personType = new TypeToken(){}.getType(); // DeclareCorrectRequest newObj = gson.fromJson(gson.toJson(paramMap), personType); ObjectMapper mapper = new ObjectMapper(); DeclareCorrectRequest convertValue = mapper.convertValue(paramMap, DeclareCorrectRequest.class); LOG.error("撤销更正执行参数:"+mapper.writeValueAsString(convertValue)); ApiResponse apiResponse = declarationRequest.cancelCorrect (convertValue); LOG.error("撤销更正执行结果"+apiResponse.getHead().getMsg()); if (apiResponse.getHead().getCode().equals("00000000")) { //同步接口; //个税申报批次号 String taxDeclarBatchNo = taxDeclare.getBatchNo(); IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx); // IncomeTaxDeclarCollection incomeTaxDeclarCollection = iIncomeTaxDeclar.getIncomeTaxDeclarCollection("where batchNo = '" + taxDeclarBatchNo + "'"); IncomeTaxDeclarInfo incomeTaxDeclarInfo = iIncomeTaxDeclar.getIncomeTaxDeclarInfo(new ObjectUuidPK(billId)); SelectorItemCollection updateSic = new SelectorItemCollection(); updateSic.add("declareStatus"); if (null != incomeTaxDeclarInfo) { // IncomeTaxDeclarInfo incomeTaxDeclarInfo = incomeTaxDeclarCollection.get(0); incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_SUCCESS); iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic); } } } } catch (IOException e) { e.printStackTrace(); } catch (EASBizException e) { e.printStackTrace(); } return paramMap; } /** * 撤销申请 * @param ctx * @param taxDeclare * @return * @throws BOSException */ protected Map cancelDeclare(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException { return this.updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.CancelTaxDeclare); } /** * 更正 * @param ctx * @param taxDeclare * @return * @throws BOSException */ protected Map updateDeclare(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException { return updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.TaxDeclareUpdate); } /** * 撤销申报 * */ public void cancelDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException { this.updateOrCancel(request, response, TaskCatalogEnum.CancelTaxDeclare); request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "cancelDeclare"); } /** * 更正申请 */ public void updateDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException { this.updateOrCancel(request, response, TaskCatalogEnum.TaxDeclareUpdate); request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "updateDeclare"); } /** * 撤销更正 * */ public void cancelUpdateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException { this.updateOrCancel(request, response, TaskCatalogEnum.CancelTaxUpdate); request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "cancelUpdate"); } }