fix: 异常加上状态码

pull/4/head
tangqian 2023-05-30 17:01:17 +08:00
parent 26c44490cb
commit e1920cc1ee
5 changed files with 69 additions and 92 deletions

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.shop.controller.admin.recharge.vo; package cn.iocoder.yudao.module.shop.controller.admin.recharge.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Schema(description = "管理后台 - 订单 Response VO") @Schema(description = "管理后台 - 订单 Response VO")
@ -16,7 +19,9 @@ public class RechargeOrderRespVO extends RechargeOrderBaseVO {
@Schema(description = "创建时间") @Schema(description = "创建时间")
private LocalDateTime createTime; private LocalDateTime createTime;
@Schema(description = "创建时间") @Schema(description = "创建时间")
private String stringCreateTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime stringCreateTime;
@Schema(description = "档次") @Schema(description = "档次")
private String grade; private String grade;
@Schema(description = "组织名称") @Schema(description = "组织名称")

View File

@ -161,8 +161,7 @@ public class RechargeOrderServiceImpl implements RechargeOrderService {
} }
} }
orderDO.setGrade(grade.toString()); orderDO.setGrade(grade.toString());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); orderDO.setStringCreateTime(orderDO.getCreateTime());
orderDO.setStringCreateTime(orderDO.getCreateTime().format(formatter));
} }
return rechargeOrderRespVOS; return rechargeOrderRespVOS;
@ -191,8 +190,7 @@ public class RechargeOrderServiceImpl implements RechargeOrderService {
} }
} }
orderDO.setGrade(grade.toString()); orderDO.setGrade(grade.toString());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); orderDO.setStringCreateTime(orderDO.getCreateTime());
orderDO.setStringCreateTime(orderDO.getCreateTime().format(formatter));
} }
return new PageResult<>(page.getRecords(), page.getTotal()); return new PageResult<>(page.getRecords(), page.getTotal());
@ -277,8 +275,7 @@ public class RechargeOrderServiceImpl implements RechargeOrderService {
} }
} }
orderDO.setGrade(grade.toString()); orderDO.setGrade(grade.toString());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); orderDO.setStringCreateTime(orderDO.getCreateTime());
orderDO.setStringCreateTime(orderDO.getCreateTime().format(formatter));
} }
return rechargeOrderRespVOS; return rechargeOrderRespVOS;

View File

