|
|
@@ -5,7 +5,9 @@ import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
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;
|
|
|
@@ -21,11 +23,9 @@ import org.sky.scientific.excel.XmTechnicianHoursListener;
|
|
|
import org.sky.scientific.excel.handle.CustomCellStyleHandler;
|
|
|
import org.sky.scientific.excel.handle.TechnicianWorkMergeStrategy;
|
|
|
import org.sky.scientific.excel.handle.TechnicianWorkStatisticsMergeStrategy;
|
|
|
-import org.sky.scientific.mapper.AttendanceMapper;
|
|
|
-import org.sky.scientific.mapper.TechnicianMapper;
|
|
|
-import org.sky.scientific.mapper.XmMapper;
|
|
|
-import org.sky.scientific.mapper.XmTechnicianHoursMapper;
|
|
|
+import org.sky.scientific.mapper.*;
|
|
|
import org.sky.scientific.pojo.dto.TechnicianDTO;
|
|
|
+import org.sky.scientific.pojo.entity.XmTechnicianEntity;
|
|
|
import org.sky.scientific.pojo.entity.XmTechnicianHours;
|
|
|
import org.sky.scientific.pojo.vo.DailyAttendance;
|
|
|
import org.sky.scientific.pojo.vo.DailyHours;
|
|
|
@@ -60,6 +60,7 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
private final XmMapper xmMapper;
|
|
|
private final AttendanceMapper attendanceMapper;
|
|
|
private final TechnicianMapper technicianMapper;
|
|
|
+ private final XmTechnicianMapper xmTechnicianMapper;
|
|
|
|
|
|
@SneakyThrows
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -195,13 +196,28 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
if (StringUtil.isBlank(dto.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
+ int year = Integer.parseInt(dto.getYearAndMonth().substring(0, 4));
|
|
|
+ int month = Integer.parseInt(dto.getYearAndMonth().substring(4));
|
|
|
+ LocalDate startDate = LocalDate.of(year, month, 1);
|
|
|
+ int daysInMonth = startDate.lengthOfMonth();
|
|
|
+
|
|
|
List<XmTechnicianHoursVO> list = baseMapper.selectHoursPage(page, dto);
|
|
|
for (XmTechnicianHoursVO temp : list) {
|
|
|
- List<DailyAttendance> dailyAttendanceList = baseMapper.selectByXmIdAndUnicode(temp.getXmId(), temp.getUnicode(), dto.getYearAndMonth());
|
|
|
- if (CollectionUtil.isEmpty(dailyAttendanceList)) {
|
|
|
- continue;
|
|
|
+
|
|
|
+ List<DailyAttendance> dailyHoursList = baseMapper.selectByXmIdAndUnicode(temp.getXmId(), temp.getUnicode(), dto.getYearAndMonth());
|
|
|
+ for (int i = 0; i < daysInMonth; i++) {
|
|
|
+ String everyDay = startDate.plusDays(i).format(DateTimeFormatter.ofPattern(DateUtil.PATTERN_YYYYMMDD));
|
|
|
+ //过滤某天的工时数据
|
|
|
+ Optional<DailyAttendance> any = dailyHoursList.stream().filter(daily -> Func.equals(daily.getWorkDate(), everyDay)).findAny();
|
|
|
+ DailyAttendance daily = null;
|
|
|
+ if (any.isEmpty()) {
|
|
|
+ daily = new DailyAttendance();
|
|
|
+ daily.setWorkDate(everyDay);
|
|
|
+ daily.setWorkHours(0.0);
|
|
|
+ dailyHoursList.add(i, daily);
|
|
|
+ }
|
|
|
}
|
|
|
- temp.setDailyAttendances(dailyAttendanceList);
|
|
|
+ temp.setDailyAttendances(dailyHoursList);
|
|
|
}
|
|
|
return page.setRecords(list);
|
|
|
}
|
|
|
@@ -283,14 +299,27 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean clear(JSONObject dto) {
|
|
|
+ public boolean clearHours(JSONObject dto) {
|
|
|
JSONArray xmAndUnicodeList = dto.getJSONArray("xmAndUnicodeList");
|
|
|
if (xmAndUnicodeList == null || xmAndUnicodeList.isEmpty()) {
|
|
|
throw new ServiceException("参数xmAndUnicodeList不能为空");
|
|
|
}
|
|
|
for (Object xmAndUnicode : xmAndUnicodeList) {
|
|
|
Map<String, String> map = (HashMap<String, String>) xmAndUnicode;
|
|
|
- baseMapper.clear(dto.getString("yearAndMonth"), Long.valueOf(map.get("xmId")), map.get("unicode"));
|
|
|
+ baseMapper.clearByXmUnicodeMonth(dto.getString("yearAndMonth"), Long.valueOf(map.get("xmId")), map.get("unicode"));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteHours(JSONObject dto) {
|
|
|
+ JSONArray xmAndUnicodeList = dto.getJSONArray("xmAndUnicodeList");
|
|
|
+ if (xmAndUnicodeList == null || xmAndUnicodeList.isEmpty()) {
|
|
|
+ throw new ServiceException("参数xmAndUnicodeList不能为空");
|
|
|
+ }
|
|
|
+ for (Object xmAndUnicode : xmAndUnicodeList) {
|
|
|
+ Map<String, String> map = (HashMap<String, String>) xmAndUnicode;
|
|
|
+ baseMapper.deleteByXmUnicodeMonth(dto.getString("yearAndMonth"), Long.valueOf(map.get("xmId")), map.get("unicode"));
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -425,8 +454,8 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
}
|
|
|
List<TechnicianHoursMonthlyVO> list = baseMapper.meiyueyanfagongshifenpeibiao(page, dto);
|
|
|
|
|
|
- Integer year = Integer.valueOf(dto.getYearAndMonth().substring(0, 4));
|
|
|
- Integer month = Integer.valueOf(dto.getYearAndMonth().substring(4));
|
|
|
+ int year = Integer.parseInt(dto.getYearAndMonth().substring(0, 4));
|
|
|
+ int month = Integer.parseInt(dto.getYearAndMonth().substring(4));
|
|
|
LocalDate startDate = LocalDate.of(year, month, 1);
|
|
|
int daysInMonth = startDate.lengthOfMonth();
|
|
|
|
|
|
@@ -524,4 +553,39 @@ public class XmTechnicianHoursServiceImpl extends BaseServiceImpl<XmTechnicianHo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean fetch(String yearAndMonth) {
|
|
|
+ List<XmTechnicianEntity> list = xmTechnicianMapper.selectList(Wrappers.<XmTechnicianEntity>lambdaQuery().eq(XmTechnicianEntity::getYearAndMonth, yearAndMonth));
|
|
|
+
|
|
|
+ if (Func.isEmpty(list)) {
|
|
|
+ throw new ServiceException("本月没有参研人员");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<XmTechnicianHours> insertList = new ArrayList<>();
|
|
|
+ for (XmTechnicianEntity xmTechnician : list) {
|
|
|
+ XmTechnicianHours hours = new XmTechnicianHours();
|
|
|
+ hours.setXmId(xmTechnician.getXmId());
|
|
|
+ hours.setUnicode(xmTechnician.getUnicode());
|
|
|
+ hours.setWorkDate(yearAndMonth + "01");
|
|
|
+ hours.setWorkHours(0.0);
|
|
|
+ hours.setTenantId(SecureUtil.getTenantId());
|
|
|
+ insertList.add(hours);
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<XmTechnicianHours> queryWrapper = Wrappers.<XmTechnicianHours>lambdaQuery().apply("left(work_date, 6) = {0}", yearAndMonth);
|
|
|
+ List<XmTechnicianHours> hoursList = baseMapper.selectList(queryWrapper);
|
|
|
+ Map<Long, List<String>> collect = hoursList.stream().collect(Collectors.groupingBy(XmTechnicianHours::getXmId, Collectors.mapping(XmTechnicianHours::getUnicode, Collectors.toList())));
|
|
|
+ if (collect.isEmpty()) {
|
|
|
+ return this.saveBatch(insertList);
|
|
|
+ } else {
|
|
|
+// collect.get()
|
|
|
+ List<XmTechnicianHours> deduplicationList = insertList.stream().filter(item -> !(collect.containsKey(item.getXmId()) && collect.get(item.getXmId()).contains(item.getUnicode()))).toList();
|
|
|
+ if (Func.isEmpty(deduplicationList)) {
|
|
|
+ throw new ServiceException("本月参研人员已全部引用");
|
|
|
+ }
|
|
|
+ return this.saveBatch(deduplicationList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|