package com.changhong.epc.parsing.service.loop.impl; import com.changhong.epc.bean.admin.AssetDepreciation; import com.changhong.epc.bean.tenant.asset.FixedSummary; import com.changhong.epc.config.tool.MybatisTool; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.parsing.mapper.tenant.asset.FixedSummaryMapper; import com.changhong.epc.parsing.service.asset.account.AccountHandleImpl; import com.changhong.epc.parsing.service.asset.depreciation.DepreciationHandleImpl; import com.changhong.epc.rely.api.epc.admin.asset.AssetDepreciationApi; import com.iemsoft.framework.cloud.core.thread.Keys; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.stereotype.Component; import javax.annotation.Resource; import static com.changhong.epc.constter.parsing.asset.AssetStatic.ACCOUNT_ERROR; import static com.changhong.epc.constter.parsing.asset.AssetStatic.DEPRECIATION_ERROR; /** * 固定资产折旧记账服务 */ @Component @Slf4j public class AssetDepreciationLoopServiceImpl extends SimplAbstractLoopSuper { @Resource private AssetDepreciationApi assetDepreciationApi; @Resource private FixedSummaryMapper fixedSummaryMapper; @Override public void init() { super.setLoopBaseService(assetDepreciationApi); super.init(); } @Override public String getThreadName() { return "固定资产折旧服务"; } @Override protected void doService() { // MybatisTool.setAdminDataSource(); businessHandle(); } @Override void init(AssetDepreciation assetDepreciation) { super.init(assetDepreciation); ThreadData.set(BaseConst.TENANT_ID, assetDepreciation.getTenantId()); ThreadData.set(BaseConst.COMPANY_ID, NumberUtils.createInteger(assetDepreciation.getCompanyId())); ThreadData.set(BaseConst.OPEN_ID, assetDepreciation.getOpenId()); ThreadData.set(Keys.USER_ID, assetDepreciation.getOpenId()); MybatisTool.initDataSource(); } @Override void doService(AssetDepreciation assetDepreciation) { switch (assetDepreciation.getType()){ case ACCOUNT: SpringUtil.getBean(AccountHandleImpl.class).doHandle(assetDepreciation); return; case DEPRECIATION: SpringUtil.getBean(DepreciationHandleImpl.class).doHandle(assetDepreciation); return; } } @Override void error(AssetDepreciation assetDepreciation, Exception e) { super.error(assetDepreciation, e); FixedSummary fixedSummary = new FixedSummary(); // 折旧、记账失败 switch (assetDepreciation.getType()){ case DEPRECIATION: fixedSummary.setCountingState(DEPRECIATION_ERROR); break; case ACCOUNT: fixedSummary.setBookkeepingState(ACCOUNT_ERROR); break; } fixedSummary.setUseDepartment(assetDepreciation.getOrgCode()); fixedSummary.setCalculationPeriod(assetDepreciation.getDate()); fixedSummaryMapper.updateFixedSummary(fixedSummary); } }