|
|
@@ -2,6 +2,8 @@
|
|
|
package org.sky.scientific.service.impl;
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -21,6 +23,7 @@ import org.sky.scientific.mapper.AssetMapper;
|
|
|
import org.sky.scientific.mapper.XmAssetHoursMapper;
|
|
|
import org.sky.scientific.mapper.XmMapper;
|
|
|
import org.sky.scientific.pojo.dto.AssetDTO;
|
|
|
+import org.sky.scientific.pojo.dto.XmAssetHoursDto;
|
|
|
import org.sky.scientific.pojo.entity.AssetEntity;
|
|
|
import org.sky.scientific.pojo.entity.XmAssetHoursEntity;
|
|
|
import org.sky.scientific.pojo.vo.AssetVO;
|
|
|
@@ -32,9 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 资产表 服务实现类
|
|
|
@@ -158,7 +159,7 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
|
|
|
int batchCount = 20;
|
|
|
|
|
|
- List<XmAssetHoursEntity> dbList = xmAssetHoursMapper.selectByYearAndMonth(yearAndMonth);
|
|
|
+ List<XmAssetHoursEntity> dbList = xmAssetHoursMapper.selectByYearAndMonth(yearAndMonth, null, null);
|
|
|
for (XmAssetHoursMonthlyExcel record : records) {
|
|
|
//保存
|
|
|
if(StringUtil.isAllBlank(record.getXmmc(), record.getXmbh())){
|
|
|
@@ -220,19 +221,81 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<XmAssetHoursVO> selectXmAssetHoursPage(XmAssetHoursVO vo, IPage<XmAssetHoursVO> page) {
|
|
|
- if (StringUtil.isBlank(vo.getYearAndMonth())) {
|
|
|
+ public IPage<XmAssetHoursVO> selectXmAssetHoursPage(XmAssetHoursDto dto, IPage<XmAssetHoursVO> page) {
|
|
|
+ if (StringUtil.isBlank(dto.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
- List<XmAssetHoursVO> list = xmAssetHoursMapper.selectXmAssetHoursPage(page, vo);
|
|
|
-// for (XmAssetHoursVO temp : list) {
|
|
|
-// List<DailyAttendance> dailyAttendanceList = xmAssetHoursMapper.selectHoursByXmIdAndAssetId(temp.getXmId(), temp.getAssetId(), vo.getYearAndMonth());
|
|
|
-// if(CollectionUtil.isEmpty(dailyAttendanceList)){
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// temp.setMonthlyHours(dailyAttendanceList.stream().mapToDouble(DailyAttendance::getWorkHours).sum());
|
|
|
-// temp.setDailyAttendances(dailyAttendanceList);
|
|
|
-// }
|
|
|
+ List<XmAssetHoursVO> list = xmAssetHoursMapper.selectXmAssetHoursPage(page, dto);
|
|
|
+ for (XmAssetHoursVO temp : list) {
|
|
|
+ List<DailyAttendance> dailyAttendanceList = xmAssetHoursMapper.selectHoursByXmIdAndAssetId(temp.getXmId(), temp.getAssetId(), dto.getYearAndMonth());
|
|
|
+ if(CollectionUtil.isEmpty(dailyAttendanceList)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ temp.setDailyAttendances(dailyAttendanceList);
|
|
|
+ }
|
|
|
return page.setRecords(list);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean batchSubmitXmAssetHours(XmAssetHoursDto dto) {
|
|
|
+ if (StringUtil.isBlank(dto.getYearAndMonth())) {
|
|
|
+ throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
+ }
|
|
|
+ if(dto.getXmId()==null){
|
|
|
+ throw new ServiceException("参数xmId不能为空");
|
|
|
+ }
|
|
|
+ if(dto.getAssetId()==null){
|
|
|
+ throw new ServiceException("参数assetId不能为空");
|
|
|
+ }
|
|
|
+ List<XmAssetHoursEntity> dbList = xmAssetHoursMapper.selectByYearAndMonth(dto.getYearAndMonth(), dto.getXmId(), dto.getAssetId());
|
|
|
+
|
|
|
+ //需要新增的,以便后续批量新增
|
|
|
+ List<XmAssetHoursEntity> insertList = new ArrayList<>();
|
|
|
+ //需要更新的,以便后续批量修改
|
|
|
+ List<XmAssetHoursEntity> updateList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (DailyAttendance dailyAttendance : dto.getDailyHoursList()) {
|
|
|
+
|
|
|
+ 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();
|
|
|
+ if (primaryKey == null) {
|
|
|
+ entity.setXmId(dto.getXmId());
|
|
|
+ entity.setAssetId(dto.getAssetId());
|
|
|
+ entity.setWorkDate(dailyAttendance.getWorkDate());
|
|
|
+ entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ entity.setTenantId(SecureUtil.getTenantId());
|
|
|
+ entity.setCreateUser(SecureUtil.getUserId());
|
|
|
+ entity.setCreateDept(Func.toLong(SecureUtil.getDeptId()));
|
|
|
+ insertList.add(entity);
|
|
|
+ } else {
|
|
|
+ entity.setId(primaryKey);
|
|
|
+ entity.setWorkHours(dailyAttendance.getWorkHours());
|
|
|
+ updateList.add(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!insertList.isEmpty()) {
|
|
|
+ xmAssetHoursMapper.batchInsert(insertList);
|
|
|
+ insertList.clear();
|
|
|
+ }
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ xmAssetHoursMapper.batchUpdate(updateList);
|
|
|
+ updateList.clear();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean clearXmAssetHours(JSONObject dto) {
|
|
|
+ JSONArray xmAndAssetIdList = dto.getJSONArray("xmAndAssetIdList");
|
|
|
+ if (xmAndAssetIdList == null || xmAndAssetIdList.isEmpty()) {
|
|
|
+ throw new ServiceException("参数xmAndAssetIdList不能为空");
|
|
|
+ }
|
|
|
+ for (Object xmAndAssetId : xmAndAssetIdList) {
|
|
|
+ Map<String, Long> map =(HashMap<String,Long>) xmAndAssetId;
|
|
|
+ xmAssetHoursMapper.clearXmAssetHours(dto.getString("yearAndMonth"),(Long) map.get("xmId"), (Long)map.get("assetId"));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|