@ -88,7 +88,7 @@ public class DeptController {
@Operation(summary = "批量组织架构导入") @Operation(summary = "批量组织架构导入")
@PostMapping(value = "/batch/import", name = "批量组织架构导入") @PostMapping(value = "/batch/import", name = "批量组织架构导入")
public CommonResult<Boolean> batchImport(@RequestParam("file") MultipartFile file) throws IOException { public CommonResult<Boolean> batchImport(@RequestParam("file") MultipartFile file){
deptService.batchImport(file); deptService.batchImport(file);
return success(true); return success(true);
} }

View File

@ -117,5 +117,5 @@ public interface DeptService {
*/ */
void validateDeptList(Collection<Long> ids); void validateDeptList(Collection<Long> ids);
void batchImport(MultipartFile file) throws IOException; void batchImport(MultipartFile file);
} }

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.BatchImportVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.BatchImportVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
@ -19,7 +18,6 @@ import cn.iocoder.yudao.module.system.util.TransactionalService;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -28,9 +26,8 @@ import com.google.common.collect.Multimap;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -325,36 +322,16 @@ public class DeptServiceImpl implements DeptService {
private static List<DeptDO> deptDOS4 = new ArrayList<>(); private static List<DeptDO> deptDOS4 = new ArrayList<>();
@Override @Override
public void batchImport(MultipartFile file) throws IOException { public void batchImport(MultipartFile file){
List<BatchImportVO> list = ExcelUtils.read(file, BatchImportVO.class);
try { try {
EasyExcel.read(file.getInputStream(), BatchImportVO.class, new AnalysisEventListener<BatchImportVO>() { List<BatchImportVO> deptList = ExcelUtils.read(file, BatchImportVO.class);
private final List<BatchImportVO> deptList = new ArrayList<>(10000);
@Override
public void invoke(BatchImportVO o, AnalysisContext analysisContext) {
deptList.add(o);
if (deptList.size() % 15 == 0) {
batchInsert();
deptList.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
if (CollectionUtils.isNotEmpty(deptList)) {
batchInsert();
}
}
private void batchInsert() {
Map<String, List<BatchImportVO>> collect = deptList.stream().collect(Collectors.groupingBy(BatchImportVO::getHierarchy)); Map<String, List<BatchImportVO>> collect = deptList.stream().collect(Collectors.groupingBy(BatchImportVO::getHierarchy));
List<BatchImportVO> batchImportVOS1 = collect.get("1"); List<BatchImportVO> batchImportVOS1 = collect.get("1");
List<BatchImportVO> batchImportVOS2 = collect.get("2"); List<BatchImportVO> batchImportVOS2 = collect.get("2");
List<BatchImportVO> batchImportVOS3 = collect.get("3"); List<BatchImportVO> batchImportVOS3 = collect.get("3");
List<BatchImportVO> batchImportVOS4 = collect.get("4"); List<BatchImportVO> batchImportVOS4 = collect.get("4");
transactionalService.run(() -> {
// 装入层级1 // 装入层级1
BatchImportVO batchImportVO1 = batchImportVOS1.get(0); BatchImportVO batchImportVO1 = batchImportVOS1.get(0);
DeptDO deptDO1 = new DeptDO(); DeptDO deptDO1 = new DeptDO();
@ -364,48 +341,46 @@ public class DeptServiceImpl implements DeptService {
deptDO1.setCharacteristic(batchImportVO1.getCharacteristic()); deptDO1.setCharacteristic(batchImportVO1.getCharacteristic());
deptMapper.insert(deptDO1); deptMapper.insert(deptDO1);
deptDO1.setParentOrganizationIds(deptDO1.getId().toString()); deptDO1.setParentOrganizationIds(deptDO1.getId().toString());
deptMapper.updateById(deptDO1); deptMapper.update(deptDO1,Wrappers.<DeptDO>lambdaUpdate().eq(DeptDO::getId,deptDO1.getId()));
// 装入层级2 // 装入层级2
for (BatchImportVO batchImportVO : batchImportVOS2) { for (BatchImportVO batchImportVO : batchImportVOS2) {
DeptDO deptDO2 = new DeptDO(); DeptDO deptDO2 = new DeptDO();
deptDO2.setName(batchImportVO.getDepName()); deptDO2.setName(batchImportVO.getDepName());
deptDO2.setParentId(deptDO1.getId()); deptDO2.setParentId(deptDO1.getId());
deptDO2.setParentOrganizationName(deptDO1.getName() + "," + batchImportVO.getDepName()); deptDO2.setParentOrganizationName(deptDO1.getParentOrganizationName() + "," + batchImportVO.getDepName());
deptDO2.setCharacteristic(batchImportVO.getCharacteristic()); deptDO2.setCharacteristic(batchImportVO.getCharacteristic());
deptMapper.insert(deptDO2); deptMapper.insert(deptDO2);
deptDO2.setParentOrganizationIds(deptDO1.getId() + "," + deptDO2.getId()); deptDO2.setParentOrganizationIds(deptDO1.getParentOrganizationIds() + "," + deptDO2.getId());
deptMapper.updateById(deptDO2); deptMapper.update(deptDO2,Wrappers.<DeptDO>lambdaUpdate().eq(DeptDO::getId,deptDO2.getId()));
deptDOS2.add(deptDO2); deptDOS2.add(deptDO2);
} }
// 装入层级3 // 装入层级3
for (BatchImportVO batchImportVO : batchImportVOS3) { for (BatchImportVO batchImportVO : batchImportVOS3) {
DeptDO deptDO3 = new DeptDO(); DeptDO deptDO3 = new DeptDO();
deptDO3.setName(batchImportVO.getDepName()); deptDO3.setName(batchImportVO.getDepName());
List<DeptDO> collect1 = deptDOS2.stream().filter(e -> e.getCharacteristic().equals(batchImportVO.getCharacteristic())).collect(Collectors.toList()); List<DeptDO> collect1 = deptDOS2.stream().filter(e -> e.getCharacteristic().equals(batchImportVO.getRelation())).collect(Collectors.toList());
DeptDO deptDO = collect1.get(0); DeptDO deptDO = collect1.get(0);
deptDO3.setParentId(deptDO.getId()); deptDO3.setParentId(deptDO.getId());
deptDO3.setParentOrganizationName(deptDO.getName() + "," + batchImportVO.getDepName()); deptDO3.setParentOrganizationName(deptDO.getParentOrganizationName() + "," + batchImportVO.getDepName());
deptDO3.setCharacteristic(batchImportVO.getCharacteristic());
deptMapper.insert(deptDO3); deptMapper.insert(deptDO3);
deptDO3.setParentOrganizationIds(deptDO.getId() + "," + deptDO3.getId()); deptDO3.setParentOrganizationIds(deptDO.getParentOrganizationIds() + "," + deptDO3.getId());
deptMapper.updateById(deptDO3); deptMapper.update(deptDO3,Wrappers.<DeptDO>lambdaUpdate().eq(DeptDO::getId,deptDO3.getId()));
deptDOS3.add(deptDO3); deptDOS3.add(deptDO3);
} }
// 装入层级4 // 装入层级4
for (BatchImportVO batchImportVO : batchImportVOS4) { for (BatchImportVO batchImportVO : batchImportVOS4) {
DeptDO deptDO4 = new DeptDO(); DeptDO deptDO4 = new DeptDO();
deptDO4.setName(batchImportVO.getDepName()); deptDO4.setName(batchImportVO.getDepName());
List<DeptDO> collect1 = deptDOS3.stream().filter(e -> e.getCharacteristic().equals(batchImportVO.getCharacteristic())).collect(Collectors.toList()); List<DeptDO> collect1 = deptDOS3.stream().filter(e -> e.getCharacteristic().equals(batchImportVO.getRelation())).collect(Collectors.toList());
DeptDO deptDO = collect1.get(0); DeptDO deptDO = collect1.get(0);
deptDO4.setParentId(deptDO.getId()); deptDO4.setParentId(deptDO.getId());
deptDO4.setParentOrganizationName(deptDO.getName() + "," + batchImportVO.getDepName()); deptDO4.setParentOrganizationName(deptDO.getParentOrganizationName() + "," + batchImportVO.getDepName());
deptMapper.insert(deptDO4); deptMapper.insert(deptDO4);
deptDO4.setParentOrganizationIds(deptDO.getId() + "," + deptDO4.getId()); deptDO4.setParentOrganizationIds(deptDO.getParentOrganizationIds() + "," + deptDO4.getId());
deptMapper.updateById(deptDO4); deptMapper.update(deptDO4,Wrappers.<DeptDO>lambdaUpdate().eq(DeptDO::getId,deptDO4.getId()));
deptDOS3.add(deptDO4); deptDOS4.add(deptDO4);
} }
});
}
}).sheet().headRowNumber(1).doRead();
} catch (IOException e) { } catch (IOException e) {
log.error("导入组织架构失败!", e); log.error("导入组织架构失败!", e);
} finally { } finally {