|
|
@@ -9,7 +9,6 @@ import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -22,8 +21,6 @@ import org.sky.core.secure.utils.SecureUtil;
|
|
|
import org.sky.core.tool.utils.*;
|
|
|
import org.sky.scientific.excel.AssetExcel;
|
|
|
import org.sky.scientific.mapper.AssetMapper;
|
|
|
-import org.sky.scientific.mapper.XmAssetHoursMapper;
|
|
|
-import org.sky.scientific.mapper.XmMapper;
|
|
|
import org.sky.scientific.pojo.dto.AssetDTO;
|
|
|
import org.sky.scientific.pojo.dto.CostSummaryDTO;
|
|
|
import org.sky.scientific.pojo.dto.XmAssetCostQueryParam;
|
|
|
@@ -54,11 +51,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
@Service
|
|
|
public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity> implements IAssetService {
|
|
|
|
|
|
- @Resource
|
|
|
- private XmMapper xmMapper;
|
|
|
- @Resource
|
|
|
- private XmAssetHoursMapper xmAssetHoursMapper;
|
|
|
-
|
|
|
@Override
|
|
|
public IPage<AssetVO> selectAssetPage(IPage<AssetVO> page, AssetDTO dto) {
|
|
|
return page.setRecords(baseMapper.selectAssetPage(page, dto));
|
|
|
@@ -66,12 +58,35 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
@Override
|
|
|
public boolean saveAsset(AssetEntity asset) {
|
|
|
- if(StringUtil.isBlank(asset.getYearAndMonth())){
|
|
|
+ if (StringUtil.isBlank(asset.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
+ LambdaQueryWrapper<AssetEntity> qw = Wrappers.<AssetEntity>lambdaQuery().eq(AssetEntity::getZcbm, asset.getZcbm()).eq(AssetEntity::getYearAndMonth, asset.getYearAndMonth());
|
|
|
+ if (this.baseMapper.selectCount(qw) > 0) {
|
|
|
+ throw new ServiceException("资产【" + asset.getZcbm() + "】已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
+// 仪器设置的算法:当前时间为2025年01月-2024年5月,差额为9个月,因为折旧从次月开始,所以已使用月数为8个月(即9-1=8),再将使用寿命-已使用月份数=0时,即已足额折旧。
|
|
|
+// 无形资产:当月即摊销,不需要-1
|
|
|
+
|
|
|
+ long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(cn.hutool.core.date.DateUtil.date(), asset.getKssj(), false);
|
|
|
+// 这里
|
|
|
+ if (!Func.equals("仪器设备", asset.getZclb())) {
|
|
|
+ ysysm++;
|
|
|
+ }
|
|
|
+ asset.setYsysm((int) ysysm);
|
|
|
+ asset.setStatus((asset.getSysm() - asset.getYsysm() <= 0) ? 2 : 0);
|
|
|
return this.save(asset);
|
|
|
}
|
|
|
|
|
|
+// public static void main(String[] args) {
|
|
|
+//
|
|
|
+//// long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(DateUtil.parse("202501", DateUtil.PATTERN_YYYYMM), DateUtil.parse("202405", DateUtil.PATTERN_YYYYMM), true);
|
|
|
+// long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(new Date(), new Date(), true);
|
|
|
+// System.out.println(ysysm);
|
|
|
+// }
|
|
|
+
|
|
|
@Override
|
|
|
public void importAsset(MultipartFile file, String yearAndMonth) {
|
|
|
|
|
|
@@ -114,9 +129,9 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
// okCount++;
|
|
|
temp.setYearAndMonth(zc.getYearAndMonth());
|
|
|
|
|
|
- temp.setYsysm(Func.toInt(temp.getYsysm(), 0)+ 1);
|
|
|
+ temp.setYsysm(Func.toInt(temp.getYsysm(), 0) + 1);
|
|
|
//使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
- temp.setStatus((temp.getSysm() - temp.getYsysm() == 0) ? 2 : 0);
|
|
|
+ temp.setStatus((temp.getSysm() - temp.getYsysm() <= 0) ? 2 : 0);
|
|
|
temp.setId(null);
|
|
|
this.save(temp);
|
|
|
}
|
|
|
@@ -141,10 +156,10 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
Query query = new Query().setCurrent(1).setSize(Integer.MAX_VALUE);
|
|
|
List<AssetVO> assetVOList = this.selectAssetPage(Condition.getPage(query), dto).getRecords();
|
|
|
- if(CollectionUtil.isEmpty(assetVOList)){
|
|
|
+ if (CollectionUtil.isEmpty(assetVOList)) {
|
|
|
throw new ServiceException("企业科研资产无数据!");
|
|
|
}
|
|
|
- AtomicInteger i= new AtomicInteger(1);
|
|
|
+ AtomicInteger i = new AtomicInteger(1);
|
|
|
assetVOList.forEach(temp -> {
|
|
|
// temp.setGenderName(DictCache.getValue(DictEnum.SEX, temp.getGender()));
|
|
|
temp.setXh(i.getAndIncrement());
|
|
|
@@ -170,16 +185,16 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
@Override
|
|
|
public IPage<XmAssetCostSummary> zjCqdtWxzctxFyHzb(IPage<XmAssetCostSummary> page, XmAssetCostQueryParam dto) {
|
|
|
- if(Func.isBlank(dto.getYearAndMonth())){
|
|
|
+ if (Func.isBlank(dto.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
List<XmAssetCostSummary> list = null;
|
|
|
dto.setTenantId(SecureUtil.getTenantId());
|
|
|
- if(dto.getYearAndMonth().length() == 6){
|
|
|
+ if (dto.getYearAndMonth().length() == 6) {
|
|
|
list = baseMapper.zjCqdtWxzctxFyHzbByYearAndMonth(page, dto);
|
|
|
- }else if(dto.getYearAndMonth().length() == 4){
|
|
|
+ } else if (dto.getYearAndMonth().length() == 4) {
|
|
|
list = baseMapper.zjCqdtWxzctxFyHzbByYear(page, dto);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new ServiceException("参数yearAndMonth格式错误,yyyyMM或yyyy");
|
|
|
}
|
|
|
|
|
|
@@ -191,7 +206,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
@Override
|
|
|
public List<CostSummaryVO> costSummary(CostSummaryDTO dto) {
|
|
|
- if(Func.isBlank(dto.getYearAndMonth())){
|
|
|
+ if (Func.isBlank(dto.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
|
|
|
@@ -210,4 +225,32 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean updateAsset(AssetEntity asset) {
|
|
|
+ if(Func.isNull(asset.getId())){
|
|
|
+ throw new ServiceException("参数id不能为空");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<AssetEntity> qw = Wrappers.<AssetEntity>lambdaQuery().eq(AssetEntity::getZcbm, asset.getZcbm()).eq(AssetEntity::getYearAndMonth, asset.getYearAndMonth());
|
|
|
+ AssetEntity dbAsset = this.getOne(qw);
|
|
|
+ if (dbAsset != null && Func.equals(dbAsset.getZcbm(), asset.getZcbm()) && !Func.equals(dbAsset.getId(), asset.getId())) {
|
|
|
+ throw new ServiceException("资产【" + asset.getZcbm() + "】已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //使用寿命-已使用月份数=0时,即已足额折旧
|
|
|
+// 仪器设置的算法:当前时间为2025年01月-2024年5月,差额为9个月,因为折旧从次月开始,所以已使用月数为8个月(即9-1=8),再将使用寿命-已使用月份数=0时,即已足额折旧。
|
|
|
+// 无形资产:当月即摊销,不需要-1
|
|
|
+
|
|
|
+ if(Func.isNull(asset.getYsysm())){
|
|
|
+ long ysysm = cn.hutool.core.date.DateUtil.betweenMonth(cn.hutool.core.date.DateUtil.date(), asset.getKssj(), false);
|
|
|
+// 这里
|
|
|
+ if (!Func.equals("仪器设备", asset.getZclb())) {
|
|
|
+ ysysm++;
|
|
|
+ }
|
|
|
+ asset.setYsysm((int) ysysm);
|
|
|
+ }
|
|
|
+
|
|
|
+ asset.setStatus((asset.getSysm() - asset.getYsysm() <= 0) ? 2 : 0);
|
|
|
+ return this.updateById(asset);
|
|
|
+ }
|
|
|
+
|
|
|
}
|