拆分think模块包
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.OrderParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-24 13:46:21
|
||||
*/
|
||||
@Api(tags = "订单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/order")
|
||||
public class OrderController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询订单")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Order>> page(OrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(orderService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部订单")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Order>> list(OrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(orderService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询订单")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Order> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(orderService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加订单")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Order order) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
// 微信openid(必填)
|
||||
if(StrUtil.isBlank(loginUser.getOpenid())){
|
||||
return fail("微信openid(必填)");
|
||||
}
|
||||
// 商品描述(必填)
|
||||
if(StrUtil.isBlank(order.getComments())){
|
||||
return fail("商品描述(必填)");
|
||||
}
|
||||
// 微信支付(商品金额不能为0)
|
||||
if(order.getPayType().equals(1)){
|
||||
if (order.getTotalPrice().compareTo(BigDecimal.ZERO) == 0) {
|
||||
return fail("商品金额不能为0");
|
||||
}
|
||||
}
|
||||
|
||||
// 订单信息
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
long orderNo = IdUtil.getSnowflakeNextId();
|
||||
order.setOrderNo(Long.toString(orderNo));
|
||||
order.setUserId(loginUser.getUserId());
|
||||
order.setOpenid(loginUser.getOpenid());
|
||||
order.setRealName(loginUser.getRealName());
|
||||
order.setPhone(loginUser.getPhone());
|
||||
final List<Integer> collect = order.getOrderInfoList().stream().map(OrderInfo::getStartTime).collect(Collectors.toList());
|
||||
order.setStartTime(Collections.min(collect));
|
||||
order.setVersion(10);
|
||||
if (orderService.save(order)) {
|
||||
order.getOrderInfoList().forEach(d -> {
|
||||
d.setOid(order.getOrderId());
|
||||
d.setTimeFlag(timeMillis);
|
||||
d.setVersion(10);
|
||||
d.setOrderTime(timeMillis / 1000);
|
||||
});
|
||||
orderInfoService.saveBatch(order.getOrderInfoList());
|
||||
// 创建微信订单
|
||||
if (order.getPayType().equals(1)) {
|
||||
return success("下单成功",orderService.createWxOrder(order));
|
||||
}
|
||||
}
|
||||
return fail("下单失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改订单")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除订单")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (orderService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加订单")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Order> list) {
|
||||
if (orderService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改订单")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Order> batchParam) {
|
||||
if (batchParam.update(orderService, "order_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除订单")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (orderService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user