Browse Source

000000011

zhoulisky 6 months ago
parent
commit
1e69fc71e1

+ 4 - 8
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/XmTechnicianHoursController.java

@@ -88,12 +88,8 @@ public class XmTechnicianHoursController extends KdController {
 	@Operation(summary = "导出")
 	public void export(HttpServletResponse response, @RequestBody XmTechnicianHoursVO param) throws IOException {
 		List<XmTechnicianHoursVO> list = service.selectPage(param, Condition.getPage(new Query().setCurrent(1).setSize(Integer.MAX_VALUE))).getRecords();
-//		if (Func.isEmpty(list)) {
-//			ExportUtil.processWithNoData(response);
-//		} else {
-			ExportUtil.processWithData(response, "每月研发工时打卡.xls");
-			service.export(response.getOutputStream(), list, param.getYearAndMonth());
-//		}
+		ExportUtil.processWithData(response, "每月研发工时打卡.xls");
+		service.export(response.getOutputStream(), list, param.getYearAndMonth());
 	}
 
 	@GetMapping("/list/print")
@@ -120,14 +116,14 @@ public class XmTechnicianHoursController extends KdController {
 	@PostMapping("/sync")
 	@ApiOperationSupport(order = 40)
 	@Operation(summary = "同步至工时系统")
-	public R<Boolean> sync(@RequestBody HoursSyncDto dto){
+	public R<Boolean> sync(@RequestBody HoursSyncDto dto) {
 		return R.status(hoursSyncService.syncHoursData(dto));
 	}
 
 	@PostMapping("accept")
 	@ApiOperationSupport(order = 50)
 	@Operation(summary = "同步至本系统")
-	public R<Boolean> acceptRdData(@RequestBody HoursSyncDto dto){
+	public R<Boolean> acceptRdData(@RequestBody HoursSyncDto dto) {
 		return R.status(hoursSyncService.acceptRdData(dto));
 	}
 

+ 16 - 3
kd-service/kd-scientific/src/main/java/org/sky/scientific/excel/AttendanceMonthlyDataListener.java

@@ -4,10 +4,12 @@ import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.metadata.data.ReadCellData;
 import com.alibaba.excel.read.listener.ReadListener;
 import lombok.Data;
+import org.sky.core.log.exception.ServiceException;
 import org.sky.core.tool.utils.StringUtil;
 import org.sky.scientific.pojo.vo.DailyAttendance;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -24,6 +26,15 @@ public class AttendanceMonthlyDataListener implements ReadListener<Map<Integer,
 	private List<AttendanceMonthlyExcel> records = new ArrayList<>();
 	private boolean headersProcessed = false;
 	private String yearAndMonth;
+	private int daysInMonth;
+
+	public AttendanceMonthlyDataListener(String yearAndMonth) {
+		this.yearAndMonth = yearAndMonth;
+		int year = Integer.parseInt(yearAndMonth.substring(0, 4));
+		int month = Integer.parseInt(yearAndMonth.substring(4));
+		LocalDate startDate = LocalDate.of(year, month, 1);
+		this.daysInMonth = startDate.lengthOfMonth();
+	}
 
 	@Override
 	public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
@@ -83,14 +94,16 @@ public class AttendanceMonthlyDataListener implements ReadListener<Map<Integer,
 		// 解析每日考勤数据
 		int maxDays = Math.min(dateHeaders.size(), dayOfWeekHeaders.size());
 		for (int i = 0; i < maxDays; i++) {
+			int everyDay = Integer.parseInt(dateHeaders.get(i));
+			if(everyDay > daysInMonth){
+				throw new ServiceException(yearAndMonth+"只有"+daysInMonth+"天,请核对日期表头");
+			}
 			String hoursStr = data.get(i + 5); // 考勤数据从第5列开始
 			//没有填报的日期,跳过
 			if (hoursStr != null && !hoursStr.trim().isEmpty()) {
 				try {
-					String date = dateHeaders.get(i);
-					String s = Integer.parseInt(date) <= 9 ? ("0" + date) : date;
 					DailyAttendance daily = new DailyAttendance();
-					daily.setWorkDate(yearAndMonth + s);
+					daily.setWorkDate(yearAndMonth + (everyDay<10?"0"+everyDay:everyDay));
 					daily.setWorkHours(safeParseDouble(hoursStr));
 					record.getDailyAttendances().add(daily);
 				} catch (NumberFormatException e) {

+ 16 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/excel/XmAssetHoursListener.java

@@ -4,11 +4,13 @@ import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.metadata.data.ReadCellData;
 import com.alibaba.excel.read.listener.ReadListener;
 import lombok.Data;
+import org.sky.core.log.exception.ServiceException;
 import org.sky.core.tool.utils.StringUtil;
 import org.sky.scientific.pojo.vo.DailyAttendance;
 import org.sky.scientific.utils.ValidationUtils;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -25,6 +27,15 @@ public class XmAssetHoursListener implements ReadListener<Map<Integer, String>>
 	private List<XmAssetHoursExcel> records = new ArrayList<>();
 	private boolean headersProcessed = false;
 	private String yearAndMonth;
+	private int daysInMonth;
+
+	public XmAssetHoursListener(String yearAndMonth) {
+		this.yearAndMonth = yearAndMonth;
+		int year = Integer.parseInt(yearAndMonth.substring(0, 4));
+		int month = Integer.parseInt(yearAndMonth.substring(4));
+		LocalDate startDate = LocalDate.of(year, month, 1);
+		this.daysInMonth = startDate.lengthOfMonth();
+	}
 
 	@Override
 	public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
@@ -83,12 +94,16 @@ public class XmAssetHoursListener implements ReadListener<Map<Integer, String>>
 
 		// 解析每日工时数据
  		for (int i = 0; i < dateHeaders.size(); i++) {
+			int everyDay = Integer.parseInt(dateHeaders.get(i));
+			if(everyDay > daysInMonth){
+				throw new ServiceException(yearAndMonth+"只有"+daysInMonth+"天,请核对日期表头");
+			}
 			String hoursStr = data.get(i + HOURS_START_COL); // 工时数据从第9列开始
 			//没有填报的日期,跳过
 			if (hoursStr != null && !hoursStr.trim().isEmpty()) {
 				try {
 					DailyAttendance daily = new DailyAttendance();
-					daily.setWorkDate(yearAndMonth + (Integer.parseInt(dateHeaders.get(i))<10?"0"+dateHeaders.get(i):dateHeaders.get(i)));
+					daily.setWorkDate(yearAndMonth + (everyDay<10?"0"+everyDay:everyDay));
 					daily.setWorkHours(safeParseDouble(hoursStr));
 					record.getDailyAttendances().add(daily);
 				} catch (NumberFormatException e) {

+ 17 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/excel/XmTechnicianHoursListener.java

@@ -5,9 +5,11 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
 import com.alibaba.excel.metadata.data.ReadCellData;
 import com.alibaba.excel.read.listener.ReadListener;
 import lombok.Data;
+import org.sky.core.log.exception.ServiceException;
 import org.sky.core.tool.utils.DateUtil;
 import org.sky.scientific.pojo.vo.DailyAttendance;
 
+import java.time.LocalDate;
 import java.util.*;
 
 @Data
@@ -22,6 +24,16 @@ public class XmTechnicianHoursListener implements ReadListener<Map<Integer, Stri
 	private List<XmTechnicianHoursExcel> records = new ArrayList<>();
 	private boolean headersProcessed = false;
 	private String yearAndMonth;
+	private int daysInMonth;
+
+	public XmTechnicianHoursListener(String yearAndMonth) {
+		this.yearAndMonth = yearAndMonth;
+		int year = Integer.parseInt(yearAndMonth.substring(0, 4));
+		int month = Integer.parseInt(yearAndMonth.substring(4));
+		LocalDate startDate = LocalDate.of(year, month, 1);
+		this.daysInMonth = startDate.lengthOfMonth();
+	}
+
 
 	@Override
 	public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
@@ -78,12 +90,16 @@ public class XmTechnicianHoursListener implements ReadListener<Map<Integer, Stri
 
 		// 解析每日工时数据
 		for (int i = 0; i < dateHeaders.size(); i++) {
+			int everyDay = Integer.parseInt(dateHeaders.get(i));
+			if(everyDay > daysInMonth){
+				throw new ServiceException(yearAndMonth+"只有"+daysInMonth+"天,请核对日期表头");
+			}
 			String hoursStr = data.get(i + DATA_START_COL); // 工时数据从第5列开始
 			//没有填报的日期,跳过
 			if (hoursStr != null && !hoursStr.trim().isEmpty()) {
 				try {
 					DailyAttendance daily = new DailyAttendance();
-					daily.setWorkDate(yearAndMonth + (Integer.parseInt(dateHeaders.get(i))<10?"0"+dateHeaders.get(i):dateHeaders.get(i)));
+					daily.setWorkDate(yearAndMonth + (everyDay<10?"0"+everyDay:everyDay));
 					daily.setWorkHours(safeParseDouble(hoursStr));
 					record.getDailyAttendances().add(daily);
 				} catch (NumberFormatException e) {

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

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

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

@@ -61,7 +61,8 @@
             WHERE xm.is_deleted = 0 and DATE_FORMAT(XMKSSJ, '%Y%m') <![CDATA[<=]]> #{yearAndMonth}
         ) xm on xm.id = xa.xm_id
         WHERE #{yearAndMonth} between DATE_FORMAT(xm.XMKSSJ, '%Y%m') and DATE_FORMAT(xm.XMJSSJ,'%Y%m')
-        <if test="zclb!=null and zclb!=''">and s.ZCLB= #{zclb}</if>
+        <if test="type==1">and s.ZCLB= '仪器设备'</if>
+        <if test="type==2">and s.ZCLB= '房屋建筑物'</if>
     </select>
 
     <select id="countByZcbmAfterMonth" resultType="java.lang.Long">

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

@@ -119,9 +119,8 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void importAttendance(MultipartFile file, String yearAndMonth) {
-		AttendanceMonthlyDataListener listener = new AttendanceMonthlyDataListener();
-		listener.setYearAndMonth(yearAndMonth);
-		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
+		AttendanceMonthlyDataListener listener = new AttendanceMonthlyDataListener(yearAndMonth);
+ 		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
 			.registerReadListener(listener)
 			.sheet(0)
 			.headRowNumber(3) // 重要:设置表头行数(0-based)
@@ -135,6 +134,11 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 		if (CollectionUtil.isEmpty(xmTechnicianEntityList)) {
 			throw new ServiceException("未找到项目参研人员名单");
 		}
+
+		SettingEntity one = settingMapper.selectOne(Wrappers.<SettingEntity>lambdaQuery().eq(SettingEntity::getYearAndMonth, yearAndMonth.substring(0, 4)));
+		if (Func.isNull(one) || Func.isNull(one.getWorkHours())) {
+			throw new ServiceException("未设置出勤时间");
+		}
 		List<String> dbUnicodeList = xmTechnicianEntityList.stream().map(XmTechnicianEntity::getUnicode).toList();
 
 		//需要新增的,以便后续批量新增
@@ -156,7 +160,9 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 			}
 			List<AttendanceEntity> dataByTechnicianMonthly = dbList.stream().filter(e -> e.getUnicode().equals(unicode)).toList();
 			for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
-
+				if (dailyAttendance.getWorkHours() > one.getWorkHours()) {
+					throw new ServiceException("出勤时长不能大于出勤时间设置[" + one.getWorkHours() + "]小时");
+				}
 				List<Long> primaryKeyList = dataByTechnicianMonthly.stream().filter(e -> Objects.equals(e.getWorkDate(), dailyAttendance.getWorkDate())).map(AttendanceEntity::getId).toList();
 				Long primaryKey = CollectionUtil.isEmpty(primaryKeyList) ? null : primaryKeyList.get(0);
 				AttendanceEntity entity = new AttendanceEntity();
@@ -178,7 +184,6 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 					if (insertCount == batchCount) {
 						insertList.clear();
 					}
-
 				}
 				if (!updateList.isEmpty() && updateList.size() % batchCount == 0) {
 					int updateCount = baseMapper.batchUpdate(updateList);

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

@@ -61,9 +61,8 @@ public class XmAssetHoursServiceImpl extends BaseServiceImpl<XmAssetHoursMapper,
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void importXmAssetHours(MultipartFile file, String yearAndMonth) {
-		XmAssetHoursListener listener = new XmAssetHoursListener();
-		listener.setYearAndMonth(yearAndMonth);
-		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
+		XmAssetHoursListener listener = new XmAssetHoursListener(yearAndMonth);
+ 		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
 			.registerReadListener(listener)
 			.sheet(0)
 			.headRowNumber(3) // 重要:设置表头行数(0-based)

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

@@ -68,9 +68,8 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public synchronized void importXmTechnicianHours(MultipartFile file, String yearAndMonth) {
-		XmTechnicianHoursListener listener = new XmTechnicianHoursListener();
-		listener.setYearAndMonth(yearAndMonth);
-		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
+		XmTechnicianHoursListener listener = new XmTechnicianHoursListener(yearAndMonth);
+ 		EasyExcel.read(new BufferedInputStream(file.getInputStream()))
 			.registerReadListener(listener)
 			.sheet(0)
 			.headRowNumber(3) // 重要:设置表头行数(0-based)