|
|
@@ -1,41 +1,33 @@
|
|
|
|
|
|
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;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import jakarta.annotation.Resource;
|
|
|
-import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.sky.core.excel.util.ExcelUtil;
|
|
|
import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.mp.base.BaseServiceImpl;
|
|
|
-import org.sky.core.secure.utils.SecureUtil;
|
|
|
-import org.sky.core.tool.utils.*;
|
|
|
+import org.sky.core.tool.utils.BeanUtil;
|
|
|
+import org.sky.core.tool.utils.CollectionUtil;
|
|
|
+import org.sky.core.tool.utils.DateUtil;
|
|
|
+import org.sky.core.tool.utils.StringUtil;
|
|
|
import org.sky.scientific.excel.AssetExcel;
|
|
|
-import org.sky.scientific.excel.XmAssetHoursMonthlyDataListener;
|
|
|
-import org.sky.scientific.excel.XmAssetHoursMonthlyExcel;
|
|
|
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;
|
|
|
-import org.sky.scientific.pojo.vo.DailyAttendance;
|
|
|
-import org.sky.scientific.pojo.vo.XmAssetHoursVO;
|
|
|
import org.sky.scientific.service.IAssetService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.BufferedInputStream;
|
|
|
-import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 资产表 服务实现类
|
|
|
@@ -135,167 +127,4 @@ public class AssetServiceImpl extends BaseServiceImpl<AssetMapper, AssetEntity>
|
|
|
//});
|
|
|
return assetList;
|
|
|
}
|
|
|
-
|
|
|
- @SneakyThrows
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- @Override
|
|
|
- public void importXmAssetHours(MultipartFile file, String yearAndMonth) {
|
|
|
- XmAssetHoursMonthlyDataListener listener = new XmAssetHoursMonthlyDataListener();
|
|
|
- listener.setYearAndMonth(yearAndMonth);
|
|
|
- EasyExcel.read(new BufferedInputStream(file.getInputStream()))
|
|
|
- .registerReadListener(listener)
|
|
|
- .sheet(0)
|
|
|
- .headRowNumber(3) // 重要:设置表头行数(0-based)
|
|
|
- .doRead();
|
|
|
- List<XmAssetHoursMonthlyExcel> records = listener.getRecords();
|
|
|
- if (CollectionUtil.isEmpty(records)) {
|
|
|
- throw new ServiceException("未能从模板中读取数据,请检查模板格式是否正确");
|
|
|
- }
|
|
|
-
|
|
|
- //需要新增的,以便后续批量新增
|
|
|
- List<XmAssetHoursEntity> insertList = new ArrayList<>();
|
|
|
- //需要更新的,以便后续批量修改
|
|
|
- List<XmAssetHoursEntity> updateList = new ArrayList<>();
|
|
|
-
|
|
|
- int batchCount = 20;
|
|
|
-
|
|
|
- List<XmAssetHoursEntity> dbList = xmAssetHoursMapper.selectByYearAndMonth(yearAndMonth, null, null);
|
|
|
- for (XmAssetHoursMonthlyExcel record : records) {
|
|
|
- //保存
|
|
|
- if(StringUtil.isAllBlank(record.getXmmc(), record.getXmbh())){
|
|
|
- throw new ServiceException("研发项目编号、研发项目名称都为空,请检查数据");
|
|
|
- }
|
|
|
- Long xmId = xmMapper.getXmIdByXmmcOrXmbh(yearAndMonth, record.getXmmc(), record.getXmbh());
|
|
|
- if (xmId == null) {
|
|
|
- throw new ServiceException("序号为[" + record.getSerialNumber() + "]的研发项目编号和研发项目名称都不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if(StringUtil.isBlank(record.getZcbm())){
|
|
|
- throw new ServiceException("序号为[" + record.getSerialNumber() + "]的资产编码为空");
|
|
|
- }
|
|
|
- AssetEntity dbAsset = baseMapper.selectOne(Wrappers.<AssetEntity>lambdaQuery().eq(AssetEntity::getZcbm, record.getZcbm()).eq(AssetEntity::getYearAndMonth, yearAndMonth));
|
|
|
- if (dbAsset == null) {
|
|
|
- throw new ServiceException("序号为[" + record.getSerialNumber() + "]的资产不存在");
|
|
|
- }
|
|
|
- List<XmAssetHoursEntity> byXmAndAssetList = dbList.stream().filter(e -> e.getXmId().equals(xmId) && e.getAssetId().equals(dbAsset.getId())).toList();
|
|
|
- for (DailyAttendance dailyAttendance : record.getDailyAttendances()) {
|
|
|
-
|
|
|
- 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();
|
|
|
- if (primaryKey == null) {
|
|
|
- entity.setXmId(xmId);
|
|
|
- entity.setAssetId(dbAsset.getId());
|
|
|
- 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() && insertList.size() % batchCount == 0) {
|
|
|
- int insertCount = xmAssetHoursMapper.batchInsert(insertList);
|
|
|
- if (insertCount == batchCount) {
|
|
|
- insertList.clear();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (!updateList.isEmpty() && updateList.size() % batchCount == 0) {
|
|
|
- int updateCount = xmAssetHoursMapper.batchUpdate(updateList);
|
|
|
- if (updateCount == batchCount) {
|
|
|
- updateList.clear();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!insertList.isEmpty()) {
|
|
|
- xmAssetHoursMapper.batchInsert(insertList);
|
|
|
- }
|
|
|
- if (!updateList.isEmpty()) {
|
|
|
- xmAssetHoursMapper.batchUpdate(updateList);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public IPage<XmAssetHoursVO> selectXmAssetHoursPage(XmAssetHoursDto dto, IPage<XmAssetHoursVO> page) {
|
|
|
- if (StringUtil.isBlank(dto.getYearAndMonth())) {
|
|
|
- throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
}
|