Browse Source

9999999999

zhoulisky 5 months ago
parent
commit
ba513bad62

+ 6 - 1
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/entity/DownloadTask.java

@@ -1,6 +1,7 @@
 
 package org.sky.scientific.pojo.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -47,7 +48,7 @@ public class DownloadTask extends TenantEntity {
 	@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
 	private Date expireTime;
 
-	@Schema(description = "状态,0:进行中,2:已完成,3:已过期")
+	@Schema(description = "状态,0:进行中,2:已完成,4:已超时/已删除")
 	private Integer status;
 
 	@Schema(description = "压缩文件的路径")
@@ -60,4 +61,8 @@ public class DownloadTask extends TenantEntity {
 	@Schema(description = "类型,0:一键下载,1:一键导出高新被查,2:一键导出加计被查")
 	@NotNull(message = "参数type不能为空")
 	private Integer type;
+
+	@Schema(description = "下载任务是否已删除")
+	@TableField(exist = false)
+	private Integer deleted;
 }

+ 8 - 11
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/ArchiveCenterController.java

@@ -76,24 +76,21 @@ public class ArchiveCenterController extends KdController {
 		if (task.getId() != null) {
 			DownloadTask dbTask = downloadTaskMapper.selectById(task.getId());
 			if (dbTask == null) {
-				return R.fail("下载任务不存在,请联系管理员");
+				dbTask = new DownloadTask();
+				dbTask.setStatus(4);
+				return R.data(dbTask);
 			}
-			if(dbTask.getStatus() == 1 && DateUtil.between(dbTask.getCreateTime(),DateUtil.now()).toSeconds() > 300){
+			if ((dbTask.getStatus() == 0 && DateUtil.between(dbTask.getCreateTime(), DateUtil.now()).toSeconds() > 300) || dbTask.getStatus() == 4) {
 				task.setStatus(4);
 				downloadTaskMapper.updateById(task);
-				return R.fail("下载任务超时,3分钟未完成,请联系管理员");
-			}
-			if(dbTask.getStatus() == 4){
-				return R.fail("下载任务已超时,请联系管理员");
-			}
-			if (dbTask.getStatus() == 2 && dbTask.getExpireTime() != null && DateUtil.now().compareTo(dbTask.getExpireTime()) > 0) {
-				// 任务已过期
-				dbTask.setStatus(3);
+//				return R.fail("下载任务超时,3分钟未完成,请联系管理员");
+				return R.data(task);
 			}
 			return R.data(dbTask);
 		} else {
 			task.setYearAndMonth(task.getYearAndMonth());
 			task.setTenantId(SecureUtil.getTenantId());
+			task.setStatus(0);
 			int result = downloadTaskMapper.insertDownloadTask(task);
 			RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
 			if (result == 1) {
@@ -162,7 +159,7 @@ public class ArchiveCenterController extends KdController {
 				}
 
 				outputStream.flush();
-				log.info("文件下载完成: {}, 大小: {} mb", task.getZipUrl(), totalBytes/1024/1024);
+				log.info("文件下载完成: {}, 大小: {} mb", task.getZipUrl(), totalBytes / 1024 / 1024);
 
 			} catch (IOException e) {
 				log.error("文件下载失败: {}", task.getZipUrl(), e);

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

@@ -63,7 +63,7 @@
         (SELECT IFNULL(sum(amount),0) FROM kd_xm_direct_cost xdc WHERE xm_id=xm.id and xdc.year_and_month=#{yearAndMonth} and xdc.type ='2') as fy7,
         (SELECT IFNULL(sum(amount),0) FROM kd_xm_direct_cost xdc WHERE xm_id=xm.id and xdc.year_and_month=#{yearAndMonth} and xdc.type ='3') as fy8
         FROM kd_xm xm
-        where #{yearAndMonth} between DATE_FORMAT(XMKSSJ, '%Y%m') and DATE_FORMAT(COALESCE(get_xm_info(xm.id, 'XMJSSJ', #{yearAndMonth}),XMJSSJ),'%Y%m')
+        where #{yearAndMonth} between DATE_FORMAT(XMKSSJ, '%Y%m') and DATE_FORMAT(COALESCE(get_xm_info(xm.id, 'XMJSSJ', #{yearAndMonth}),XMJSSJ),'%Y%m') and xm.`status` != 0
         <if test="xmmc!=null">and xm.XMMC like concat('%',#{xmmc},'%')</if>
     </select>
 
@@ -83,7 +83,7 @@
         (SELECT IFNULL(sum(amount),0) FROM kd_xm_direct_cost xdc WHERE xm_id=xm.id and left(xdc.year_and_month,4)=#{yearAndMonth} and xdc.type ='2') as fy7,
         (SELECT IFNULL(sum(amount),0) FROM kd_xm_direct_cost xdc WHERE xm_id=xm.id and left(xdc.year_and_month,4)=#{yearAndMonth} and xdc.type ='3') as fy8
         FROM kd_xm xm
-        where #{yearAndMonth} between DATE_FORMAT(XMKSSJ, '%Y') and DATE_FORMAT(COALESCE(get_xm_info(xm.id, 'XMJSSJ', #{yearAndMonth}),XMJSSJ),'%Y')
+        where #{yearAndMonth} between DATE_FORMAT(XMKSSJ, '%Y') and DATE_FORMAT(COALESCE(get_xm_info(xm.id, 'XMJSSJ', #{yearAndMonth}),XMJSSJ),'%Y') and xm.`status` != 0
         <if test="xmmc!=null">and XMMC like concat('%',#{xmmc},'%')</if>
     </select>
 

+ 4 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmTechnicianHoursMapper.java

@@ -66,6 +66,10 @@ public interface XmTechnicianHoursMapper extends BaseMapper<XmTechnicianHours> {
 
 	Long countByUnicodeAndMonth(@Param("unicode") String unicode, @Param("yearAndMonth") String yearAndMonth);
 
+	Double sumByUnicodeAndDay(@Param("unicode") String unicode, @Param("day") String day);
+
+	Double sumByUnicodeAndMonth(@Param("unicode") String unicode, @Param("month") String month);
+
 	/**
 	 * 查询待同步的工时数据
 	 * @param dto

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

@@ -148,6 +148,18 @@
         where unicode = #{unicode} and left(work_date,6) = #{yearAndMonth}
     </select>
 
+    <select id="sumByUnicodeAndDay" resultType="java.lang.Double">
+        select ifnull(sum(work_hours),0)
+        from kd_xm_technician_hours
+        where unicode = #{unicode} and work_date = #{day}
+    </select>
+
+    <select id="sumByUnicodeAndMonth" resultType="java.lang.Double">
+        select ifnull(sum(work_hours),0)
+        from kd_xm_technician_hours
+        where unicode = #{unicode} and left(work_date,6) = #{month}
+    </select>
+
     <select id="selectListForSync" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
             h.tenant_id as tenantId, xm.id as xmId, xm.XMBH as xmbh,h.unicode, h.work_date as workDate , h.work_hours as workHours

+ 5 - 6
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/ArchiveServiceImpl.java

@@ -306,7 +306,7 @@ public class ArchiveServiceImpl implements IArchiveService {
 		if (archiveAttach == null) {
 			archiveAttach = new ArchiveAttachEntity();
 		}
-		Path basePath = Paths.get(archiveDir, SecureUtil.getTenantId(), year, dir);
+		Path basePath = Paths.get(archiveDir, UUID.randomUUID().toString(), SecureUtil.getTenantId(), year, dir);
 		if (FileUtil.exist(basePath.toString())) {
 			FileUtil.del(basePath.toString());
 		}
@@ -518,10 +518,9 @@ public class ArchiveServiceImpl implements IArchiveService {
 
 
 		//设置任务状态为 已完成
-		task.setStatus(2);
-		task.setDoneTime(new Date());
-		task.setExpireTime(DateUtil.plusHours(new Date(), 1));
-		task.setZipUrl(zipPath);
+			task.setStatus(2);
+			task.setDoneTime(new Date());
+ 			task.setZipUrl(zipPath);
 		task.setFileSize(FileUtil.size(FileUtil.file(zipPath)));
 		downloadTaskMapper.updateById(task);
 	}
@@ -1396,7 +1395,7 @@ public class ArchiveServiceImpl implements IArchiveService {
 		for (int i = 1; i <= 12; i++) {
 			String yearAndMonth = year + (i < 10 ? "0" + i : i);
 			XmLeaseEntity param = new XmLeaseEntity();
- 			param.setYearAndMonth(yearAndMonth);
+			param.setYearAndMonth(yearAndMonth);
 			param.setXmId(xmId);
 			List<JSONObject> leaseList = xmLeaseService.yanfazulinzichanfeiyongfenpeibiao(param);
 			if (Func.isEmpty(leaseList)) {

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

@@ -19,10 +19,7 @@ import org.sky.scientific.excel.AttendanceMonthlyDataListener;
 import org.sky.scientific.excel.AttendanceMonthlyExcel;
 import org.sky.scientific.excel.handle.AttendanceMergeStrategy;
 import org.sky.scientific.excel.handle.CustomCellStyleHandler;
-import org.sky.scientific.mapper.AttendanceMapper;
-import org.sky.scientific.mapper.SettingMapper;
-import org.sky.scientific.mapper.TechnicianMapper;
-import org.sky.scientific.mapper.XmTechnicianMapper;
+import org.sky.scientific.mapper.*;
 import org.sky.scientific.pojo.dto.AttendanceDto;
 import org.sky.scientific.pojo.entity.AttendanceEntity;
 import org.sky.scientific.pojo.entity.SettingEntity;
@@ -55,6 +52,7 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 	private final TechnicianMapper technicianMapper;
 	private final SettingMapper settingMapper;
 	private final XmTechnicianMapper xmTechnicianMapper;
+	private final XmTechnicianHoursMapper technicianHoursMapper;
 
 	@Override
 	public IPage<AttendanceVO> selectAttendancePage(AttendanceDto attendance, IPage<AttendanceVO> page) {
@@ -107,6 +105,8 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 			//新增
 			affectNum = baseMapper.insert(attendance);
 		} else {
+			//获取已填报的工时,新的考勤不能小于已填报工时总和
+			this.judgeAttendance(attendance.getUnicode(), attendance.getWorkDate(), attendance.getWorkHours());
 			//修改
 			LambdaQueryWrapper<AttendanceEntity> updateWrapper = Wrappers.<AttendanceEntity>lambdaQuery()
 				.eq(AttendanceEntity::getUnicode, attendance.getUnicode())
@@ -164,6 +164,9 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 				if (dailyAttendance.getWorkHours() > one.getWorkHours()) {
 					throw new ServiceException("出勤时长不能大于出勤时间设置[" + one.getWorkHours() + "]小时");
 				}
+				//获取已填报的工时,新的考勤不能小于已填报工时总和
+				this.judgeAttendance(dailyAttendance.getUnicode(), dailyAttendance.getWorkDate(), dailyAttendance.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();
@@ -202,6 +205,13 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 		}
 	}
 
+	private void judgeAttendance(String unicode, String workDate, double workHours){
+		//获取已填报的工时,新的考勤不能小于已填报工时总和
+		double workHoursByDay = technicianHoursMapper.sumByUnicodeAndDay(unicode, workDate);
+		if(workHours<workHoursByDay){
+			throw new ServiceException("日期【"+workDate+"】填报的出勤时长不能小于已填报的工时【"+workHoursByDay+"】,请联系管理员");
+		}
+	}
 	@Override
 	public void exportAttendance(OutputStream os, List<AttendanceVO> list, String yearAndMonth) {
 		try {
@@ -337,6 +347,10 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 			}
 			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);
+
+			//获取已填报的工时,新的考勤不能小于已填报工时总和
+			this.judgeAttendance(attendance.getUnicode(), dailyAttendance.getWorkDate(), dailyAttendance.getWorkHours());
+
 			AttendanceEntity entity = new AttendanceEntity();
 			if (primaryKey == null) {
 				entity.setUnicode(attendance.getUnicode());
@@ -365,13 +379,19 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 	}
 
 	@Override
+	@Transactional
 	public boolean clearAttendance(List<AttendanceDto> attendanceList) {
 		if (CollectionUtil.isEmpty(attendanceList)) {
 			throw new ServiceException("参数不能为空");
 		}
 		int affectNum = 0;
-		for (AttendanceDto entity : attendanceList) {
-			affectNum += baseMapper.clearUnicodeAndMonthly(entity.getUnicode(), entity.getYearAndMonth());
+		for (AttendanceDto dto : attendanceList) {
+			//获取已填报的工时的不能删除
+			double workHoursByMonth = technicianHoursMapper.sumByUnicodeAndMonth(dto.getUnicode(), dto.getYearAndMonth());
+			if(workHoursByMonth > 0){
+				throw new ServiceException("已填报工时数据,无法清除工时数据,请联系管理员");
+			}
+			affectNum += baseMapper.clearUnicodeAndMonthly(dto.getUnicode(), dto.getYearAndMonth());
 		}
 		return affectNum >= 0;
 	}
@@ -405,8 +425,14 @@ public class AttendanceServiceImpl extends BaseServiceImpl<AttendanceMapper, Att
 	}
 
 	@Override
+	@Transactional
 	public boolean deleteAttendance(List<AttendanceDto> attendanceList) {
 		for (AttendanceDto dto : attendanceList) {
+			//获取已填报的工时的不能删除
+			double workHoursByMonth = technicianHoursMapper.sumByUnicodeAndMonth(dto.getUnicode(), dto.getYearAndMonth());
+			if(workHoursByMonth > 0){
+				throw new ServiceException("已填报工时数据,无法删除,请联系管理员");
+			}
 			baseMapper.deleteByUnicodeAndMonthly(dto.getUnicode(), dto.getYearAndMonth());
 		}
 		return true;

+ 10 - 2
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/XmJtbServiceImpl.java

@@ -29,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.io.FileOutputStream;
 import java.io.OutputStreamWriter;
-import java.util.Date;
 import java.util.Objects;
 
 /**
@@ -94,10 +93,19 @@ public class XmJtbServiceImpl extends BaseServiceImpl<XmJtbMapper, XmJtbEntity>
 			bgrz.setZdmc("STATUS");
 			bgrz.setBghdz(String.valueOf(XmStatusEnum.已结题.getCode()));
 			bgrz.setBgyy("项目结题");
-			bgrz.setBgsxsj(new Date());
+			bgrz.setBgsxsj(xmJtb.getTbsj());
 			bgrz.setTenantId(SecureUtil.getTenantId());
 			xmBgrzMapper.insert(bgrz);
+
+			XmEntity xmEntity = new XmEntity();
+			xmEntity.setId(xmJtb.getXmId());
+			xmEntity.setStatus(XmStatusEnum.已结题.getCode());
+			xmMapper.updateById(xmEntity);
 		} else {
+			XmEntity xmEntity = new XmEntity();
+			xmEntity.setId(xmJtb.getXmId());
+			xmEntity.setStatus(XmStatusEnum.开展中.getCode());
+			xmMapper.updateById(xmEntity);
 			xmBgrzMapper.deleteBgrzByJtb(xmJtb.getXmId());
 		}
 		xmJtb.setId(null);