提交 4000e048 作者: “chaining”

feat:

1. 墙盒excel导入
2. 墙盒批量申请
父级 47a6f82f
package com.boco.nbd.wios.downloadfile.controller;
import cn.hutool.core.util.ObjectUtil;
import com.boco.nbd.wios.manage.entity.bo.Order;
import com.boco.nbd.wios.manage.entity.vo.WallboxApplyExcelVO;
import com.boco.nbd.wios.manage.mapper.def.OrderDao;
import com.boco.nbd.wios.manage.service.impl.WallboxApplyService;
import com.boco.nbd.wios.utils.ExcelUtils;
import com.ihidea.component.api.v2.BaseResponse;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
public class ImportControllerV2 {
@Autowired
private Validator validator;
@Autowired
private WallboxApplyService wallboxApplyService;
@Autowired
private OrderDao orderDao;
@PostMapping("/wallbox-apply/import")
@ApiOperation("导入墙盒申请")
public BaseResponse<List<WallboxApplyExcelVO>> importExcel(@RequestParam(value = "file") MultipartFile file
) throws Exception {
List<WallboxApplyExcelVO> list = ExcelUtils.read(file, WallboxApplyExcelVO.class);
for (WallboxApplyExcelVO vo : list) {
Set<ConstraintViolation<WallboxApplyExcelVO>> violations = validator.validate(vo, CreateEntityGroup
.class);
if (!violations.isEmpty()) {
String errorMessage = violations.stream()
.map(ConstraintViolation::getMessage)
.collect(Collectors.joining(";"));
vo.setErrorMessage(errorMessage);
}
if (StringUtils.isNotBlank(vo.getOrderId())){
Order order = orderDao.selectById(vo.getOrderId());
if (ObjectUtil.isNull(order)) {
vo.setErrorMessage("不存在安装订单号");
}
if (ObjectUtil.isNotNull(order)) {
vo.setWallboxModel(order.getWallboxModel());
}
if (ObjectUtil.isNotNull(wallboxApplyService.selectWallboxDetail(vo.getOrderId()))) {
vo.setErrorMessage("重复订单申请");
}
}
}
return new BaseResponse<>(list);
}
}
package com.boco.nbd.wios.flow.controller;
import cn.hutool.core.util.ObjectUtil;
import com.boco.nbd.framework.common.ResponseMessage2;
import com.boco.nbd.framework.parent.microservice.exception.ErrorInfoException;
import com.boco.nbd.wios.manage.client.DepponClient;
import com.boco.nbd.wios.manage.entity.bo.Order;
import com.boco.nbd.wios.manage.entity.bo.Supplier;
import com.boco.nbd.wios.manage.entity.bo.SupplierStaff;
import com.boco.nbd.wios.manage.entity.bo.WallboxApply;
import com.boco.nbd.wios.manage.entity.cams.enums.OrderStatus;
import com.boco.nbd.wios.manage.entity.vo.WallboxApplyExcelVO;
import com.boco.nbd.wios.manage.mapper.def.OrderDao;
import com.boco.nbd.wios.manage.service.impl.*;
import com.boco.nbd.wios.utils.ExcelUtils;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import com.ihidea.core.support.session.SessionInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
public class ImportWallboxApplyController {
@Autowired
private Validator validator;
@Autowired
private WallboxApplyService wallboxApplyService;
@Autowired
private OrderDao orderDao;
@Autowired
private OrderService orderService;
@Autowired
private TokenService tokenService;
@Autowired
private SupplierStaffService supplierStaffService;
@Autowired
private SupplierService supplierService;
@Resource
private DepponClient depponClient;
@PostMapping("/wallboxApply/importExcel")
@ApiOperation("导入墙盒申请")
public ResponseMessage2 importExcel(@RequestParam(value = "file") MultipartFile file
) throws Exception {
List<WallboxApplyExcelVO> list = ExcelUtils.read(file, WallboxApplyExcelVO.class);
for (int i = 0; i < list.size(); i++) {
String orderId = list.get(i).getOrderId();
Integer ifEmergency = list.get(i).getIfEmergency();
Order order = orderService.get(orderId);
if (ObjectUtil.isNull(order)) {
throw new ErrorInfoException("第" + (i + 1) + "行订单不存在!");
}
Integer status = order.getStatus();
// 检查订单状态是否在1-43之间
boolean allowed = status >= OrderStatus.DISPATCHING.getType() && status <= OrderStatus.INSTALLING.getType();
if (!allowed) {
throw new ErrorInfoException("第" + (i + 1) + "行订单派单之后才能进行墙盒申请!");
}
SessionInfo loginUser = tokenService.getUser();
String userId = loginUser.getUserId();
SupplierStaff infoByAccount = supplierStaffService.getByAccountId(Integer.valueOf(userId));
Supplier supplier = supplierService.getById(infoByAccount.getSupplierId());
if (supplier == null) {
throw new ErrorInfoException("第" + (i + 1) + "行供应商不存在!");
}
WallboxApply wa = new WallboxApply();
wa.setSupplierId(Long.valueOf(supplier.getId()));
wa.setSupplierTeam(supplier.getName());
wa.setOrderId(orderId);
wa.setIfEmergency(ifEmergency);
wa.setCreateAccount(tokenService.getUser().getUserId());
//TODO 默认仓库
// wa.setReceiverWarehouseId(receiverWarehouseId);
wallboxApplyService.insertWallboxApply(wa);
}
return ResponseMessage2.Success();
}
}
package com.boco.nbd.wios.flow.imports.impl;
import cn.hutool.core.util.ObjectUtil;
import com.boco.nbd.cams.core.constant.MessageConstant;
import com.boco.nbd.wios.flow.imports.Import;
import com.boco.nbd.wios.manage.entity.bo.Order;
import com.boco.nbd.wios.manage.entity.cams.enums.OrderStatus;
import com.boco.nbd.wios.manage.service.impl.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* description
*
* @author ning.chai@foxmail.com
*/
@Service
@Slf4j
public class WallboxApplyImport implements Import {
@Autowired
private WallboxApplyService wallboxApplyService;
@Autowired
private OrderService orderService;
@Override
public List<?> handle(List<Object> list) {
for (int i = 1; i < list.size(); i++) {
List<String> childList = (List<String>) list.get(i);
// 安装订单号
String orderId = childList.get(0);
// 是否紧急
String ifEmergency = childList.get(1);
if (org.springframework.util.StringUtils.isEmpty(orderId) || org.springframework.util.StringUtils.isEmpty(ifEmergency)) {
childList.add("error:"+ MessageConstant.MISSING_PARAM);
continue;
}
if (StringUtils.isNotBlank(orderId)){
Order order = orderService.get(orderId);
if (ObjectUtil.isNull(order)) {
childList.add("error:不存在安装订单号");
continue;
}
Integer status = order.getStatus();
// 检查订单状态是否在1-43之间
boolean allowed = status >= OrderStatus.DISPATCHING.getType() && status <= OrderStatus.INSTALLING.getType();
if (!allowed) {
childList.add("error:订单派单之后才能进行墙盒申请");
}
if (ObjectUtil.isNotNull(wallboxApplyService.selectWallboxDetail(orderId))) {
childList.add("error:重复订单申请");
continue;
}
}
}
return list;
}
}
...@@ -7,6 +7,7 @@ import lombok.Data; ...@@ -7,6 +7,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable;
/** /**
* <p> * <p>
...@@ -16,7 +17,7 @@ import javax.validation.constraints.NotNull; ...@@ -16,7 +17,7 @@ import javax.validation.constraints.NotNull;
* @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a> * @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a>
*/ */
@Data @Data
public class WallboxApplyExcelVO { public class WallboxApplyExcelVO implements Serializable {
/** 安装订单号 */ /** 安装订单号 */
@ExcelProperty("安装订单号") @ExcelProperty("安装订单号")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论