Browse Source

00000003356666

zhoulisky 5 months ago
parent
commit
56bba6aea0

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

@@ -89,7 +89,7 @@
         </foreach>
     </insert>
 
-    <select id="selectByYearAndMonth" resultMap="ResultMap" parameterType="java.lang.String">
+    <select id="selectByYearAndMonth" resultMap="ResultMap">
         select id, xm_id, asset_id, work_date, work_hours
         from kd_xm_asset_hours
         where left(work_date,6) = #{yearAndMonth}

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

@@ -94,7 +94,7 @@
             parameterType="org.sky.scientific.pojo.dto.XmAssetQueryParam">
         SELECT
             v1.xm_id, xm.xmmc, xm.xmbh,v1.year_and_month,
-            ZCBM as 'asset.ZCBM',ZCMC as 'asset.ZCMC', ZCLB as 'asset.ZCLB', GL as 'asset.GL',YT as 'asset.YT',ZCYZ as 'asset.ZCYZ',JCZ as 'asset.JCZ',YZJE as 'asset.YZJE',
+            ZCBM as 'asset.ZCBM',ZCMC as 'asset.ZCMC', ZCLB as 'asset.ZCLB', GL as 'asset.GL',YT as 'asset.YT',ZCYZ as 'asset.ZCYZ',JCZ as 'asset.JCZ', ifnull(YZJE,0) as 'asset.YZJE',
             v1.attendanceHours,v1.workHours,v1.yanfaFenTanLv,v1.yanfaTanXiao
         FROM wuxingAssetCostView v1
         LEFT JOIN

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

@@ -153,7 +153,7 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 			//保存
 			String unicode = technicianMapper.getUnicodeByNumberAndIdentityCard(record.getNumber(), record.getIdCard());
 			if (unicode == null) {
-				throw new ServiceException("序号为[" + record.getSerialNumber() + "]的工号和者身份证都不存在");
+				throw new ServiceException(TechnicianServiceImpl.getTechnicianNotExistTips(record.getNumber(), record.getIdCard()));
 			}
 			if (!dbUnicodeList.contains(unicode)) {
 				throw new ServiceException("序号为[" + record.getSerialNumber() + "]的研发人员不在参研人员名单");

+ 3 - 7
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/SalaryServiceImpl.java

@@ -264,14 +264,10 @@ public class SalaryServiceImpl extends BaseServiceImpl<SalaryMapper, SalaryEntit
 				throw new ServiceException("序号为[" + excel.getXh() + "]的工号和身份证不能都为空");
 			}
 			//根据工号或者身份证查询technicianId
-//			LambdaQueryWrapper<TechnicianEntity> wrapper = Wrappers.<TechnicianEntity>lambdaQuery()
-//				.eq(TechnicianEntity::getYearAndMonth, yearAndMonth)
-//				.and(t -> t.eq(TechnicianEntity::getNumber, excel.getNumber()).eq(TechnicianEntity::getIdCard, excel.getIdCard()));
-//			TechnicianEntity dbTechnician = technicianMapper.selectOne(wrapper);
+
 			String unicode = technicianMapper.getUnicodeByNumberAndIdentityCard(excel.getNumber(), excel.getIdCard());
-////			TechnicianEntity dbTechnician = (TechnicianEntity) unicode
-			if (Func.isNull(unicode)) {
-				throw new ServiceException("序号为[" + excel.getXh() + "]的工号和者身份证都不存在");
+ 			if (Func.isNull(unicode)) {
+				throw new ServiceException(TechnicianServiceImpl.getTechnicianNotExistTips(excel.getNumber(), excel.getIdCard()));
 			}
 
 			//非本月实际参研人员,提示“某某非本月实际参研人员,请核对数据”

+ 12 - 4
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/TechnicianServiceImpl.java

@@ -82,9 +82,6 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		}
 
 		String unicode = baseMapper.getUnicodeByNumberAndIdentityCard(technician.getNumber(), technician.getIdCard());
