提交 266729b1 作者: “chaining”

墙盒申请

父级 92ac644e
......@@ -290,6 +290,13 @@
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.deppon.com</groupId>
<artifactId>dop-sdk</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/dop-sdk-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
</dependencies>
<dependencyManagement>
......
package com.starcharge.wios.Import.v2;
import cn.hutool.core.util.ObjectUtil;
import com.ihidea.component.api.v2.BaseResponse;
import com.starcharge.wios.dao.OrderDao;
import com.starcharge.wios.dao.entity.Order;
import com.starcharge.wios.service.WallboxApplyService;
import com.starcharge.wios.utils.ExcelUtils;
import com.starcharge.wios.validation.CreateEntityGroup;
import com.starcharge.wios.vo.WallboxApplyExcelVO;
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.starcharge.wios.client;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.Body;
import com.dtflys.forest.annotation.Post;
/**
* <p>
* 德邦物流clinet,注意入参使用Map或者对象实体
* <p>
*
* @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a>
*/
@BaseRequest(baseURL = "http://dpsanbox.deppon.com/sandbox-web/standard-order/", interceptor = DopInterceptor.class)
public interface DepponClient {
/**
* 新标准轨迹查询
* http://dop.deppon.com/#/wantAccess/myApiConfig
* @param {"mailNo":"7503587254"}
* @return 字符串
*/
@Post("newTraceQuery.action")
String newTraceQuery(@Body("params") String params);
}
package com.starcharge.wios.client;
import com.deppon.dop.module.sdk.shared.util.SecurityUtil;
import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.reflection.ForestMethod;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
/**
* <p>
* 德邦物流请求拦截器,实现自动注入companyCode、digest、timestamp参数
* <p>
*
* @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a>
*/
public class DopInterceptor <T> implements Interceptor<T> {
private final String companyCode="EWBXRCHSZX";
private final String appkey="fe38a755ce4f7629717342e441cdedff";
/**
* 该方法在被调用时,检测token是否过期,并在beforeExecute前被调用
* @Param request Forest请求对象
* @Param args 方法被调用时传入的参数数组
*/
@Override
public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
}
@Override
public boolean beforeExecute(ForestRequest request) {
request.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
String params = request.getBody().get(0).toString();
// String timestamp=System.currentTimeMillis()+"";
String timestamp="1697877426621";
//params+appkey+timestamp,,,ZDU0NzYzZWJkODRhZjBlZjcyYjEwZDYxYTNlNzRkNWQ=
String digest= SecurityUtil.getStandardDigest( params+appkey+timestamp);
request.addBody("companyCode", companyCode);
request.addBody("digest",digest);
request.addBody("timestamp",timestamp);
return true; // 继续执行请求返回true
}
/**
* 该方法在请求成功响应时被调用
*/
@Override
public void onSuccess(T data, ForestRequest req, ForestResponse res) {
}
/**
* 该方法在请求发送失败时被调用
*/
@Override
public void onError(ForestRuntimeException ex, ForestRequest req, ForestResponse res) {
// 执行发送请求失败后处理的代码
int status = res.getStatusCode(); // 获取请求响应状态码
String content = res.getContent();
}
/**
* 该方法在请求发送之后被调用
*/
@Override
public void afterExecute(ForestRequest req, ForestResponse res) {
}
private String getDigest(String plainText) {
return Base64.encodeBase64String(DigestUtils.md5Hex(plainText).getBytes());
}
}
package com.starcharge.wios.convert;
import com.starcharge.wios.dao.entity.WallboxApply;
import com.starcharge.wios.vo.WallboxApplyInstallInfoVO;
import com.starcharge.wios.vo.WallboxApplyInstallListVO;
import com.starcharge.wios.vo.WallboxApplyReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* <p>
* description
* <p>
*
* @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a>
*/
@Mapper
public interface WallboxApplyConvert {
WallboxApplyConvert INSTANCE = Mappers.getMapper(WallboxApplyConvert.class);
WallboxApply convert(WallboxApplyReqVO bean);
WallboxApplyInstallInfoVO convert2Info(WallboxApply bean);
WallboxApplyInstallListVO convert(WallboxApply bean);
List<WallboxApplyInstallListVO> convertList(List<WallboxApply> bean);
}
......@@ -126,8 +126,9 @@ public class SupplierService {
public List<SupplierVo> getList(SupplierBo condition) {
SessionInfo sessionInfo = tokenService.getUser();
if (sessionInfo != null && !StringUtils.isEmpty(sessionInfo.getAttribute().get("installSupplierId")))
if (sessionInfo != null && !StringUtils.isEmpty(sessionInfo.getAttribute().get("installSupplierId"))){
condition.setId(sessionInfo.getAttribute().get("installSupplierId"));
}
if (condition.getServiceRegionId() != null) {
Region region = regionDao.selectById(condition.getServiceRegionId());
List<String> regionIdList = Arrays.asList(region.getIdTree().split("_"));
......@@ -137,7 +138,11 @@ public class SupplierService {
}
return supplierDao.getList(condition);
}
public Supplier getById(Integer id){
return supplierDao.selectById(id);
}
public void update(int id, SupplierBo supplierBo) {
supplierDao.update(id, supplierBo);
}
......
package com.starcharge.wios.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ihidea.core.support.exception.ServiceException;
import com.ihidea.core.support.session.SessionInfo;
import com.starcharge.wios.auth.service.TokenService;
import com.starcharge.wios.dao.OrderDao;
import com.starcharge.wios.dao.OrderInstallDao;
import com.starcharge.wios.dao.SupplierDao;
import com.starcharge.wios.dao.SupplierStaffDao;
import com.starcharge.wios.dao.entity.Order;
import com.starcharge.wios.dao.entity.OrderInstall;
import com.starcharge.wios.dao.entity.SupplierStaff;
import com.starcharge.wios.dao.entity.WallboxApply;
import com.starcharge.wios.dao.mappers.WallboxApplyMapper;
import com.starcharge.wios.dto.WallboxApplyBatchCheckDTO;
import com.starcharge.wios.dto.WallboxApplyCheckDTO;
import com.starcharge.wios.dto.WallboxApplyDetailQueryDTO;
import com.starcharge.wios.vo.WallboxApplyCheckVO;
import com.starcharge.wios.vo.WallboxApplyDetailVO;
import com.starcharge.wios.vo.WallboxApplyInstallInfoVO;
import com.starcharge.wios.vo.WallboxApplyInstallListVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* description
* <p>
*
* @author <a href="mail to: ning.chai@foxmail.com" rel="nofollow">chaining</a>
*/
@Service
public class WallboxApplyService {
@Autowired
private WallboxApplyMapper wallboxApplyMapper;
@Autowired
private OrderDao orderDao;
@Autowired
private OrderInstallDao orderInstallDao;
@Autowired
private TokenService tokenService;
@Autowired
private SupplierDao supplierDao;
@Autowired
private SupplierStaffDao supplierStaffDao;
private final Integer CHECK_STATUS_REJECT = 2;
/**
* 查询墙盒申请
*
* @param id 墙盒申请主键
* @return 墙盒申请
*/
public WallboxApplyInstallInfoVO selectWallboxApplyById(Long id) {
return wallboxApplyMapper.selectWallboxApplyById(id);
}
/**
* 墙盒详情(墙盒状态)
*
* @param orderId 订单id
* @return 墙盒申请
*/
public WallboxApplyDetailVO selectWallboxDetail(String orderId) {
SessionInfo loginUser = tokenService.getUser();
String userId = loginUser.getUserId();
List<SupplierStaff> supplier = supplierStaffDao.selectByAccountId(Integer.valueOf(userId));
WallboxApplyDetailQueryDTO query = new WallboxApplyDetailQueryDTO();
query.setOrderId(orderId);
query.setSupplierId(supplier.stream().findFirst().get().getSupplierId().toString());
return wallboxApplyMapper.selectWallboxDetail(query);
}
/**
* 查询墙盒申请列表
*
* @param WallboxApply 墙盒申请
* @return 墙盒申请
*/
public List<WallboxApply> selectWallboxApplyList(WallboxApply WallboxApply) {
return wallboxApplyMapper.selectWallboxApplyList(WallboxApply);
}
/**
* 根据订单表查询墙盒申请列表
*
* @param WallboxApply 墙盒申请
* @return 墙盒申请
*/
public List<WallboxApplyInstallListVO> selectWallboxApplyListFromOrder(WallboxApply WallboxApply) {
List<WallboxApplyInstallListVO> list =
wallboxApplyMapper.selectWallboxApplyListFromOrder(WallboxApply);
list.stream().map(l->{
return l;
});
return list;
}
public WallboxApply calculateTimeRemaining(WallboxApply wallboxApply) {
return wallboxApply;
}
/**
* 新增墙盒申请
*
* @param req 墙盒申请
* @return 结果
*/
public int insertWallboxApply(WallboxApply req) {
//判断是否可以新增
//validateApplyExists(req.getOrderId());
WallboxApply condition = new WallboxApply();
condition.setOrderId(req.getOrderId());
condition.setCheckStatus(1L);
List<WallboxApply> retList = wallboxApplyMapper.selectWallboxApplyList(condition);
if (CollectionUtils.isNotEmpty(retList)){
throw new ServiceException("存在已审核通过的安装单,无法重复申请");
}
condition.setSupplierId(req.getSupplierId());
List<WallboxApply> retList2 = wallboxApplyMapper.selectWallboxApplyList(condition);
if (CollectionUtils.isNotEmpty(retList2)){
throw new ServiceException("该订单已申请");
}
//补全相关信息
Order order = orderDao.selectById(req.getOrderId());
req.setRegionId(order.getRegionId());
String wallboxModel = order.getWallboxModel();
if (StrUtil.isBlank(wallboxModel)) {
throw new ServiceException("订单数据异常,缺失墙盒信息,请联系系统管理员");
}
req.setWallboxItemId(order.getWallboxModel());
req.setWallboxModel(order.getWallboxModel() == null ? "" : order.getWallboxModel());
req.setOutOrderId(order.getOutOrderId());
req.setInstallReserveTime(order.getInstallReserveTime());
req.setAddress(order.getAddress());
req.setTrackingNumber(order.getShipno());
req.setInstallProcess(Integer.toUnsignedLong(order.getStatus()));
req.setInstallStatus(Integer.toString(order.getStatus()));
req.setOutOrderId(order.getOutOrderId());
return wallboxApplyMapper.insertWallboxApply(req);
}
/**
* 新增墙盒申请
*
* @param orderId 订单号
* @return 结果
*/
public int insertWallboxApply(int orderId) {
//判断订单状态
// orderInstallDao.selectByOrderId()
return 0;
}
/**
* 修改墙盒申请
*
* @return 结果
*/
public int updateWallboxApply(WallboxApply wallboxApply) {
WallboxApply record = wallboxApplyMapper.selectWallboxApplyByOrderId(wallboxApply.getOutOrderId());
// if (!CHECK_STATUS_REJECT.equals(record.getCheckStatus())) {
// throw new ServiceException("非驳回状态订单无法修改信息!");
// }
wallboxApply.setCheckTime(new Date());
return wallboxApplyMapper.updateWallboxApply(wallboxApply);
}
/**
* 审核
* @param req
* @return
*/
public int checkWallboxApply(WallboxApplyCheckVO req){
WallboxApply cond = new WallboxApply();
cond.setOrderId(req.getOrderId());
List<WallboxApply> list = wallboxApplyMapper.selectWallboxApplyList(cond);
List<WallboxApply> filteredList = list.stream()
.filter(l -> l.getCheckStatus() == 2)
.collect(Collectors.toList());
if (!filteredList.isEmpty()) {
throw new ServiceException("同订单已审核");
}
WallboxApply update = new WallboxApply();
update.setId(req.getId());
update.setOrderId(req.getOrderId());
update.setCheckStatus(req.getCheckStatus());
update.setCheckRemarks(req.getCheckRemarks());
update.setCheckTime(new Date());
update.setCheckAccount(tokenService.getUser().getUserId());
return wallboxApplyMapper.updateWallboxApply(update);
}
/**
* 批量审核
*/
public WallboxApplyBatchCheckDTO checkBatch(WallboxApplyBatchCheckDTO req) {
List<WallboxApplyCheckDTO> checkList = req.getCheckList();
List<WallboxApply> toUpdateList = new ArrayList<>();
boolean allowedUpdate = true;
for (WallboxApplyCheckDTO wallboxApply : checkList) {
WallboxApply cond = new WallboxApply();
cond.setOrderId(wallboxApply.getOrderId());
List<WallboxApply> list = wallboxApplyMapper.selectWallboxApplyList(cond);
List<WallboxApply> filteredList = list.stream()
.filter(l -> l.getCheckStatus() == 2)
.collect(Collectors.toList());
if (!filteredList.isEmpty()) {
wallboxApply.setDataStatus("0");
wallboxApply.setErrorMessage("该订单已审核通过");
allowedUpdate = false;
}
if (allowedUpdate){
WallboxApply update = new WallboxApply();
update.setId(wallboxApply.getId());
update.setCheckStatus(req.getCheckStatus());
update.setCheckRemarks(req.getCheckRemarks());
update.setCheckAccount(tokenService.getUser().getUserId());
toUpdateList.add(update);
}
}
if (allowedUpdate){
// 批量更新操作
toUpdateList.forEach(l -> wallboxApplyMapper.updateWallboxApply(l));
}
return req;
}
void validateApplyExists(String id) {
OrderInstall orderInstall = orderInstallDao.selectByOrderId(id);
if (ObjectUtil.isNull(orderInstall)) {
throw new ServiceException("不存在安装单号");
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论