|
|
@@ -7,9 +7,11 @@ import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.sky.core.excel.util.ExcelUtil;
|
|
|
@@ -21,11 +23,13 @@ import org.sky.core.secure.utils.SecureUtil;
|
|
|
import org.sky.core.tool.utils.*;
|
|
|
import org.sky.scientific.e.AssetStatusEnum;
|
|
|
import org.sky.scientific.excel.AssetExcel;
|
|
|
-import org.sky.scientific.mapper.AssetMapper;
|
|
|
+import org.sky.scientific.mapper.*;
|
|
|
import org.sky.scientific.pojo.dto.AssetDTO;
|
|
|
import org.sky.scientific.pojo.dto.CostSummaryDTO;
|
|
|
import org.sky.scientific.pojo.dto.XmAssetCostQueryParam;
|
|
|
import org.sky.scientific.pojo.entity.AssetEntity;
|
|
|
+import org.sky.scientific.pojo.entity.XmFixedAsset;
|
|
|
+import org.sky.scientific.pojo.entity.XmIntangibleAsset;
|
|
|
import org.sky.scientific.pojo.vo.AssetVO;
|
|
|
import org.sky.scientific.pojo.vo.CostSummaryVO;
|
|
|
import org.sky.scientific.pojo.vo.XmAssetCostSummary;
|
|
|
@@ -49,11 +53,18 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity> implements IAssetService {
|
|
|
|
|
|
+ private final XmAssetHoursMapper hoursMapper;
|
|
|
+ private final XmFixedAssetMapper fixedAssetMapper;
|
|
|
+ private final XmIntangibleAssetMapper intangibleAssetMapper;
|
|
|
+ private final YsWxzctxfyMapper ysWxzctxfyMapper;
|
|
|
+ private final YsZjfyycqdtfyMapper ysZjfyycqdtfyMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<AssetVO> selectAssetPage(IPage<AssetVO> page, AssetDTO dto) {
|
|
|
- if(Func.isNotBlank(dto.getZclb())){
|
|
|
+ if (Func.isNotBlank(dto.getZclb())) {
|
|
|
dto.setZclbList(Arrays.asList(dto.getZclb().split(",")));
|
|
|
}
|
|
|
return page.setRecords(baseMapper.selectAssetPage(page, dto));
|
|
|
@@ -69,7 +80,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
throw new ServiceException("资产【" + asset.getZcbm() + "】已存在");
|
|
|
}
|
|
|
|
|
|
- if(!isFixedAsset(asset.getZclb())){
|
|
|
+ if (!isFixedAsset(asset.getZclb())) {
|
|
|
asset.setGl("/");
|
|
|
}
|
|
|
|
|
|
@@ -77,13 +88,13 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
// 仪器设置的算法:当前时间为2025年01月-2024年5月,差额为9个月,因为折旧从次月开始,所以已使用月数为8个月(即9-1=8),再将使用寿命-已使用月份数=0时,即已足额折旧。
|
|
|
// 无形资产:当月即摊销,不需要-1
|
|
|
|
|
|
- long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse(asset.getYearAndMonth(), DateUtil.PATTERN_YYYYMM) , asset.getKssj(), false);
|
|
|
+ long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse(asset.getYearAndMonth(), DateUtil.PATTERN_YYYYMM), asset.getKssj(), false);
|
|
|
// 这里
|
|
|
if (!isFixedAsset(asset.getZclb())) {
|
|
|
ysysm++;
|
|
|
}
|
|
|
asset.setYsysm((int) ysysm);
|
|
|
- asset.setStatus((asset.getSysm() - asset.getYsysm() <= 0) ? 2 : 0);
|
|
|
+ asset.setStatus((asset.getSysm() - asset.getYsysm() <= 0) ? AssetStatusEnum.已足额折旧.getCode() : AssetStatusEnum.正常.getCode());
|
|
|
return this.save(asset);
|
|
|
}
|
|
|
|
|
|
@@ -98,7 +109,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
for (AssetExcel excel : data) {
|
|
|
AssetEntity zc = Objects.requireNonNull(BeanUtil.copyProperties(excel, AssetDTO.class));
|
|
|
String identifier = excel.getZcbm() + ":" + excel.getZcmc();
|
|
|
- if(idenfifierList.contains(identifier)){
|
|
|
+ if (idenfifierList.contains(identifier)) {
|
|
|
throw new ServiceException("数据已存在,导入失败!");
|
|
|
}
|
|
|
idenfifierList.add(identifier);
|
|
|
@@ -112,7 +123,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if(Func.notNull(zc.getJcz())){
|
|
|
+ if (Func.notNull(zc.getJcz())) {
|
|
|
zc.setJcz(Math.min(zc.getJcz(), 1.0));
|
|
|
}
|
|
|
AssetStatusEnum assetStatusEnum = Arrays.stream(AssetStatusEnum.values()).filter(temp -> temp.getName().equalsIgnoreCase(excel.getStatusName())).findFirst().orElse(AssetStatusEnum.正常);
|
|
|
@@ -160,18 +171,41 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public boolean physicalDeleteByIds(List<Long> ids,String yearAndMonth) {
|
|
|
+ public boolean physicalDeleteByIds(List<Long> ids, String yearAndMonth) {
|
|
|
//删除说明
|
|
|
//① 删除:如果此资产,在研发项目中,已使用情况下,不可以删除。系统提示:资产已被使用,无法删除!
|
|
|
//② 如果此资产,无任何研发项目使用,可以在资产清单管理中,将此资产进行删除。
|
|
|
//③ 如果此资产,曾经被研发项目使用(可能研发项目后续不再使用此资产),这一类情况也不可以进行删除。
|
|
|
- List<Long> list = baseMapper.checkAssetUsage(ids, yearAndMonth, SecureUtil.getTenantId());
|
|
|
- if(Func.isNotEmpty(list)){
|
|
|
- throw new ServiceException("资产已被使用,无法删除!");
|
|
|
+// List<Long> list = baseMapper.checkAssetUsage(ids, yearAndMonth, SecureUtil.getTenantId());
|
|
|
+// if (Func.isNotEmpty(list)) {
|
|
|
+// throw new ServiceException("资产已被使用,无法删除!");
|
|
|
+// }
|
|
|
+
|
|
|
+ for (Long assetId : ids) {
|
|
|
+ AssetEntity dbAsset = baseMapper.selectById(assetId);
|
|
|
+ canDeleteAsset(dbAsset, yearAndMonth);
|
|
|
}
|
|
|
return baseMapper.physicalDeleteByIds(ids);
|
|
|
}
|
|
|
|
|
|
+ private void canDeleteAsset(AssetEntity asset, String yearAndMonth) {
|
|
|
+ if (hoursMapper.countByZcbmAfterMonth(asset.getZcbm(), yearAndMonth) > 0) {
|
|
|
+ throw new ServiceException("无法删除,每月仪器设备工时打卡中引用了【" + asset.getZcbm() + "】");
|
|
|
+ }
|
|
|
+ if (fixedAssetMapper.selectCount(Wrappers.<XmFixedAsset>lambdaQuery().eq(XmFixedAsset::getZcbm, asset.getZcbm()).ge(XmFixedAsset::getYearAndMonth, yearAndMonth)) > 0) {
|
|
|
+ throw new ServiceException("无法删除,每月仪器设备明细/每月在用建筑物明细中引用了【" + asset.getZcbm() + "】");
|
|
|
+ }
|
|
|
+ if (intangibleAssetMapper.selectCount(Wrappers.<XmIntangibleAsset>lambdaQuery().eq(XmIntangibleAsset::getZcbm, asset.getZcbm()).ge(XmIntangibleAsset::getYearAndMonth, yearAndMonth)) > 0) {
|
|
|
+ throw new ServiceException("无法删除,每月无形资产明细中引用了【" + asset.getZcbm() + "】");
|
|
|
+ }
|
|
|
+ if(ysWxzctxfyMapper.countByZcbmAfterMonth(asset.getZcbm(), yearAndMonth) > 0){
|
|
|
+ throw new ServiceException("无法删除,研发项目预算-无形资产摊销费用中引用了【" + asset.getZcbm() + "】");
|
|
|
+ }
|
|
|
+ if(ysZjfyycqdtfyMapper.countByZcbmAfterMonth(asset.getZcbm(), yearAndMonth) > 0){
|
|
|
+ throw new ServiceException("无法删除,研发项目预算-折旧费用与长期待摊费用中引用了【" + asset.getZcbm() + "】");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@SneakyThrows
|
|
|
@Override
|
|
|
public void exportAsset(HttpServletResponse response, AssetDTO dto) {
|
|
|
@@ -181,8 +215,8 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
AtomicInteger i = new AtomicInteger(1);
|
|
|
list.forEach(temp -> {
|
|
|
- temp.setXh(i.getAndIncrement()+"");
|
|
|
- temp.setKssjStr(Func.notNull(temp.getKssj())?DateUtil.format(temp.getKssj(), DateUtil.PATTERN_DATE):"");
|
|
|
+ temp.setXh(i.getAndIncrement() + "");
|
|
|
+ temp.setKssjStr(Func.notNull(temp.getKssj()) ? DateUtil.format(temp.getKssj(), DateUtil.PATTERN_DATE) : "");
|
|
|
Arrays.stream(AssetStatusEnum.values()).anyMatch(assetStatusEnum -> assetStatusEnum.getCode() == temp.getStatus());
|
|
|
AssetStatusEnum assetStatusEnum = Arrays.stream(AssetStatusEnum.values()).filter(o -> o.getCode() == temp.getStatus()).findFirst().orElse(AssetStatusEnum.正常);
|
|
|
temp.setStatusStr(assetStatusEnum.getName());
|
|
|
@@ -226,13 +260,13 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- @SneakyThrows
|
|
|
+ @SneakyThrows
|
|
|
@Override
|
|
|
- public void exportCostSummary(HttpServletResponse response, CostSummaryDTO dto) {
|
|
|
+ public void exportCostSummary(HttpServletResponse response, CostSummaryDTO dto) {
|
|
|
List<CostSummaryVO> list = this.costSummary(dto);
|
|
|
AtomicInteger index = new AtomicInteger(1);
|
|
|
list.forEach(temp -> {
|
|
|
- temp.setXh(index.getAndIncrement()+"");
|
|
|
+ temp.setXh(index.getAndIncrement() + "");
|
|
|
});
|
|
|
|
|
|
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/研发费用汇总表P0040.xls");
|
|
|
@@ -248,7 +282,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
//设置list集合数据
|
|
|
excelWriter.fill(list, fillConfig, writeSheet);
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
map.put("ryrgfySum", list.stream().map(CostSummaryVO::getRyrgfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("zjtrfySum", list.stream().map(CostSummaryVO::getZjtrfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("zjfyycqdtfySum", list.stream().map(CostSummaryVO::getZjfyycqdtfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
@@ -259,16 +293,17 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
map.put("wwfySum", list.stream().map(CostSummaryVO::getWwfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("wwfyAdjustSum", list.stream().map(CostSummaryVO::getWwfyAdjust).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("totalSum", list.stream().map(CostSummaryVO::getTotal).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
- map.put("year", dto.getYearAndMonth().substring(0,4));
|
|
|
+ map.put("year", dto.getYearAndMonth().substring(0, 4));
|
|
|
map.put("month", dto.getYearAndMonth().substring(4));
|
|
|
excelWriter.fill(map, writeSheet);
|
|
|
excelWriter.finish();
|
|
|
if (templateFileName != null) {
|
|
|
templateFileName.close();
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
public boolean updateAsset(AssetEntity asset) {
|
|
|
if (Func.isNull(asset.getId())) {
|
|
|
throw new ServiceException("参数id不能为空");
|
|
|
@@ -282,30 +317,57 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
throw new ServiceException("资产【" + asset.getZcbm() + "】已存在");
|
|
|
}
|
|
|
|
|
|
- if(!isFixedAsset(asset.getZclb())){
|
|
|
+ if (!isFixedAsset(asset.getZclb())) {
|
|
|
asset.setGl("/");
|
|
|
}
|
|
|
// 正常状态、停用状态,可修改资产数据。其他情况不能修改。假设在修改资产时,正好出现使用寿命-已使用月份数=0时,即已足额折旧状态时,就显示为已足额折旧状态了,不可以再次修改了。
|
|
|
// 修改资产时,系统需要二次确认。
|
|
|
-
|
|
|
-
|
|
|
if (Func.equals(dbAsset.getStatus(), AssetStatusEnum.正常.getCode()) || Func.equals(dbAsset.getStatus(), AssetStatusEnum.停用.getCode())) {
|
|
|
-// if (Func.isNull(asset.getYsysm())) {
|
|
|
- //使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
// 仪器设置的算法:当前时间为2025年01月-2024年5月,差额为9个月,因为折旧从次月开始,所以已使用月数为8个月(即9-1=8),再将使用寿命-已使用月份数=0时,即已足额折旧。
|
|
|
// 无形资产:当月即摊销,不需要-1
|
|
|
- long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse(asset.getYearAndMonth(), DateUtil.PATTERN_YYYYMM), asset.getKssj(), false);
|
|
|
+ long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse(asset.getYearAndMonth(), DateUtil.PATTERN_YYYYMM), asset.getKssj(), false);
|
|
|
// 这里
|
|
|
- if (!Func.equals("仪器设备", asset.getZclb())) {
|
|
|
- ysysm++;
|
|
|
- }
|
|
|
- asset.setYsysm((int) ysysm);
|
|
|
+ if (!Func.equals("仪器设备", asset.getZclb())) {
|
|
|
+ ysysm++;
|
|
|
}
|
|
|
- if (asset.getSysm() - asset.getYsysm() <= 0) {
|
|
|
- asset.setStatus(AssetStatusEnum.已足额折旧.getCode());
|
|
|
+ asset.setYsysm((int) ysysm);
|
|
|
+ }
|
|
|
+ //使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
+ if (asset.getSysm() - asset.getYsysm() <= 0) {
|
|
|
+ asset.setStatus(AssetStatusEnum.已足额折旧.getCode());
|
|
|
+ }
|
|
|
+ return this.updateOtherMonthAsset(asset);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean updateOtherMonthAsset(AssetEntity asset) {
|
|
|
+ LambdaQueryWrapper<AssetEntity> queryWrapper = Wrappers.<AssetEntity>lambdaQuery()
|
|
|
+ .eq(AssetEntity::getZcbm, asset.getZcbm()).ge(AssetEntity::getYearAndMonth, asset.getYearAndMonth());
|
|
|
+ List<AssetEntity> list = baseMapper.selectList(queryWrapper);
|
|
|
+ for (AssetEntity entity : list) {
|
|
|
+
|
|
|
+ AssetEntity updateEntity = new AssetEntity();
|
|
|
+ cn.hutool.core.bean.BeanUtil.copyProperties(asset, updateEntity);
|
|
|
+ updateEntity.setId(null);
|
|
|
+ updateEntity.setYearAndMonth(null);
|
|
|
+ updateEntity.setTenantId(null);
|
|
|
+ updateEntity.setZgs(null);
|
|
|
+
|
|
|
+ long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse(entity.getYearAndMonth(), DateUtil.PATTERN_YYYYMM), updateEntity.getKssj(), false);
|
|
|
+// 这里
|
|
|
+ if (!Func.equals("仪器设备", updateEntity.getZclb())) {
|
|
|
+ ysysm++;
|
|
|
}
|
|
|
-// }
|
|
|
- return this.updateById(asset);
|
|
|
+ updateEntity.setYsysm((int) ysysm);
|
|
|
+
|
|
|
+ //使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
+ if (updateEntity.getSysm() - updateEntity.getYsysm() <= 0) {
|
|
|
+ updateEntity.setStatus(AssetStatusEnum.已足额折旧.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<AssetEntity> updateWrapper = Wrappers.<AssetEntity>lambdaUpdate().eq(AssetEntity::getZcbm, entity.getZcbm()).eq(AssetEntity::getYearAndMonth, entity.getYearAndMonth());
|
|
|
+ baseMapper.update(updateEntity, updateWrapper);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -361,7 +423,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
@Override
|
|
|
public boolean recover(AssetEntity asset) {
|
|
|
|
|
|
- if(Func.isNull(asset.getId())){
|
|
|
+ if (Func.isNull(asset.getId())) {
|
|
|
throw new ServiceException("参数id不能为空");
|
|
|
}
|
|
|
// if (!List.of(AssetStatusEnum.改造.getCode(), AssetStatusEnum.停用.getCode()).contains(asset.getStatus())) {
|
|
|
@@ -406,13 +468,14 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
}
|
|
|
return page.setRecords(list);
|
|
|
}
|
|
|
+
|
|
|
@SneakyThrows
|
|
|
@Override
|
|
|
public void exportZjCqdtWxzctxFyHzb(HttpServletResponse response, XmAssetCostQueryParam dto) {
|
|
|
List<XmAssetCostSummary> list = zjCqdtWxzctxFyHzb(Condition.getPage(new Query().setCurrent(1).setSize(Integer.MAX_VALUE)), dto).getRecords();
|
|
|
AtomicInteger index = new AtomicInteger(1);
|
|
|
|
|
|
- list.forEach(temp -> {
|
|
|
+ list.forEach(temp -> {
|
|
|
temp.setXh(index.getAndIncrement() + "");
|
|
|
});
|
|
|
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/研发费用管理-折旧费用、长期待摊费用、无形资产摊销费用汇总表.xls");
|
|
|
@@ -428,10 +491,10 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
//设置list集合数据
|
|
|
excelWriter.fill(list, fillConfig, writeSheet);
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
String yearAndMonth = dto.getYearAndMonth();
|
|
|
- map.put("yearAndMonth", yearAndMonth.length()==6?yearAndMonth.substring(0,4)+"年"+yearAndMonth.substring(4)+"月":yearAndMonth+"年");
|
|
|
+ map.put("yearAndMonth", yearAndMonth.length() == 6 ? yearAndMonth.substring(0, 4) + "年" + yearAndMonth.substring(4) + "月" : yearAndMonth + "年");
|
|
|
map.put("yqsbzjfySum", list.stream().map(XmAssetCostSummary::getYqsbzjfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("fwzjfySum", list.stream().map(XmAssetCostSummary::getFwzjfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
map.put("cqdtfySum", list.stream().map(XmAssetCostSummary::getCqdtfy).reduce(BigDecimal.ZERO, BigDecimal::add));
|