zhoulisky 7 months ago
parent
commit
957e35620b
18 changed files with 204 additions and 105 deletions
  1. 1 1
      kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/SalaryController.java
  2. 1 1
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.java
  3. 4 3
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.xml
  4. 2 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmAssetHoursMapper.java
  5. 7 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmAssetHoursMapper.xml
  6. 2 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmFixedAssetMapper.java
  7. 7 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmFixedAssetMapper.xml
  8. 2 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmMapper.java
  9. 8 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmMapper.xml
  10. 1 1
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmTechnicianHoursMapper.xml
  11. 3 1
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsRyrgfyMapper.java
  12. 7 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsRyrgfyMapper.xml
  13. 2 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsWxzctxfyMapper.java
  14. 7 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsWxzctxfyMapper.xml
  15. 2 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsZjfyycqdtfyMapper.java
  16. 7 0
      kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsZjfyycqdtfyMapper.xml
  17. 101 38
      kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/AssetServiceImpl.java
  18. 40 60
      kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/TechnicianServiceImpl.java

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

@@ -68,7 +68,7 @@ public class SalaryController extends KdController {
 		return R.status(service.updateSalary(salary));
 	}
 
-	@PostMapping("/remove")
+	@PostMapping("/clear")
 	@ApiOperationSupport(order = 7)
 	@Operation(summary = "每月工资信息-清除工资数据", description = "多个 unicode、yearAndMonth")
 	public R clearSalary(@RequestBody List<SalaryEntity> salaryList) {

+ 1 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.java

@@ -50,7 +50,7 @@ public interface TechnicianMapper extends BaseMapper<TechnicianEntity> {
 	 * @param list
 	 * @return
 	 */
-	int batchDelete(List<Long> list);
+	int batchDelete(@Param("unicodeList") List<String> unicodeList, @Param("yearAndMonth") String yearAndMonth);
 
 	/**
 	 * 年度科技人员汇总表

+ 4 - 3
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.xml

@@ -44,9 +44,10 @@
 
     <delete id="batchDelete">
         DELETE FROM kd_technician
-        WHERE id IN
-        <foreach item="id" collection="list" separator="," close=")" open="(" index="">
-            #{id}
+        WHERE year_and_month <![CDATA[>=]]> #{yearAndMonth}
+        and unicode IN
+        <foreach item="unicode" collection="unicodeList" separator="," close=")" open="(" index="">
+            #{unicode}
         </foreach>
     </delete>
 

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

@@ -35,4 +35,6 @@ public interface XmAssetHoursMapper extends BaseMapper<XmAssetHoursEntity> {
 	 * @return
 	 */
 	int clearXmAssetHours(@Param("yearAndMonth") String yearAndMonth, @Param("xmId") Long xmId, @Param("assetId") Long assetId);
+
+	Long countByZcbmAfterMonth(@Param("zcbm") String zcbm, @Param("yearAndMonth") String yearAndMonth);
 }

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmAssetHoursMapper.xml

@@ -101,6 +101,13 @@
         </if>
     </select>
 
+    <select id="countByZcbmAfterMonth" resultType="java.lang.Long">
+        select count(*)
+        from kd_xm_asset_hours h
+        left join kd_asset a on h.asset_id = a.id
+        where a.zcbm = #{zcbm} and left(h.work_date,6) <![CDATA[>=]]> #{yearAndMonth}
+    </select>
+
     <delete id="clearXmAssetHours">
         DELETE FROM kd_xm_asset_hours
                WHERE left(work_date,6) = #{yearAndMonth} and xm_id = #{xmId} and asset_id = #{assetId}

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

@@ -49,4 +49,6 @@ public interface XmFixedAssetMapper extends BaseMapper<XmFixedAsset> {
 	 */
 	@TenantIgnore
 	List<XmFixedAssetCostVo> keyanfangwujianzhuwuzhejiufeiyongfenpeibiao(IPage<XmFixedAssetCostVo> page, @Param("ew") XmAssetQueryParam dto);
+
+//	Long countByZcbmAfterMonth(@Param("zcbm") String zcbm, @Param("yearAndMonth") String yearAndMonth);
 }

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmFixedAssetMapper.xml

@@ -148,6 +148,13 @@
         <if test="ew.yzjeMin!=null and ew.yzjeMax!=null">and asset.yzje between #{ew.yzjeMin} and #{ew.yzjeMax}</if>
     </select>
 
+<!--    <select id="countByZcbmAfterMonth" resultType="java.lang.Long">-->
+<!--        select count(*)-->
+<!--        from kd_xm_fixed_asset h-->
+<!--        left join kd_asset a on h.asset_id = a.id-->
+<!--        where a.zcbm = #{zcbm} and h.year_and_month <![CDATA[>=]]> #{yearAndMonth}-->
+<!--    </select>-->
+
     <delete id="physicalDeleteByIds">
         DELETE FROM kd_xm_fixed_asset
         WHERE id IN

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

@@ -98,5 +98,7 @@ public interface XmMapper extends BaseMapper<XmEntity> {
 
 	boolean updateXm(XmUpdateDto dto);
 
+	Long countXmfzrByUnicodeAndYearMonth(@Param("unicode") String unicode, @Param("yearAndMonth") String yearAndMonth);
+
 
 }

+ 8 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmMapper.xml

@@ -260,4 +260,12 @@
         where id = #{xmId}
     </select>
 
+    <select id="countXmfzrByUnicodeAndYearMonth" resultType="java.lang.Long">
+        select
+            COUNT(*)
+        from kd_xm xm
+        left join kd_technician t on t.id = COALESCE(get_xm_info(xm.id, 'XMFZR', #{yearAndMonth}), xm.XMFZR)
+        where t.unicode = #{unicode} and t.year_and_month <![CDATA[>=]]>  #{yearAndMonth}
+    </select>
+
 </mapper>

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

@@ -144,7 +144,7 @@
 
     <select id="countByUnicodeAndMonth" resultType="java.lang.Long">
         select count(*) from kd_xm_technician_hours
-        where unicode = #{unicode} and left(work_date,6) = #{yearAndMonth}
+        where unicode = #{unicode} and left(work_date,6)  <![CDATA[>=]]>  #{yearAndMonth}
     </select>
 
     <select id="selectListForSync" resultType="com.alibaba.fastjson.JSONObject">

+ 3 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsRyrgfyMapper.java

@@ -1,8 +1,8 @@
-
 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.scientific.pojo.entity.YsRyrgfyEntity;
 import org.sky.scientific.pojo.vo.YsRyrgfyVO;
 
@@ -26,4 +26,6 @@ public interface YsRyrgfyMapper extends BaseMapper<YsRyrgfyEntity> {
 	List<YsRyrgfyVO> selectYsRyrgfyPage(IPage page, YsRyrgfyVO ysRyrgfy);
 
 	int physicalDeleteByIds(List<Long> ids);
+
+	Long countByUnicodeAndYearMonth(@Param("unicode") String unicode, @Param("yearAndMonth") String yearMonth);
 }

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsRyrgfyMapper.xml

@@ -38,4 +38,11 @@
 
     </select>
 
+    <select id="countByUnicodeAndYearMonth" resultType="java.lang.Long">
+        SELECT count(*)
+        from kd_ys_ryrgfy r
+        left  join kd_technician t on t.id = r.technician_id
+        where t.unicode = #{unicode} and t.year_and_month <![CDATA[>=]]>  #{yearAndMonth}
+    </select>
+
 </mapper>

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

@@ -35,4 +35,6 @@ public interface YsWxzctxfyMapper extends BaseMapper<YsWxzctxfyEntity> {
     int physicalDeleteByIds(List<Long> ids);
 
 	List<YsWxzctxfyVO> selectByYearAndMonth(String yearAndMonth);
+
+    long countByZcbmAfterMonth(@Param("zcbm") String zcbm, @Param("yearAndMonth") String yearAndMonth);
 }

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsWxzctxfyMapper.xml

@@ -53,4 +53,11 @@
         WHERE #{yearAndMonth} between DATE_FORMAT(xm.XMKSSJ, '%Y%m') and DATE_FORMAT(xm.XMJSSJ,'%Y%m')
     </select>
 
+    <select id="countByZcbmAfterMonth" resultType="java.lang.Long">
+        select count(*)
+        from kd_ys_wxzctxfy h
+        left join kd_asset a on h.asset_id = a.id
+        where a.zcbm = #{zcbm} and a.year_and_month <![CDATA[>=]]> #{yearAndMonth}
+    </select>
+
 </mapper>

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

@@ -41,4 +41,6 @@ public interface YsZjfyycqdtfyMapper extends BaseMapper<YsZjfyycqdtfyEntity> {
 	 * @return List<YsZjfyycqdtfyEntity>
 	 */
 	List<YsZjfyycqdtfyEntity> selectByYearAndMonth(@Param("yearAndMonth") String yearAndMonth, @Param("zclb") String zclb);
+
+    long countByZcbmAfterMonth(@Param("zcbm") String zcbm, @Param("yearAndMonth") String yearAndMonth);
 }

+ 7 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsZjfyycqdtfyMapper.xml

@@ -63,4 +63,11 @@
         <if test="zclb!=null and zclb!=''">and s.ZCLB= #{zclb}</if>
     </select>
 
+    <select id="countByZcbmAfterMonth" resultType="java.lang.Long">
+        select count(*)
+        from kd_ys_zjfyycqdtfy h
+        left join kd_asset a on h.asset_id = a.id
+        where a.zcbm = #{zcbm} and a.year_and_month <![CDATA[>=]]> #{yearAndMonth}
+    </select>
+
 </mapper>

+ 101 - 38
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/AssetServiceImpl.java

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

+ 40 - 60
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/TechnicianServiceImpl.java

@@ -62,11 +62,10 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 	private final YsRyrgfyMapper ysRyrgfyMapper;
 	private final XmTechnicianMapper xmTechnicianMapper;
 	private final XmMapper xmMapper;
-	private final XmTechnicianHoursMapper xmTechnicianHoursMapper;
+	private final XmTechnicianHoursMapper hoursMapper;
 	private final DepartmentMapper departmentMapper;
 	private final SalaryMapper salaryMapper;
 	private final AttendanceMapper attendanceMapper;
-	private final XmBgrzMapper xmBgrzMapper;
 
 	@Override
 	public boolean insertTechnician(TechnicianEntity technician) {
@@ -81,26 +80,8 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		if (Func.notNull(unicode)) {
 			throw new ServiceException("工号或身份证已存在");
 		}
-//		if (unicode == null) {
-//			unicode = generateUnicode();
-//		}
 		technician.setUnicode(generateUnicode());
-
-//		if (Func.isNull(technician.getId())) {
-		//新增
 		return this.save(technician);
-//		} else {
-//			//修改technician.getYearAndMonth()及之后月份的数据
-//			LambdaQueryWrapper<TechnicianEntity> updateWrapper = Wrappers.<TechnicianEntity>lambdaQuery().eq(TechnicianEntity::getUnicode, technician.getUnicode()).ge(TechnicianEntity::getYearAndMonth, technician.getYearAndMonth());
-//			technician.setId(null);
-//			technician.setTenantId(null);
-//			technician.setUnicode(null);
-//			technician.setYearAndMonth(null);
-//			technician.setCreateTime(null);
-//			technician.setCreateUser(null);
-//			technician.setCreateDept(null);
-//			return this.update(technician, updateWrapper);
-//		}
 	}
 
 	@Override
@@ -112,32 +93,20 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 			throw new ServiceException("工号和身份证号码不能同时为空");
 		}
 
-		if(Func.isBlank(technician.getUnicode())){
+		if (Func.isBlank(technician.getUnicode())) {
 			throw new ServiceException("参数unicode不能为空");
 		}
 
-//		String unicode = baseMapper.getUnicodeByNumberAndIdentityCard(technician.getNumber(), technician.getIdCard());
-//
-//		if (unicode == null) {
-//			unicode = generateUnicode();
-//		}
-//		technician.setUnicode(unicode);
-
-//		if (Func.isNull(technician.getId())) {
-//			//新增
-//			return this.save(technician);
-//		} else {
-			//修改technician.getYearAndMonth()及之后月份的数据
-			LambdaQueryWrapper<TechnicianEntity> updateWrapper = Wrappers.<TechnicianEntity>lambdaQuery().eq(TechnicianEntity::getUnicode, technician.getUnicode()).ge(TechnicianEntity::getYearAndMonth, technician.getYearAndMonth());
-			technician.setId(null);
-			technician.setTenantId(null);
-			technician.setUnicode(null);
-			technician.setYearAndMonth(null);
-			technician.setCreateTime(null);
-			technician.setCreateUser(null);
-			technician.setCreateDept(null);
-			return this.update(technician, updateWrapper);
-//		}
+		//修改technician.getYearAndMonth()及之后月份的数据
+		LambdaQueryWrapper<TechnicianEntity> updateWrapper = Wrappers.<TechnicianEntity>lambdaQuery().eq(TechnicianEntity::getUnicode, technician.getUnicode()).ge(TechnicianEntity::getYearAndMonth, technician.getYearAndMonth());
+		technician.setId(null);
+		technician.setTenantId(null);
+		technician.setUnicode(null);
+		technician.setYearAndMonth(null);
+		technician.setCreateTime(null);
+		technician.setCreateUser(null);
+		technician.setCreateDept(null);
+		return this.update(technician, updateWrapper);
 	}
 
 	@Override
@@ -307,23 +276,11 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 			if (Func.isNull(dbTechnician)) {
 				throw new ServiceException("删除失败,技术人员不存在");
 			}
+			technician.setUnicode(dbTechnician.getUnicode());
 			//删除人员花名册时需判断数据是否被引入
-			//项目负责人
-			Long xmBgCount = xmBgrzMapper.selectCount(Wrappers.<XmBgrzEntity>lambdaQuery().eq(XmBgrzEntity::getZdmc, "XMFZR").eq(XmBgrzEntity::getBgqdz, dbTechnician.getId()).or().eq(XmBgrzEntity::getBghdz, dbTechnician.getId()));
-			if (xmMapper.selectCount(Wrappers.<XmEntity>lambdaQuery().eq(XmEntity::getXmfzr, technician.getId())) > 0 || xmBgCount > 0) {
-				throw new ServiceException("删除失败,[" + dbTechnician.getName() + "]是项目负责人");
-			}
-
-			//每月参研人员名单
-			if (xmTechnicianMapper.selectCount(Wrappers.<XmTechnicianEntity>lambdaQuery().eq(XmTechnicianEntity::getUnicode, dbTechnician.getUnicode()).eq(XmTechnicianEntity::getYearAndMonth, dbTechnician.getYearAndMonth())) > 0) {
-				throw new ServiceException("删除失败,每月参研人员名单引用了[" + dbTechnician.getName() + "]");
-			}
-			//项目预算表
-			if (ysRyrgfyMapper.selectCount(Wrappers.<YsRyrgfyEntity>lambdaQuery().eq(YsRyrgfyEntity::getTechnicianId, technician.getId())) > 0) {
-				throw new ServiceException("删除失败,研发项目费用预算-人员人工费用引入了[" + dbTechnician.getName() + "]");
-			}
+			canDeleteTechnician(dbTechnician.getUnicode(), dbTechnician.getYearAndMonth(), dbTechnician.getName());
 		}
-		return baseMapper.batchDelete(list.stream().map(TechnicianEntity::getId).toList()) > 0;
+		return baseMapper.batchDelete(list.stream().map(TechnicianEntity::getUnicode).toList(), list.get(0).getYearAndMonth()) > 0;
 	}
 
 	@Transactional