-//		if (Func.notNull(unicode)) {
-//			throw new ServiceException("工号或身份证已存在");
-//		}
 		if(Func.isBlank(unicode)){
 			unicode = generateUnicode();
 		}else {
@@ -834,7 +831,7 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		for (XmTechnicianEntity xmTechnician : dataList) {
 			String unicode = baseMapper.getUnicodeByNumberAndIdentityCard(xmTechnician.getNumber(), xmTechnician.getIdCard());
 			if (Func.isBlank(unicode)) {
-				throw new ServiceException("工号[" + xmTechnician.getNumber() + "]/身份证[" + xmTechnician.getIdCard() + "]不存在");
+				throw new ServiceException(getTechnicianNotExistTips(xmTechnician.getNumber(), xmTechnician.getIdCard()));
 			}
 			Long xmId = xmMapper.getXmIdByXmmcOrXmbh(null, null, xmTechnician.getXmbh());
 			if (Func.isNull(xmId)) {
@@ -860,4 +857,15 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		return true;
 	}
 
+	public static String getTechnicianNotExistTips(String number, String idCard){
+		StringBuilder builder = new StringBuilder();
+		if(Func.isNotBlank(number)){
+			builder.append("工号[").append(number).append("]");
+		}
+		if(Func.isNotBlank(idCard)){
+			builder.append("身份证[").append(idCard).append("]");
+		}
+ 		return builder.append("不存在").toString();
+	}
+
 }

+ 40 - 3
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/XmAssetHoursServiceImpl.java

@@ -41,6 +41,7 @@ import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 /**
  * 科研仪器设备工时 服务实现类
@@ -62,7 +63,7 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
 	@Override
 	public void importXmAssetHours(MultipartFile file, String yearAndMonth) {
 		XmAssetHoursListener listener = new XmAssetHoursListener(yearAndMonth);
- 		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
+		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
 			.registerReadListener(listener)
 			.sheet(0)
 			.headRowNumber(3) // 重要:设置表头行数(0-based)
@@ -102,8 +103,27 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
 			updateZgs(dbAsset.getId(), record.getZgs(), yearAndMonth);
 
 			List<XmAssetHoursEntity> byXmAndAssetList = dbList.stream().filter(e -> e.getXmId().equals(xmId) && e.getAssetId().equals(dbAsset.getId())).toList();
+
+			List<XmAssetHoursEntity> dbAssetHours = baseMapper.selectByYearAndMonth(yearAndMonth, null, dbAsset.getId());
 			for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
 
+				Map<String, List<XmAssetHoursEntity>> mapByDate = dbAssetHours.stream().collect(Collectors.groupingBy(XmAssetHoursEntity::getWorkDate));
+				List<XmAssetHoursEntity> dbHourList = mapByDate.get(dailyAttendance.getWorkDate());
+				if(Func.isEmpty(dbHourList) ){
+					dbHourList = new ArrayList<>();
+					mapByDate.put(dailyAttendance.getWorkDate(), dbHourList);
+				}
+				for (XmAssetHoursEntity hours : dbHourList) {
+					if(Func.equals(hours.getWorkDate(), dailyAttendance.getWorkDate()) && Func.equals(hours.getXmId(), xmId)){
+						hours.setWorkHours(dailyAttendance.getWorkHours());
+						break;
+					}
+				}
+				double totalHoursByDay = dbHourList.stream().mapToDouble(XmAssetHoursEntity::getWorkHours).sum();
+				if(totalHoursByDay > 24){
+					throw new ServiceException("设备在" + dailyAttendance.getWorkDate() +"这天的工时超过了24小时,请核对数据");
+				}
+
 				List<Long> primaryKeyList = byXmAndAssetList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(XmAssetHoursEntity::getId).toList();
 				Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
 				XmAssetHoursEntity entity = new XmAssetHoursEntity();
@@ -160,7 +180,7 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
 		return page.setRecords(list);
 	}
 
-	private void updateZgs(Long assetId, Double zgs, String yearAndMonth){
+	private void updateZgs(Long assetId, Double zgs, String yearAndMonth) {
 		if (zgs != null) {
 			//不能大于当月工作天数(自然天数)X24小时
 			// 解析年份和月份
@@ -208,8 +228,25 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
 		//需要更新的,以便后续批量修改
 		List<XmAssetHoursEntity> updateList = new ArrayList<>();
 
-		for (DailyAttendance dailyAttendance : dto.getDailyHoursList()) {
+		List<XmAssetHoursEntity> dbAssetHours = baseMapper.selectByYearAndMonth(dto.getYearAndMonth(), null, dto.getAssetId());
 
+		for (DailyAttendance dailyAttendance : dto.getDailyHoursList()) {
+			Map<String, List<XmAssetHoursEntity>> mapByDate = dbAssetHours.stream().collect(Collectors.groupingBy(XmAssetHoursEntity::getWorkDate));
+			List<XmAssetHoursEntity> dbHourList = mapByDate.get(dailyAttendance.getWorkDate());
+			if(Func.isEmpty(dbHourList) ){
+				dbHourList = new ArrayList<>();
+				mapByDate.put(dailyAttendance.getWorkDate(), dbHourList);
+			}
+			for (XmAssetHoursEntity hours : dbHourList) {
+				if(Func.equals(hours.getWorkDate(), dailyAttendance.getWorkDate()) && Func.equals(hours.getXmId(), dto.getXmId())){
+					hours.setWorkHours(dailyAttendance.getWorkHours());
+					break;
+				}
+			}
+			double totalHoursByDay = dbHourList.stream().mapToDouble(XmAssetHoursEntity::getWorkHours).sum();
+			if(totalHoursByDay > 24){
+				throw new ServiceException("设备在" + dailyAttendance.getWorkDate() +"这天的工时超过了24小时,请核对数据");
+			}
 			List<Long> primaryKeyList = dbList.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(XmAssetHoursEntity::getId).toList();
 			Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
 			XmAssetHoursEntity entity = new XmAssetHoursEntity();

+ 7 - 6
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/XmIntangibleAssetServiceImpl.java

@@ -105,11 +105,11 @@ public class XmIntangibleAssetServiceImpl extends BaseServiceImpl<XmIntangibleAs
 				if (jtXmIdList.contains(dbAsset.getXmId())) {
 					continue;
 				}
-				if(xmService.judgeXmIsOver(dbAsset.getXmId(), false)){
+				if (xmService.judgeXmIsOver(dbAsset.getXmId(), false)) {
 					jtXmIdList.add(dbAsset.getXmId());
 					continue;
 				}
-				if(!Func.equals(dbAsset.getAsset().getStatus(), AssetStatusEnum.正常.getCode())){
+				if (!Func.equals(dbAsset.getAsset().getStatus(), AssetStatusEnum.正常.getCode())) {
 					continue;
 				}
 				XmIntangibleAsset asset = new XmIntangibleAsset();
@@ -132,11 +132,11 @@ public class XmIntangibleAssetServiceImpl extends BaseServiceImpl<XmIntangibleAs
 				if (jtXmIdList.contains(ys.getXmId())) {
 					continue;
 				}
-				if(xmService.judgeXmIsOver(ys.getXmId(), false)){
+				if (xmService.judgeXmIsOver(ys.getXmId(), false)) {
 					jtXmIdList.add(ys.getXmId());
 					continue;
 				}
-				if(!Func.equals(ys.getZcEntity().getStatus(), AssetStatusEnum.正常.getCode())){
+				if (!Func.equals(ys.getZcEntity().getStatus(), AssetStatusEnum.正常.getCode())) {
 					continue;
 				}
 				XmIntangibleAsset asset = new XmIntangibleAsset();
@@ -203,7 +203,7 @@ public class XmIntangibleAssetServiceImpl extends BaseServiceImpl<XmIntangibleAs
 			}
 			assetIdMap.put(assetkey, dbAsset);
 
-			if(!Func.equals(dbAsset.getStatus(), AssetStatusEnum.正常.getCode())){
+			if (!Func.equals(dbAsset.getStatus(), AssetStatusEnum.正常.getCode())) {
 				throw new ServiceException("序号为[" + excel.getXh() + "]的资产状态非正常");
 			}
 
@@ -316,6 +316,7 @@ public class XmIntangibleAssetServiceImpl extends BaseServiceImpl<XmIntangibleAs
 		dto.setTenantId(SecureUtil.getTenantId());
 		List<XmIntangibleAssetCostVo> list = baseMapper.keyanwuxingzichantanxiaofeiyongfenpeibiao(page, dto);
 		for (XmIntangibleAssetCostVo vo : list) {
+			AssetEntity asset = vo.getAsset();
 			//研发分摊率=月研发工时/月总工时
 			if (vo.getAttendanceHours() == 0 || vo.getWorkHours() == 0) {
 				vo.setYanfaFenTanLv(0);
@@ -323,7 +324,7 @@ public class XmIntangibleAssetServiceImpl extends BaseServiceImpl<XmIntangibleAs
 				vo.setYanfaFenTanLv(vo.getWorkHours() / vo.getAttendanceHours());
 			}
 			//研发摊销=(月折旧额/月摊销额(元)) * 研发分摊率
-			vo.setYanfaTanXiao(vo.getAsset().getYzje().doubleValue() * vo.getYanfaFenTanLv());
+			vo.setYanfaTanXiao(asset != null ? asset.getYzje().doubleValue() * vo.getYanfaFenTanLv() : 0.0);
 		}
 		return page.setRecords(list);
 	}

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

@@ -131,7 +131,7 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
 			} else {
 				unicode = technicianMapper.getUnicodeByNumberAndIdentityCard(record.getNumber(), record.getIdCard());
 				if (unicode == null) {
-					throw new ServiceException("序号为[" + record.getSerialNumber() + "]的研发人员不存在");
+					throw new ServiceException(TechnicianServiceImpl.getTechnicianNotExistTips(record.getNumber(), record.getIdCard()));
 				}
 				technicianMap.put(techniciankey, unicode);
 			}