Commit 518edf96 authored by 李灿灿's avatar 李灿灿

订单相关接口

parent 70abf9cf
......@@ -30,4 +30,28 @@ public class OrderConstants {
* 操作成功
*/
public static final String OPERATE_SUCCESS = "操作成功";
/**
* 操作失败
*/
public static final String OPERATE_FAILED = "操作失败";
/**
* 订单编号不能为空
*/
public static final String ORDER_NO_IS_EMPTY = "订单编号不能为空";
/**
* 回复内容不能为空
*/
public static final String REPLY_CONTENT_IS_EMPTY = "回复内容不能为空";
/**
* 附件不能为空
*/
public static final String ENCLOSURE_IS_EMPTY = "附件不能为空";
/**
* 非法的附件类型
*/
public static final String ENCLOSURE_TYPE_IS_ERROR = "非法的附件类型";
/**
* 附件超出上传上限
*/
public static final String ENCLOSURE_SIZE_ERROR = "附件超出上传上限";
}
package com.yifu.cloud.plus.v1.yifu.order.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrderEnclosure;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author licancan
* @description 订单回复列表vo
* @date 2022-08-29 17:07:50
*/
@Data
@Schema(description = "订单回复列表vo")
public class OrderReplyListVO implements Serializable {
private static final long serialVersionUID = -1376876766552447670L;
/**
* 订单编号
*/
@JsonIgnore
private String orderNo;
/**
* 创建人姓名(回复人)
*/
@Schema(description = "创建人姓名(回复人)")
private String createName;
/**
* 创建时间(回复时间)
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
@Schema(description = "创建时间(回复时间)")
private LocalDateTime createTime;
/**
* 回复内容
*/
@Schema(description = "回复内容")
private String replyContent;
/**
* 回复附件
*/
@Schema(description = "回复附件")
private List<TOrderEnclosure> orderReplyEnclosure;
}
......@@ -2,18 +2,23 @@ package com.yifu.cloud.plus.v1.yifu.order.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.order.constants.OrderConstants;
import com.yifu.cloud.plus.v1.yifu.order.service.TOrderService;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderDetailVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListParam;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
/**
......@@ -96,4 +101,38 @@ public class OrderController {
return tOrderService.getEnclosureUrl(id);
}
/**
* 添加回复
*
* @author licancan
* @param file 附件
* @param filePath 附件路径
* @param replyContent 回复内容
* @param orderNo 订单编号
* @return {@link R}
* @throws IOException
*/
@Schema(description = "添加回复")
@PostMapping(value = "/uploadReplyEnclosure")
public R uploadReplyEnclosure(@RequestBody MultipartFile file, String filePath, String replyContent,String orderNo) throws IOException {
return tOrderService.uploadReplyEnclosure(file, filePath,replyContent,orderNo);
}
/**
* 订单回复列表分页查询
*
* @author licancan
* @param page
* @param orderNo
* @return {@link R< IPage< OrderReplyListVO>>}
*/
@Operation(summary = "订单回复列表分页查询", description = "订单回复列表分页查询")
@GetMapping("/getOrderReplyPageList")
public R<IPage<OrderReplyListVO>> getOrderReplyPageList(Page<OrderReplyListVO> page, String orderNo) {
if (Common.isEmpty(orderNo)){
return R.failed(OrderConstants.ORDER_NO_IS_EMPTY);
}
return R.ok(tOrderService.getOrderReplyPageList(page,orderNo));
}
}
......@@ -8,6 +8,7 @@ import com.yifu.cloud.plus.v1.yifu.order.entity.TOrder;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderDetailVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListParam;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -57,4 +58,14 @@ public interface TOrderMapper extends BaseMapper<TOrder> {
* @return {@link OrderDetailVO}
*/
OrderDetailVO getOrderDetailById(@Param("id") String id);
/**
* 订单回复列表分页查询
*
* @author licancan
* @param page
* @param orderNo
* @return {@link IPage< OrderReplyListVO>}
*/
IPage<OrderReplyListVO> getOrderReplyPageList(Page<OrderReplyListVO> page,@Param("orderNo") String orderNo);
}
......@@ -9,7 +9,10 @@ import com.yifu.cloud.plus.v1.yifu.order.entity.TOrder;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderDetailVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListParam;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
......@@ -65,4 +68,27 @@ public interface TOrderService extends IService<TOrder> {
* @return {@link R}
*/
R getEnclosureUrl(String id);
/**
* 添加回复
*
* @author licancan
* @param file 附件
* @param filePath 附件路径
* @param replyContent 回复内容
* @param orderNo 订单编号
* @return {@link R}
* @throws IOException
*/
R uploadReplyEnclosure(MultipartFile file, String filePath, String replyContent, String orderNo) throws IOException;
/**
* 订单回复列表分页查询
*
* @author licancan
* @param page
* @param orderNo
* @return {@link IPage< OrderReplyListVO>}
*/
IPage<OrderReplyListVO> getOrderReplyPageList(Page<OrderReplyListVO> page, String orderNo);
}
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
......@@ -12,22 +13,29 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.order.constants.OrderConstants;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrder;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrderEnclosure;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrderReply;
import com.yifu.cloud.plus.v1.yifu.order.mapper.TOrderMapper;
import com.yifu.cloud.plus.v1.yifu.order.service.TOrderEnclosureService;
import com.yifu.cloud.plus.v1.yifu.order.service.TOrderReplyService;
import com.yifu.cloud.plus.v1.yifu.order.service.TOrderService;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderDetailVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListParam;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderListVO;
import com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
......@@ -41,6 +49,8 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
@Resource
private TOrderEnclosureService tOrderEnclosureService;
@Resource
private TOrderReplyService tOrderReplyService;
@Resource
private OSSUtil ossUtil;
/**
......@@ -88,7 +98,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
if (StringUtils.isEmpty(id)){
return R.failed(OrderConstants.ORDER_ID_IS_EMPTY);
}
if (CommonConstants.TWO_INT != status && CommonConstants.THREE_INT != status){
if (CommonConstants.ONE_INT != status && CommonConstants.TWO_INT != status){
return R.failed(OrderConstants.STATUS_ERROR);
}
YifuUser user = SecurityUtils.getUser();
......@@ -96,7 +106,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
if (!Optional.ofNullable(byId).isPresent()){
return R.failed(OrderConstants.DATA_IS_EMPTY);
}
if (CommonConstants.THREE_INT == byId.getOrderStatus()){
if (CommonConstants.TWO_INT == byId.getOrderStatus()){
return R.failed(OrderConstants.ORDER_IS_HANDLED);
}
byId.setOrderStatus(status);
......@@ -159,4 +169,104 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
return new R<>(url.toString());
}
/**
* 添加回复
*
* @author licancan
* @param file 附件
* @param filePath 附件路径
* @param replyContent 回复内容
* @param orderNo 订单编号
* @return {@link R}
* @throws IOException
*/
@Override
@Transactional
public R uploadReplyEnclosure(MultipartFile file, String filePath, String replyContent, String orderNo) throws IOException {
YifuUser user = SecurityUtils.getUser();
if (Common.isEmpty(orderNo)){
return R.failed(OrderConstants.ORDER_NO_IS_EMPTY);
}
if (Common.isEmpty(replyContent)){
return R.failed(OrderConstants.REPLY_CONTENT_IS_EMPTY);
}
//todo 校验回复内容的长度
if(Common.isEmpty(file)){
return R.failed(OrderConstants.ENCLOSURE_IS_EMPTY);
}
if(!Common.checkInsuranceFile(file.getOriginalFilename())){
return R.failed(OrderConstants.ENCLOSURE_TYPE_IS_ERROR);
}
if (file.getSize() > (CommonConstants.FIFTY_INT*CommonConstants.BYTE*CommonConstants.BYTE)){
return R.failed(OrderConstants.ENCLOSURE_SIZE_ERROR);
}
String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
//filePath不传默认存储空间的根目录
//支持的附件格式
String key = "";
if (!Common.isNotNull(filePath)) {
key = fileName;
} else {
key = filePath + "/" + fileName;
}
boolean flag = ossUtil.uploadFileByStream(file.getInputStream(), key, null);
if (flag) {
log.info("文件:" + fileName + "上传至存储空间" + ossUtil.getBucketName() + "成功!");
TOrderEnclosure orderEnclosure = new TOrderEnclosure();
orderEnclosure.setOrderNo(orderNo);
orderEnclosure.setEnclosureName(file.getOriginalFilename());
orderEnclosure.setEnclosureFlag(CommonConstants.ONE_INT);
orderEnclosure.setEnclosureAddress(key);
orderEnclosure.setDeleteFlag(CommonConstants.ZERO_INT);
try {
boolean b = tOrderEnclosureService.save(orderEnclosure);
if (b){
TOrderReply reply = new TOrderReply();
reply.setOrderNo(orderNo);
reply.setReplyContent(replyContent);
reply.setCreateName(user.getNickname());
reply.setCreateTime(LocalDateTime.now());
reply.setDeleteFlag(CommonConstants.ZERO_INT);
tOrderReplyService.save(reply);
//todo 同步推送ekp
}
} catch (Exception e) {
log.error("OSS文件上传接口异常:" + e.getMessage());
ossUtil.deleteObject(null, key);
return R.failed("failed:" + e.getMessage());
}
return R.ok(OrderConstants.OPERATE_SUCCESS);
} else {
return R.failed(OrderConstants.OPERATE_FAILED);
}
}
/**
* 订单回复列表分页查询
*
* @param page
* @param orderNo
* @return {@link IPage<OrderReplyListVO>}
* @author licancan
*/
@Override
public IPage<OrderReplyListVO> getOrderReplyPageList(Page<OrderReplyListVO> page, String orderNo) {
IPage<OrderReplyListVO> orderReplyList = baseMapper.getOrderReplyPageList(page,orderNo);
if (CollectionUtils.isNotEmpty(orderReplyList.getRecords())){
orderReplyList.getRecords().stream().forEach(e ->{
List<TOrderEnclosure> list = tOrderEnclosureService.list(Wrappers.<TOrderEnclosure>query().lambda()
.eq(TOrderEnclosure::getOrderNo, e.getOrderNo())
.eq(TOrderEnclosure::getEnclosureFlag,CommonConstants.ONE_INT)
.eq(TOrderEnclosure::getDeleteFlag,CommonConstants.ZERO_INT)
);
if (CollectionUtils.isNotEmpty(list)){
e.setOrderReplyEnclosure(list);
}else {
e.setOrderReplyEnclosure(Lists.newArrayList());
}
});
}
return orderReplyList;
}
}
......@@ -129,4 +129,16 @@
where t.ID = #{id}
</select>
<select id="getOrderReplyPageList" resultType="com.yifu.cloud.plus.v1.yifu.order.vo.OrderReplyListVO">
select
t.ORDER_NO as orderNo,
t.CREATE_NAME as createName,
t.CREATE_TIME as createTime,
t.REPLY_CONTENT as replyContent
from t_order_reply t
where t.DELETE_FLAG = 0
and t.ORDER_NO = #{orderNo}
ORDER BY t.CREATE_TIME DESC
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment