简单的Service实例
实体类
@Data
public class OmsOrder implements Serializable {
@ApiModelProperty(value = "订单id")
private Long id;
private Long memberId;
private Long couponId;
@ApiModelProperty(value = "订单编号")
private String orderSn;
@ApiModelProperty(value = "提交时间")
private Date createTime;
@ApiModelProperty(value = "用户帐号")
private String memberUsername;
@ApiModelProperty(value = "订单总金额")
private BigDecimal totalAmount;
@ApiModelProperty(value = "应付金额(实际支付金额)")
private BigDecimal payAmount;
@ApiModelProperty(value = "运费金额")
private BigDecimal freightAmount;
@ApiModelProperty(value = "促销优化金额(促销价、满减、阶梯价)")
private BigDecimal promotionAmount;
@ApiModelProperty(value = "积分抵扣金额")
private BigDecimal integrationAmount;
@ApiModelProperty(value = "优惠券抵扣金额")
private BigDecimal couponAmount;
@ApiModelProperty(value = "管理员后台调整订单使用的折扣金额")
private BigDecimal discountAmount;
@ApiModelProperty(value = "支付方式:0->未支付;1->支付宝;2->微信")
private Integer payType;
@ApiModelProperty(value = "订单来源:0->PC订单;1->app订单")
private Integer sourceType;
@ApiModelProperty(value = "订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单")
private Integer status;
@ApiModelProperty(value = "订单类型:0->正常订单;1->秒杀订单")
private Integer orderType;
@ApiModelProperty(value = "物流公司(配送方式)")
private String deliveryCompany;
@ApiModelProperty(value = "物流单号")
private String deliverySn;
@ApiModelProperty(value = "自动确认时间(天)")
private Integer autoConfirmDay;
@ApiModelProperty(value = "可以获得的积分")
private Integer integration;
@ApiModelProperty(value = "可以活动的成长值")
private Integer growth;
@ApiModelProperty(value = "活动信息")
private String promotionInfo;
@ApiModelProperty(value = "发票类型:0->不开发票;1->电子发票;2->纸质发票")
private Integer billType;
@ApiModelProperty(value = "发票抬头")
private String billHeader;
@ApiModelProperty(value = "发票内容")
private String billContent;
@ApiModelProperty(value = "收票人电话")
private String billReceiverPhone;
@ApiModelProperty(value = "收票人邮箱")
private String billReceiverEmail;
@ApiModelProperty(value = "收货人姓名")
private String receiverName;
@ApiModelProperty(value = "收货人电话")
private String receiverPhone;
@ApiModelProperty(value = "收货人邮编")
private String receiverPostCode;
@ApiModelProperty(value = "省份/直辖市")
private String receiverProvince;
@ApiModelProperty(value = "城市")
private String receiverCity;
@ApiModelProperty(value = "区")
private String receiverRegion;
@ApiModelProperty(value = "详细地址")
private String receiverDetailAddress;
@ApiModelProperty(value = "订单备注")
private String note;
@ApiModelProperty(value = "确认收货状态:0->未确认;1->已确认")
private Integer confirmStatus;
@ApiModelProperty(value = "删除状态:0->未删除;1->已删除")
private Integer deleteStatus;
@ApiModelProperty(value = "下单时使用的积分")
private Integer useIntegration;
@ApiModelProperty(value = "支付时间")
private Date paymentTime;
@ApiModelProperty(value = "发货时间")
private Date deliveryTime;
@ApiModelProperty(value = "确认收货时间")
private Date receiveTime;
@ApiModelProperty(value = "评价时间")
private Date commentTime;
@ApiModelProperty(value = "修改时间")
private Date modifyTime;
}
Dao
public interface OmsOrderDao {
List<OmsOrder> getList(@Param("queryParam") OmsOrderQueryParam queryParam);
int delivery(@Param("list") List<OmsOrderDeliveryParam> deliveryParamList);
OmsOrderDetail getDetail(@Param("id") Long id);
}
Service
public interface OmsOrderService {
List<OmsOrder> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum);
@Transactional
int delivery(List<OmsOrderDeliveryParam> deliveryParamList);
@Transactional
int close(List<Long> ids, String note);
int delete(List<Long> ids);
OmsOrderDetail detail(Long id);
@Transactional
int updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam);
@Transactional
int updateMoneyInfo(OmsMoneyInfoParam moneyInfoParam);
@Transactional
int updateNote(Long id, String note, Integer status);
}
ServiceImpl
@Service
public class OmsOrderServiceImpl implements OmsOrderService {
@Autowired
private OmsOrderMapper orderMapper;
@Autowired
private OmsOrderDao orderDao;
@Autowired
private OmsOrderOperateHistoryDao orderOperateHistoryDao;
@Autowired
private OmsOrderOperateHistoryMapper orderOperateHistoryMapper;
@Override
public List<OmsOrder> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
return orderDao.getList(queryParam);
}
@Override
public int delivery(List<OmsOrderDeliveryParam> deliveryParamList) {
int count = orderDao.delivery(deliveryParamList);
List<OmsOrderOperateHistory> operateHistoryList = deliveryParamList.stream()
.map(omsOrderDeliveryParam -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(omsOrderDeliveryParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(2);
history.setNote("完成发货");
return history;
}).collect(Collectors.toList());
orderOperateHistoryDao.insertList(operateHistoryList);
return count;
}
@Override
public int close(List<Long> ids, String note) {
OmsOrder record = new OmsOrder();
record.setStatus(4);
OmsOrderExample example = new OmsOrderExample();
example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
int count = orderMapper.updateByExampleSelective(record, example);
List<OmsOrderOperateHistory> historyList = ids.stream().map(orderId -> {
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(orderId);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(4);
history.setNote("订单关闭:"+note);
return history;
}).collect(Collectors.toList());
orderOperateHistoryDao.insertList(historyList);
return count;
}
@Override
public int delete(List<Long> ids) {
OmsOrder record = new OmsOrder();
record.setDeleteStatus(1);
OmsOrderExample example = new OmsOrderExample();
example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
return orderMapper.updateByExampleSelective(record, example);
}
@Override
public OmsOrderDetail detail(Long id) {
return orderDao.getDetail(id);
}
@Override
public int updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam) {
OmsOrder order = new OmsOrder();
order.setId(receiverInfoParam.getOrderId());
order.setReceiverName(receiverInfoParam.getReceiverName());
order.setReceiverPhone(receiverInfoParam.getReceiverPhone());
order.setReceiverPostCode(receiverInfoParam.getReceiverPostCode());
order.setReceiverDetailAddress(receiverInfoParam.getReceiverDetailAddress());
order.setReceiverProvince(receiverInfoParam.getReceiverProvince());
order.setReceiverCity(receiverInfoParam.getReceiverCity());
order.setReceiverRegion(receiverInfoParam.getReceiverRegion());
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(receiverInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(receiverInfoParam.getStatus());
history.setNote("修改收货人信息");
orderOperateHistoryMapper.insert(history);
return count;
}
@Override
public int updateMoneyInfo(OmsMoneyInfoParam moneyInfoParam) {
OmsOrder order = new OmsOrder();
order.setId(moneyInfoParam.getOrderId());
order.setFreightAmount(moneyInfoParam.getFreightAmount());
order.setDiscountAmount(moneyInfoParam.getDiscountAmount());
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(moneyInfoParam.getOrderId());
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(moneyInfoParam.getStatus());
history.setNote("修改费用信息");
orderOperateHistoryMapper.insert(history);
return count;
}
@Override
public int updateNote(Long id, String note, Integer status) {
OmsOrder order = new OmsOrder();
order.setId(id);
order.setNote(note);
order.setModifyTime(new Date());
int count = orderMapper.updateByPrimaryKeySelective(order);
OmsOrderOperateHistory history = new OmsOrderOperateHistory();
history.setOrderId(id);
history.setCreateTime(new Date());
history.setOperateMan("后台管理员");
history.setOrderStatus(status);
history.setNote("修改备注信息:"+note);
orderOperateHistoryMapper.insert(history);
return count;
}
}
Controller
@Controller
@Api(tags = "OmsOrderController", description = "订单管理")
@RequestMapping("/order")
public class OmsOrderController {
@Autowired
private OmsOrderService orderService;
@ApiOperation("查询订单")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<OmsOrder>> list(OmsOrderQueryParam queryParam,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
List<OmsOrder> orderList = orderService.list(queryParam, pageSize, pageNum);
return CommonResult.success(CommonPage.restPage(orderList));
}
@ApiOperation("批量发货")
@RequestMapping(value = "/update/delivery", method = RequestMethod.POST)
@ResponseBody
public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList) {
int count = orderService.delivery(deliveryParamList);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
@ApiOperation("批量关闭订单")
@RequestMapping(value = "/update/close", method = RequestMethod.POST)
@ResponseBody
public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note) {
int count = orderService.close(ids, note);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
@ApiOperation("批量删除订单")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids) {
int count = orderService.delete(ids);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
@ApiOperation("获取订单详情:订单信息、商品信息、操作记录")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<OmsOrderDetail> detail(@PathVariable Long id) {
OmsOrderDetail orderDetailResult = orderService.detail(id);
return CommonResult.success(orderDetailResult);
}
@ApiOperation("修改收货人信息")
@RequestMapping(value = "/update/receiverInfo", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoParam receiverInfoParam) {
int count = orderService.updateReceiverInfo(receiverInfoParam);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
@ApiOperation("修改订单费用信息")
@RequestMapping(value = "/update/moneyInfo", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateReceiverInfo(@RequestBody OmsMoneyInfoParam moneyInfoParam) {
int count = orderService.updateMoneyInfo(moneyInfoParam);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
@ApiOperation("备注订单")
@RequestMapping(value = "/update/note", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateNote(@RequestParam("id") Long id,
@RequestParam("note") String note,
@RequestParam("status") Integer status) {
int count = orderService.updateNote(id, note, status);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
}
查询参数(dto)
@Getter
@Setter
public class OmsOrderQueryParam {
@ApiModelProperty(value = "订单编号")
private String orderSn;
@ApiModelProperty(value = "收货人姓名/号码")
private String receiverKeyword;
@ApiModelProperty(value = "订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单")
private Integer status;
@ApiModelProperty(value = "订单类型:0->正常订单;1->秒杀订单")
private Integer orderType;
@ApiModelProperty(value = "订单来源:0->PC订单;1->app订单")
private Integer sourceType;
@ApiModelProperty(value = "订单提交时间")
private String createTime;
}
Mapper
public interface OmsOrderMapper {
long countByExample(OmsOrderExample example);
int deleteByExample(OmsOrderExample example);
int deleteByPrimaryKey(Long id);
int insert(OmsOrder record);
int insertSelective(OmsOrder record);
List<OmsOrder> selectByExample(OmsOrderExample example);
OmsOrder selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") OmsOrder record, @Param("example") OmsOrderExample example);
int updateByExample(@Param("record") OmsOrder record, @Param("example") OmsOrderExample example);
int updateByPrimaryKeySelective(OmsOrder record);
int updateByPrimaryKey(OmsOrder record);
}