package com.changhong.epc.form.service.assets; import com.changhong.epc.bean.admin.AssetType; import com.changhong.epc.bean.tenant.asset.FixedSummary; import com.changhong.epc.constter.exception.EPCServiceException; import com.changhong.epc.constter.parsing.asset.AssetMsg; import com.changhong.epc.constter.parsing.asset.AssetStatic; import com.changhong.epc.form.mapper.tenant.asset.FixedSummaryMapper; import com.changhong.epc.form.rest.Assets.CalculationController; import com.changhong.epc.rely.api.epc.admin.asset.AssetDepreciationApi; import com.iemsoft.framework.cloud.core.tools.DateTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Objects; /** * 固定资产折旧 */ @Slf4j @Service public class CalculationsServiceImple implements CalculationService, AssetStatic, AssetMsg { @Resource private AssetDepreciationApi assetDepreciationApi; @Resource private FixedSummaryMapper fixedSummaryMapper; @Override @Transactional public int depreciation(CalculationController.CalculationDto calculationDto) { calculationDto.getUseDep().stream().forEach(organization -> { FixedSummary fixedSummary = fixedSummaryMapper.getOneFixedSummary(FixedSummary.of(organization.getCode(), calculationDto.getDate())); if(ObjectUtil.empty(fixedSummary)){ fixedSummary = new FixedSummary(); fixedSummary.setUseDepartment(organization.getCode()); fixedSummary.setCalculationPeriod(calculationDto.getDate()); fixedSummary.setCalculationData(DateTool.currentFormatDate(DateTool.DATE_PATTERN)); fixedSummary.initParam(); } fixedSummary.setCountingState(DEPRECIATION_ING); if(fixedSummary.getId() == null){ fixedSummaryMapper.insertSelective(fixedSummary); }else{ fixedSummaryMapper.updateByPrimaryKeySelective(fixedSummary); } }); return assetDepreciationApi.insert( calculationDto.getDate() , calculationDto.getUseDep().stream().map(org->org.getCode()).toArray(String[]::new) , AssetType.DEPRECIATION); } @Override @Transactional public int account(CalculationController.CalculationDto calculationDto) { calculationDto.getUseDep().stream().forEach(organization -> { FixedSummary fixedSummary = fixedSummaryMapper.getOneFixedSummary(FixedSummary.of(organization.getCode(), calculationDto.getDate())); if(ObjectUtil.empty(fixedSummary) || !Objects.equals(fixedSummary.getCountingState(), DEPRECIATION_SUCCESS)){ throw new EPCServiceException(ACCOUNT_NOT_DEPRECIATION); } fixedSummary.setAccountingTime(DateTool.currentFormatDate(DateTool.DATE_PATTERN)); fixedSummary.setBookkeepingState(ACCOUNT_ING); fixedSummary.updateIngParam(); fixedSummaryMapper.updateByPrimaryKeySelective(fixedSummary); }); return assetDepreciationApi.insert( calculationDto.getDate() , calculationDto.getUseDep().stream().map(org->org.getCode()).toArray(String[]::new) , AssetType.ACCOUNT); } }