|
@@ -1,4 +1,13 @@
|
|
|
package org.dromara.business.service.impl;
|
|
package org.dromara.business.service.impl;
|
|
|
|
|
+import cn.idev.excel.EasyExcel;
|
|
|
|
|
+import cn.idev.excel.context.AnalysisContext;
|
|
|
|
|
+import cn.idev.excel.event.AnalysisEventListener;
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
+import org.dromara.business.domain.bo.BlindLevelsBo;
|
|
|
|
|
+import org.dromara.business.domain.vo.BlindLevelsImportVo;
|
|
|
|
|
+import org.dromara.business.service.IBlindLevelsService;
|
|
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
|
|
+import org.dromara.common.core.service.UserService;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
@@ -8,13 +17,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.dromara.business.domain.bo.BlindStructuresBo;
|
|
import org.dromara.business.domain.bo.BlindStructuresBo;
|
|
|
import org.dromara.business.domain.vo.BlindStructuresVo;
|
|
import org.dromara.business.domain.vo.BlindStructuresVo;
|
|
|
import org.dromara.business.domain.BlindStructures;
|
|
import org.dromara.business.domain.BlindStructures;
|
|
|
import org.dromara.business.mapper.BlindStructuresMapper;
|
|
import org.dromara.business.mapper.BlindStructuresMapper;
|
|
|
import org.dromara.business.service.IBlindStructuresService;
|
|
import org.dromara.business.service.IBlindStructuresService;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
@@ -32,6 +46,9 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
|
|
|
|
|
private final BlindStructuresMapper baseMapper;
|
|
private final BlindStructuresMapper baseMapper;
|
|
|
|
|
|
|
|
|
|
+ private final IBlindLevelsService blindLevelsService;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserService userService;
|
|
|
/**
|
|
/**
|
|
|
* 查询【请填写功能名称】
|
|
* 查询【请填写功能名称】
|
|
|
*
|
|
*
|
|
@@ -54,6 +71,17 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
public TableDataInfo<BlindStructuresVo> queryPageList(BlindStructuresBo bo, PageQuery pageQuery) {
|
|
public TableDataInfo<BlindStructuresVo> queryPageList(BlindStructuresBo bo, PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<BlindStructures> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<BlindStructures> lqw = buildQueryWrapper(bo);
|
|
|
Page<BlindStructuresVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
Page<BlindStructuresVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
|
|
+ List<BlindStructuresVo> resultRecords = result.getRecords();
|
|
|
|
|
+ for (BlindStructuresVo record : resultRecords) {
|
|
|
|
|
+ BlindLevelsBo blindLevelsBo=new BlindLevelsBo();
|
|
|
|
|
+ record.setBlindLevels(blindLevelsService.queryList(blindLevelsBo));
|
|
|
|
|
+ if(record.getCreateUserId()!=null){
|
|
|
|
|
+ String createName = userService.selectUserNameById(record.getCreateUserId());
|
|
|
|
|
+ record.setCreateName(createName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return TableDataInfo.build(result);
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,16 +115,77 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
* @return 是否新增成功
|
|
* @return 是否新增成功
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public Boolean insertByBo(BlindStructuresBo bo) {
|
|
|
|
|
- BlindStructures add = MapstructUtils.convert(bo, BlindStructures.class);
|
|
|
|
|
- validEntityBeforeSave(add);
|
|
|
|
|
- boolean flag = baseMapper.insertBlindStructures(add) > 0;
|
|
|
|
|
- if (flag) {
|
|
|
|
|
- bo.setId(add.getId());
|
|
|
|
|
|
|
+ public R<Boolean> insertByBo(BlindStructuresBo bo, MultipartFile file) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 转换 BO -> PO
|
|
|
|
|
+ BlindStructures add = MapstructUtils.convert(bo, BlindStructures.class);
|
|
|
|
|
+ validEntityBeforeSave(add);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析 Excel 文件
|
|
|
|
|
+ List<BlindLevelsImportVo> dataList;
|
|
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
|
|
+ dataList = parseExcel(inputStream);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("读取文件失败", e);
|
|
|
|
|
+ return R.fail("读取文件失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(dataList)) {
|
|
|
|
|
+ return R.fail("导入数据为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 校验数据逻辑(可选)
|
|
|
|
|
+ /* if (!validateData(dataList)) {
|
|
|
|
|
+ return R.fail("导入数据校验失败,请检查等级顺序或数值是否正确");
|
|
|
|
|
+ }*/
|
|
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
|
|
+ add.setCreateUserId(userId);
|
|
|
|
|
+ // 4. 插入主表
|
|
|
|
|
+ boolean flag = baseMapper.insertBlindStructures(add) > 0;
|
|
|
|
|
+ if (!flag) {
|
|
|
|
|
+ return R.fail("插入主表失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bo.setId(add.getId()); // 同步 ID
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 插入子表数据
|
|
|
|
|
+ for (BlindLevelsImportVo vo : dataList) {
|
|
|
|
|
+ BlindLevelsBo levelBo = new BlindLevelsBo();
|
|
|
|
|
+ levelBo.setBlindStructureId(add.getId());
|
|
|
|
|
+ levelBo.setLevelNumber(vo.getLevelNumber());
|
|
|
|
|
+ levelBo.setSmallBlind(vo.getSmallBlind());
|
|
|
|
|
+ levelBo.setBigBlind(vo.getBigBlind());
|
|
|
|
|
+ levelBo.setAnte(vo.getAnte());
|
|
|
|
|
+ levelBo.setDurationMinutes(vo.getDurationMinutes());
|
|
|
|
|
+ levelBo.setCreateUserId(userId);
|
|
|
|
|
+ blindLevelsService.insertByBo(levelBo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok(true); // 成功返回
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("插入盲注结构失败", e);
|
|
|
|
|
+ throw e; // 抛出异常以触发事务回滚
|
|
|
}
|
|
}
|
|
|
- return flag;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 解析 Excel 方法
|
|
|
|
|
+ private List<BlindLevelsImportVo> parseExcel(InputStream inputStream) {
|
|
|
|
|
+ List<BlindLevelsImportVo> list = new ArrayList<>();
|
|
|
|
|
+ EasyExcel.read(inputStream, BlindLevelsImportVo.class, new AnalysisEventListener<BlindLevelsImportVo>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void invoke(BlindLevelsImportVo data, AnalysisContext context) {
|
|
|
|
|
+ list.add(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
|
|
+ // 解析完成
|
|
|
|
|
+ }
|
|
|
|
|
+ }).sheet().doRead();
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 修改【请填写功能名称】
|
|
* 修改【请填写功能名称】
|
|
|
*
|
|
*
|
|
@@ -104,10 +193,58 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
* @return 是否修改成功
|
|
* @return 是否修改成功
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public Boolean updateByBo(BlindStructuresBo bo) {
|
|
|
|
|
- BlindStructures update = MapstructUtils.convert(bo, BlindStructures.class);
|
|
|
|
|
- validEntityBeforeSave(update);
|
|
|
|
|
- return baseMapper.updateBlindStructuresById(update) > 0;
|
|
|
|
|
|
|
+ //@Transactional(rollbackFor = Exception.class) // 开启事务
|
|
|
|
|
+ public R<Boolean> updateByBo(BlindStructuresBo bo, MultipartFile file) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 转换 BO -> PO
|
|
|
|
|
+ BlindStructures update = MapstructUtils.convert(bo, BlindStructures.class);
|
|
|
|
|
+ validEntityBeforeSave(update);
|
|
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
|
|
+ update.setUpdateUserId(userId);
|
|
|
|
|
+ // 2. 更新主表
|
|
|
|
|
+ int i = baseMapper.updateBlindStructuresById(update);
|
|
|
|
|
+ if (i <= 0) {
|
|
|
|
|
+ return R.fail("更新失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 删除原有等级数据
|
|
|
|
|
+ Boolean b = blindLevelsService.deleteBlindLevelByBlindStructureId(update.getId());
|
|
|
|
|
+ if (!b) {
|
|
|
|
|
+ return R.fail("删除历史等级失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 解析 Excel 文件
|
|
|
|
|
+ List<BlindLevelsImportVo> dataList;
|
|
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
|
|
+ dataList = parseExcel(inputStream);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("读取文件失败", e);
|
|
|
|
|
+ return R.fail("读取文件失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(dataList)) {
|
|
|
|
|
+ return R.fail("导入数据为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 插入新等级数据
|
|
|
|
|
+ for (BlindLevelsImportVo vo : dataList) {
|
|
|
|
|
+ BlindLevelsBo levelBo = new BlindLevelsBo();
|
|
|
|
|
+ levelBo.setBlindStructureId(update.getId());
|
|
|
|
|
+ levelBo.setLevelNumber(vo.getLevelNumber());
|
|
|
|
|
+ levelBo.setSmallBlind(vo.getSmallBlind());
|
|
|
|
|
+ levelBo.setBigBlind(vo.getBigBlind());
|
|
|
|
|
+ levelBo.setAnte(vo.getAnte());
|
|
|
|
|
+ levelBo.setDurationMinutes(vo.getDurationMinutes());
|
|
|
|
|
+ levelBo.setCreateUserId(userId);
|
|
|
|
|
+ blindLevelsService.insertByBo(levelBo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok(true); // 成功返回 true
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("更新盲注结构失败", e);
|
|
|
|
|
+ throw e; // 抛出异常触发事务回滚
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -131,4 +268,49 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
|
|
|
}
|
|
}
|
|
|
return baseMapper.deleteBlindStructuresByIds(ids) > 0;
|
|
return baseMapper.deleteBlindStructuresByIds(ids) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static boolean validateData(List<BlindLevelsImportVo> dataList) {
|
|
|
|
|
+ if (dataList == null || dataList.isEmpty()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return validateDataRecursively(dataList, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean validateDataRecursively(List<BlindLevelsImportVo> dataList, int currentIndex) {
|
|
|
|
|
+ if (currentIndex >= dataList.size() - 1) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BlindLevelsImportVo current = dataList.get(currentIndex);
|
|
|
|
|
+ BlindLevelsImportVo next = dataList.get(currentIndex + 1);
|
|
|
|
|
+
|
|
|
|
|
+ // Check if levels are continuous
|
|
|
|
|
+ if (current.getLevelNumber() + 1 != next.getLevelNumber()) {
|
|
|
|
|
+ System.out.println("Error: Levels are not continuous at index " + currentIndex);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check if values are increasing
|
|
|
|
|
+ if (current.getSmallBlind() >= next.getSmallBlind() ||
|
|
|
|
|
+ current.getBigBlind() >= next.getBigBlind() ||
|
|
|
|
|
+ current.getAnte() >= next.getAnte()) {
|
|
|
|
|
+ System.out.println("Error: Values are not increasing at index " + currentIndex);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check if upgrade time is positive
|
|
|
|
|
+ if (next.getDurationMinutes() <= 0){
|
|
|
|
|
+ System.out.println("Error: Upgrade time is not positive at index " + (currentIndex + 1));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return validateDataRecursively(dataList, currentIndex + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|