购物车提交和订单查询接口
This commit is contained in:
parent
62c81d8fa0
commit
6432a0c004
|
|
@ -0,0 +1,51 @@
|
|||
package com.bonus.material.order.controller;
|
||||
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.book.domain.BookCarInfoDto;
|
||||
import com.bonus.material.order.domain.OrderDetailDto;
|
||||
import com.bonus.material.order.domain.OrderInfoDto;
|
||||
import com.bonus.material.order.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:04
|
||||
*/
|
||||
|
||||
@Api(value = "订单模块", tags = {"订单模块"})
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
public class OrderController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
/**
|
||||
* 提交预约车到订单
|
||||
*/
|
||||
@ApiOperation(value = "提交预约车到订单")
|
||||
@PostMapping("/submitBookCar")
|
||||
public AjaxResult submitBookCar(@RequestBody OrderInfoDto orderInfoDto) {
|
||||
Integer i = orderService.submitOrderInfo(orderInfoDto);
|
||||
if (i > 0) {
|
||||
return success("下单成功");
|
||||
} else {
|
||||
return error("下单失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交预约车到订单
|
||||
*/
|
||||
@ApiOperation(value = "获取订单详情")
|
||||
@GetMapping("/getOrderDetails")
|
||||
public AjaxResult getOrderDetails(OrderInfoDto orderInfoDto) {
|
||||
return AjaxResult.success(orderService.getOrderDetails(orderInfoDto));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.bonus.material.order.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:28
|
||||
*/
|
||||
@Data
|
||||
public class OrderDetailDto {
|
||||
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "订单id")
|
||||
private Integer orderId;
|
||||
|
||||
@ApiModelProperty(value = "设备id")
|
||||
private Integer maId;
|
||||
|
||||
@ApiModelProperty(value = "租期开始时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date rentBeginTime;
|
||||
|
||||
@ApiModelProperty(value = "租期结束时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date rentEndTime;
|
||||
|
||||
@ApiModelProperty(value = "天数")
|
||||
private String days;
|
||||
|
||||
@ApiModelProperty(value = "数量")
|
||||
private Integer num;
|
||||
|
||||
@ApiModelProperty(value = "总金额")
|
||||
private BigDecimal costs;
|
||||
|
||||
@ApiModelProperty(value = "设备类型(0:编码 1:数量)")
|
||||
private String manageType;
|
||||
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.bonus.material.order.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:28
|
||||
*/
|
||||
@Data
|
||||
public class OrderInfoDto {
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private Integer orderId;
|
||||
|
||||
@ApiModelProperty(value = "父id(续租原订单)")
|
||||
private Integer pId;
|
||||
|
||||
@ApiModelProperty(value = "订单编号")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "订单日期")
|
||||
private Date orderTime;
|
||||
|
||||
@ApiModelProperty(value = "开始日期")
|
||||
private Date startTime;
|
||||
|
||||
@ApiModelProperty(value = "结束日期")
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "订单金额")
|
||||
private BigDecimal cost;
|
||||
|
||||
@ApiModelProperty(value = " 订单状态")
|
||||
private String orderStatus;
|
||||
|
||||
@ApiModelProperty(value = " 装备名称")
|
||||
private String deviceName;
|
||||
|
||||
@ApiModelProperty(value = "下单地址")
|
||||
private String address;
|
||||
|
||||
@ApiModelProperty(value = "下单用户id")
|
||||
private Long orderUser;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private Long creater;
|
||||
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改人")
|
||||
private Long updater;
|
||||
|
||||
@ApiModelProperty(value = "修改日期")
|
||||
private Date updateTime;
|
||||
|
||||
private List<OrderDetailDto> detailsList;
|
||||
|
||||
@ApiModelProperty(value = "承租方公司名称")
|
||||
private String companyName;
|
||||
|
||||
@ApiModelProperty(value = "出租方公司名称")
|
||||
private String czcompanyName;
|
||||
|
||||
@ApiModelProperty(value = "出租方联系电话")
|
||||
private String personPhone;
|
||||
|
||||
@ApiModelProperty(value = "承租方联系电话")
|
||||
private String phoneNumber;
|
||||
|
||||
@ApiModelProperty(value = "租金区间字段")
|
||||
private BigDecimal lowerBound;
|
||||
|
||||
private BigDecimal upperBound;
|
||||
|
||||
private String ids;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.bonus.material.order.mapper;
|
||||
|
||||
import com.bonus.material.device.domain.DevInfo;
|
||||
import com.bonus.material.order.domain.OrderDetailDto;
|
||||
import com.bonus.material.order.domain.OrderInfoDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:36
|
||||
*/
|
||||
public interface OrderMapper {
|
||||
Integer insertOrderInfo(OrderInfoDto orderInfoDto);
|
||||
|
||||
Integer insertOrderDetail(OrderDetailDto orderDetailDto);
|
||||
|
||||
DevInfo getdeviceCount(OrderDetailDto orderDetailDto);
|
||||
|
||||
Integer updateDeviceStatus(OrderDetailDto orderDetailDto);
|
||||
|
||||
List<OrderInfoDto> getOrderDetails(OrderInfoDto orderInfoDto);
|
||||
|
||||
OrderDetailDto selectOrderDetailsById(String id);
|
||||
|
||||
void updateMaStatus(OrderDetailDto orderDetailDto);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.bonus.material.order.service;
|
||||
|
||||
import com.bonus.material.order.domain.OrderDetailDto;
|
||||
import com.bonus.material.order.domain.OrderInfoDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:34
|
||||
*/
|
||||
public interface OrderService {
|
||||
|
||||
Integer submitOrderInfo(OrderInfoDto orderInfoDto);
|
||||
|
||||
List<OrderInfoDto> getOrderDetails(OrderInfoDto orderInfoDto);
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.bonus.material.order.service.impl;
|
||||
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.device.domain.DevInfo;
|
||||
import com.bonus.material.order.domain.OrderDetailDto;
|
||||
import com.bonus.material.order.domain.OrderInfoDto;
|
||||
import com.bonus.material.order.mapper.OrderMapper;
|
||||
import com.bonus.material.order.service.OrderService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liang.chao
|
||||
* @Date:2024/11/26 - 10:34
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Integer submitOrderInfo(OrderInfoDto orderInfoDto) {
|
||||
// 首先判断库存是否足够
|
||||
List<OrderDetailDto> orderDetailDtos = orderInfoDto.getDetailsList();
|
||||
for (OrderDetailDto orderDetailDto : orderDetailDtos) {
|
||||
// 如果是数量设备 ,改库存
|
||||
if ("1".equals(orderDetailDto.getManageType())) {
|
||||
// 先查询库存是否足够
|
||||
DevInfo devInfo = orderMapper.getdeviceCount(orderDetailDto);
|
||||
if (devInfo.getDeviceCount() < orderDetailDto.getNum()) {
|
||||
throw new RuntimeException(devInfo.getDeviceName() + "库存不足");
|
||||
}
|
||||
} else {
|
||||
//如果是编码设备,改设备状态为在租
|
||||
orderMapper.updateDeviceStatus(orderDetailDto);
|
||||
}
|
||||
// 更改购物车状态为已下单
|
||||
orderMapper.updateMaStatus(orderDetailDto);
|
||||
}
|
||||
//生成订单信息
|
||||
String code = "D" + System.currentTimeMillis();
|
||||
orderInfoDto.setOrderStatus("2");
|
||||
orderInfoDto.setCode(code);
|
||||
Long userid = SecurityUtils.getLoginUser().getUserid();
|
||||
orderInfoDto.setOrderUser(userid);
|
||||
orderInfoDto.setCreater(userid);
|
||||
Integer i = orderMapper.insertOrderInfo(orderInfoDto);
|
||||
if (i > 0) {
|
||||
for (OrderDetailDto orderDetailDto : orderDetailDtos) {
|
||||
orderDetailDto.setOrderId(orderInfoDto.getOrderId());
|
||||
orderMapper.insertOrderDetail(orderDetailDto);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderInfoDto> getOrderDetails(OrderInfoDto orderInfoDto) {
|
||||
List<OrderDetailDto> list = new ArrayList();
|
||||
List<OrderInfoDto> orderInfoDtos = orderMapper.getOrderDetails(orderInfoDto);
|
||||
for (OrderInfoDto dto : orderInfoDtos) {
|
||||
String ids = dto.getIds();
|
||||
for (String id : ids.split(",")) {
|
||||
OrderDetailDto orderDetailDto = orderMapper.selectOrderDetailsById(id);
|
||||
list.add(orderDetailDto);
|
||||
}
|
||||
dto.setDetailsList(list);
|
||||
}
|
||||
return orderInfoDtos;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.material.order.mapper.OrderMapper">
|
||||
|
||||
<insert id="insertOrderInfo" parameterType="com.bonus.material.order.domain.OrderInfoDto" useGeneratedKeys="true" keyProperty="orderId">
|
||||
insert into ma_order_info (code, order_time, cost, order_status, order_user, address, creater, create_time)
|
||||
values
|
||||
(#{code}, now(), #{cost}, #{orderStatus}, #{orderUser}, #{address}, #{creater}, now())
|
||||
</insert>
|
||||
<insert id="insertOrderDetail">
|
||||
INSERT INTO `ma_order_details` (
|
||||
`order_id`,
|
||||
`ma_id`,
|
||||
`rent_begin_time`,
|
||||
`rent_end_time`,
|
||||
`days`,
|
||||
`num`,
|
||||
`costs`,
|
||||
`create_time`,
|
||||
`update_time`
|
||||
) VALUES (
|
||||
#{orderId},
|
||||
#{maId},
|
||||
#{rentBeginTime},
|
||||
#{rentEndTime},
|
||||
#{days},
|
||||
#{num},
|
||||
#{costs},
|
||||
now(),
|
||||
#{updateTime})
|
||||
</insert>
|
||||
<update id="updateDeviceStatus">
|
||||
update ma_dev_info set ma_status = 3 where ma_id = #{maId} and is_active = 1
|
||||
</update>
|
||||
<update id="updateMaStatus">
|
||||
update book_car_detail set order_status = 1 where id = #{id}
|
||||
</update>
|
||||
<select id="getdeviceCount" resultType="com.bonus.material.device.domain.DevInfo">
|
||||
select device_count,device_name from ma_dev_info where ma_id = #{maId} and is_active = 1
|
||||
</select>
|
||||
<select id="getOrderDetails" resultType="com.bonus.material.order.domain.OrderInfoDto">
|
||||
SELECT
|
||||
moi.code AS code,
|
||||
GROUP_CONCAT(hh.id) AS ids,
|
||||
moi.order_time,
|
||||
c.company_name AS czcompanyName,
|
||||
mdi.person_phone AS personPhone,
|
||||
su.phonenumber AS phoneNumber,
|
||||
moi.address,
|
||||
dept.companyName
|
||||
FROM
|
||||
ma_order_details hh
|
||||
LEFT JOIN ma_order_info moi ON moi.order_id = hh.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON hh.ma_id = mdi.ma_id
|
||||
LEFT JOIN bm_company_info c ON mdi.own_co = c.company_id
|
||||
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
||||
LEFT JOIN sys_user su ON su.user_id = moi.order_user
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
sd.dept_name AS companyName,
|
||||
sd.dept_id AS deptId
|
||||
FROM
|
||||
sys_dept sd
|
||||
JOIN (
|
||||
SELECT
|
||||
SUBSTRING_INDEX(ancestors, ',', 1) AS first_ancestor,
|
||||
dept_id
|
||||
FROM
|
||||
sys_dept
|
||||
) AS subquery
|
||||
ON sd.dept_id = subquery.dept_id
|
||||
AND sd.dept_id = subquery.first_ancestor
|
||||
) dept ON dept.deptId = su.dept_id
|
||||
WHERE
|
||||
mt.del_flag = '0'
|
||||
<if test="deviceName != null and deviceName != ''">
|
||||
AND mdi.device_name like concat('%',#{deviceName},'%')
|
||||
</if>
|
||||
<if test="orderStatus != null">
|
||||
AND moi.order_status = #{orderStatus}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != '' ">
|
||||
AND moi.order_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
|
||||
</if>
|
||||
<if test="czcompanyName != null and czcompanyName != ''">
|
||||
AND c.company_name like concat('%',#{czcompanyName},'%')
|
||||
</if>
|
||||
<if test="companyName != null and companyName != ''">
|
||||
AND dept.companyName like concat('%',#{companyName},'%')
|
||||
</if>
|
||||
<if test="companyName != null and companyName != ''">
|
||||
AND mdi.month_lease_price BETWEEN #{lowerBound} AND #{upperBound}
|
||||
</if>
|
||||
GROUP BY
|
||||
c.company_id,
|
||||
moi.`code`,
|
||||
su.phonenumber,
|
||||
moi.address,
|
||||
moi.order_time
|
||||
</select>
|
||||
<select id="selectOrderDetailsById" resultType="com.bonus.material.order.domain.OrderDetailDto">
|
||||
SELECT
|
||||
mdi.device_name,
|
||||
mdi.day_lease_price,
|
||||
moi.order_status,
|
||||
hh.days,
|
||||
hh.num,
|
||||
hh.costs,
|
||||
hh.rent_begin_time,
|
||||
hh.rent_end_time
|
||||
FROM
|
||||
ma_order_details hh
|
||||
LEFT JOIN ma_order_info moi on hh.order_id = moi.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON hh.ma_id = mdi.ma_id
|
||||
WHERE
|
||||
id = 1
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue