zhouli 9 months ago
parent
commit
46687bf904

+ 3 - 3
kd-ops/kd-resource/src/main/resources/application-test.yml

@@ -1,6 +1,6 @@
 #数据源配置
 spring:
   datasource:
-    url: ${kd.datasource.home.url}
-    username: ${kd.datasource.home.username}
-    password: ${kd.datasource.home.password}
+    url: ${kd.datasource.test.url}
+    username: ${kd.datasource.test.username}
+    password: ${kd.datasource.test.password}

+ 6 - 0
kd-service/kd-scientific/pom.xml

@@ -31,6 +31,12 @@
             <groupId>org.sky</groupId>
             <artifactId>kd-scientific-api</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.16</version> <!-- 请检查最新版本 -->
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/AssetController.java

@@ -85,7 +85,7 @@ public class AssetController extends KdController {
 	@ApiOperationSupport(order = 5)
 	@Operation(summary = "修改", description = "传入zc")
 	public R update(@Valid @RequestBody AssetEntity asset) {
-		return R.status(service.updateById(asset));
+		return R.status(service.updateAsset(asset));
 	}
 
 	@PostMapping("/remove")

+ 2 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/SubjectEnterpriseMapper.java

@@ -3,6 +3,7 @@ package org.sky.scientific.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Param;
+import org.sky.core.tenant.annotation.TenantIgnore;
 import org.sky.scientific.pojo.entity.SubjectEnterprise;
 
 import java.util.List;
@@ -20,6 +21,7 @@ public interface SubjectEnterpriseMapper extends BaseMapper<SubjectEnterprise> {
 	 * @param subjectEnterprise
 	 * @return
 	 */
+	@TenantIgnore
 	List<SubjectEnterprise> selectSubjectEnterpriseList(IPage<SubjectEnterprise> page, @Param("ew") SubjectEnterprise subjectEnterprise);
 
 	int insertBatch(List<SubjectEnterprise> insertList);

+ 0 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/SubjectEnterpriseMapper.xml

@@ -30,7 +30,6 @@
         </foreach>
     </delete>
 
-
     <select id="selectSubjectEnterpriseList" resultMap="ResultMap">
         select e.id, e.subject_id, e.code, e.name, s.rd_subject_enable, s.ad_subject_enable, e.subject_name
         from kd_subject_enterprise e

+ 2 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/SubjectMapper.xml

@@ -44,9 +44,10 @@
             ) AS "has_children"
         FROM
             kd_subject sub
-        WHERE sub.tenant_id = #{param2.tenantId}
+        <where>
             <if test="param1 != null">and parent_id = #{param1}</if>
             <if test="param2.code!=null and param2.code !=''">and code like concat('%',#{param2.code},'%')</if>
             <if test="param2.name!=null and param2.name !=''">and name like concat('%',#{param2.name},'%')</if>
+        </where>
      </select>
 </mapper>

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/IAssetService.java

@@ -81,4 +81,11 @@ public interface IAssetService extends BaseService<AssetEntity> {
 	 * @return
 	 */
 	List<CostSummaryVO> costSummary(CostSummaryDTO dto);
+
+	/**
+	 * 修改
+	 * @param asset
+	 * @return
+	 */
+	boolean updateAsset(AssetEntity asset);
 }

+ 61 - 18
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/AssetServiceImpl.java

@@ -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);
+	}
+
 }

+ 0 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/SubjectServiceImpl.java

@@ -54,7 +54,6 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
 		if (Func.isEmpty(Func.toStr(subject.get(PARENT_ID)))) {
 			parentId = null;
 		}
-		subject.put("tenantId", SecureUtil.getTenantId());
 		List<SubjectVO> list = baseMapper.lazyList(parentId, subject);
 		return ForestNodeMerger.merge(list);
 	}