@@ -451,6 +408,7 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		if (Func.isNull(dbXmTechnician)) {
 			throw new ServiceException("数据不存在");
 		}
+
 		//每月研发人员工资
 		if (salaryMapper.selectCount(Wrappers.<SalaryEntity>lambdaQuery().eq(SalaryEntity::getYearAndMonth, dbXmTechnician.getYearAndMonth()).eq(SalaryEntity::getUnicode, dbXmTechnician.getUnicode())) > 0) {
 			throw new ServiceException("每月研发人员工资引用了该数据,无法删除");
@@ -460,12 +418,34 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 			throw new ServiceException("每月研发人员出勤引用了该数据,无法删除");
 		}
 		//每月研发人员工时
-		if (xmTechnicianHoursMapper.countByUnicodeAndMonth(dbXmTechnician.getUnicode(), dbXmTechnician.getYearAndMonth()) > 0) {
+		if (hoursMapper.countByUnicodeAndMonth(dbXmTechnician.getUnicode(), dbXmTechnician.getYearAndMonth()) > 0) {
 			throw new ServiceException("每月研发人员工时引用了该数据,无法删除");
 		}
 		return xmTechnicianMapper.physicalDeleteXmTechnicianMonthlyById(id) == 1;
 	}
 
+	private void canDeleteTechnician(String unicode, String yeaAndMonth, String name) {
+
+		if (xmMapper.countXmfzrByUnicodeAndYearMonth(unicode, yeaAndMonth) > 0) {
+			throw new ServiceException("删除失败,[" + name + "]是项目负责人");
+		}
+ 		if (xmTechnicianMapper.selectCount(Wrappers.<XmTechnicianEntity>lambdaQuery().eq(XmTechnicianEntity::getUnicode, unicode).ge(XmTechnicianEntity::getYearAndMonth, yeaAndMonth)) > 0) {
+			throw new ServiceException("删除失败,每月参研人员名单引用了[" + name + "]");
+		}
+ 		if (ysRyrgfyMapper.countByUnicodeAndYearMonth(unicode, yeaAndMonth) > 0) {
+			throw new ServiceException("删除失败,研发项目费用预算-人员人工费用引用了[" + name + "]");
+		}
+ 		if (salaryMapper.selectCount(Wrappers.<SalaryEntity>lambdaQuery().eq(SalaryEntity::getUnicode, unicode).ge(SalaryEntity::getYearAndMonth, yeaAndMonth)) > 0) {
+			throw new ServiceException("删除失败,每月研发人员工资引用了[" + name + "]");
+		}
+ 		if (attendanceMapper.selectCount(Wrappers.<AttendanceEntity>lambdaQuery().eq(AttendanceEntity::getUnicode, unicode).apply("LEFT(work_date,6) >= {0}", yeaAndMonth)) > 0) {
+			throw new ServiceException("删除失败,每月研发人员出勤引用了[" + name + "]");
+		}
+ 		if(hoursMapper.selectCount(Wrappers.<XmTechnicianHours>lambdaQuery().eq(XmTechnicianHours::getUnicode, unicode).apply("LEFT(work_date,6) >= {0}", yeaAndMonth)) > 0){
+			throw new ServiceException("删除失败,每月研发工时打卡引用了[" + name + "]");
+		}
+	}
+
 	@Override
 	public IPage<TechnicianEntity> selectTechnicianPageByDateInterval(IPage<TechnicianEntity> page, HashMap<String, String> param) {
 		if (!param.containsKey("startDate") || !param.containsKey("endDate")) {
@@ -513,7 +493,7 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 			// 参研项目列表
 			vo.setXmList(xmTechnicianMapper.selectXmListByUnicodeAndYear(vo.getUnicode(), entity.getYearAndMonth()));
 			// 参研时长列表
-			List<DailyAttendance> attendances = xmTechnicianHoursMapper.selectHoursListByUnicodeAndYear(vo.getUnicode(), entity.getYearAndMonth());
+			List<DailyAttendance> attendances = hoursMapper.selectHoursListByUnicodeAndYear(vo.getUnicode(), entity.getYearAndMonth());
 			vo.setHoursList(attendances);
 		}
 		return page.setRecords(list);