package com.changhong.epc.form.service.assets; import com.changhong.epc.bean.admin.AssetDepreciation; import com.changhong.epc.bean.admin.CorresElField; import com.changhong.epc.bean.form.Accrued; import com.changhong.epc.bean.form.Asset; import com.changhong.epc.bean.form.QueryParam; import com.changhong.epc.bean.form.SectoralAssets; import com.changhong.epc.bean.tenant.system.SystemForm; import com.changhong.epc.constter.base.BaseConst; 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.constter.system.businesscode.BudgetBusinessMeaningCode; import com.changhong.epc.form.mapper.tenant.AccruedMapper; import com.changhong.epc.form.mapper.tenant.QueryParamMapper; import com.changhong.epc.form.mapper.tenant.SectoralAssetsMapper; import com.changhong.epc.form.service.budget.department.DepartmentRelationService; import com.changhong.epc.form.service.budget.impl.GetConstant; import com.changhong.epc.rely.api.bean.Company; import com.changhong.epc.rely.api.bean.Organization; import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi; import com.changhong.epc.rely.api.epc.admin.asset.AssetDepreciationApi; import com.changhong.epc.rely.api.service.CscApiService; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.DateTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.text.ParseException; import java.util.*; @Service("assetService") public class AssetServiceImpl implements AssetService,BaseConst,BudgetBusinessMeaningCode, AssetStatic, AssetMsg { @Resource private CscApiService cscApiService; @Resource private SectoralAssetsMapper sectoralAssetsMapper; @Resource private AccruedMapper accruedMapper; @Resource(name = "departmentRelationService") private DepartmentRelationService departmentRelationService; @Resource private QueryParamMapper queryParamMapper; @Resource private CorresElFieldApi corresElFieldApi; @Resource private AssetDepreciationApi assetDepreciationApi; /** * * 通过时间查询所有一级部门的 折旧信息 * param: date时间 * return : List */ @Override public List getSectoralAsset(String date){ Company company = cscApiService.getCompany(); if(company == null){ return Collections.EMPTY_LIST; } return sectoralAssetsMapper.getSectoralAssets( company.getOrgCode() , date , GetConstant.getFormIdGetConstant(SystemForm.ASSET_FORM_ID.name()) , corresElFieldApi.getVal(ASSET_IS_SECTORAL, CorresElField::getMdCode) ); } /** *分页查询折旧信息 * @throws ParseException */ public List getAccrueds(QueryParam queryParam) { queryParam.setTenantId(Objects.toString(ThreadData.get(TENANT_ID))); queryParam.setFormId(GetConstant.getFormIdGetConstant(SystemForm.ASSET_FORM_ID.name())); queryParam.setAllUseDep(queryParam.getUseDepCode()); // Calendar bef = Calendar.getInstance(); // bef.setTime(DateTool.stringToDate(queryParam.getDate(), "yyyy-MM")); // bef.add(Calendar.MONTH, -1); // queryParam.setDate(DateTool.dateToString(bef.getTime(), "yyyy-MM")); List accs; if(queryParam.getState().equals("0")){ accs = queryParamMapper.selectAssetPage(queryParam); }else{ accs = queryParamMapper.selectAccruedsPage(queryParam); } for(int i = 0 ; i < accs.size();i++){ switch (accs.get(i).getDepreciationMethod()) { case AssetStatic.DUBLEdDECLININGBALANCEMETHODCODE: accs.get(i).setDepreciationMethod(AssetStatic.DUBLEdDECLININGBALANCEMETHOD); break; case AssetStatic.AVERAGELIFEMETHODCODE: accs.get(i).setDepreciationMethod(AssetStatic.AVERAGELIFEMETHOD); break; case AssetStatic.SUMOFYEARSMETHODCODE: accs.get(i).setDepreciationMethod(AssetStatic.SUMOFYEARSMETHOD); break; default:break; } } return accs; } @Override public int updateAssetsByState(Map map) { String state=map.get("status2"); String colId=map.get("colId"); String voucherCode=map.get("voucherCode"); return sectoralAssetsMapper.updateSectoralAssetsStatus(getType(state),colId,voucherCode); } @Override public Boolean validateAsset(AssetDepreciation assetDepreciation) { Boolean account = assetDepreciationApi.assetIsAccount(); String date = sectoralAssetsMapper.getLastDepreciationDate(assetDepreciation.getOrgCode(), account); if(ObjectUtil.empty(date)){ return Boolean.TRUE; } // 资产化日期必须大于最后一次最后计提、记账时间 int compare = DateTool.dateToString(DateTool.stringToDate(date), "yyyy-MM") .compareTo(DateTool.dateToString(DateTool.stringToDate(assetDepreciation.getDate()), "yyyy-MM")); if(!(account ? compare <= 0 : compare <= 0)){ throw new EPCServiceException(CREATE_ASSET_DATE_ERROR, /*(account ? ">" : ">=" )*/ ">=" + date); } return Boolean.TRUE; } /** * 通过一级部门进行查询 */ @Override public List getErrAsset(QueryParam queryParam) { String tenantId =Objects.toString(ThreadData.get(TENANT_ID)); //String formId = GetConstant.getFormIdGetConstant(ASSETFORMID); String formId = GetConstant.getFormIdGetConstant(SystemForm.ASSET_FORM_ID.name()); Calendar bef = Calendar.getInstance(); bef.setTime(DateTool.stringToDate(queryParam.getDate(), "yyyy-MM")); bef.add(Calendar.MONTH, -1); List assets = accruedMapper.selectErrAsset(null, DateTool.dateToString(bef.getTime(), "yyyy-MM"), queryParam.getUseDepCode(),AssetStatic.CANDEPRECIATION,tenantId,formId); for(int i = 0 ;i getErrAssetOne(QueryParam queryParam) { List organization=departmentRelationService.getHigCode(queryParam.getUseDepCode()); if(organization == null){ organization = new ArrayList<>(); } String tenantId =Objects.toString(ThreadData.get(TENANT_ID)); String formId = GetConstant.getFormIdGetConstant(SystemForm.ASSET_FORM_ID.name()); List assets = accruedMapper.selectErrAssetOne(null, queryParam.getDate(), organization,AssetStatic.CANDEPRECIATION,tenantId,formId); for(int i = 0 ;i