CardOrderService.java
6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.rnt.service;
/**
* 订单service.<br/>
*
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: ParkOrderService.java
* @Description:
* @version: v1.0.0
* @author: wangfs
* @date: 2017年6月8日 下午7:26:31
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2017年6月8日 wangfs v1.0.0 创建
*/
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.rnt.model.park.ParkingLot;
import org.beetl.sql.core.kit.StringKit;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Duang;
import com.jfinal.log.Log;
import com.rnt.commo.enums.DataStatusEnum;
import com.rnt.commo.enums.OrderTypeEnum;
import com.rnt.commo.enums.SequenceTypeEnum;
import com.rnt.model.zf.Order;
import com.rnt.model.zf.OrderDetailCard;
import com.rnt.model.zf.ParkCardCoupons;
import com.rnt.utils.SequenceUtil;
import com.rnt.vo.BizResult;
import com.rnt.vo.CardBuyVO;
import com.rnt.vo.CardOrderVO;
import com.rnt.vo.ParkLotCardVO;
public class CardOrderService {
private static final Log logger = Log.getLog(CardOrderService.class);
/**
* 插入订单数据
* @param cardBuyVO
* @return OrderId
*/
public String saveOrder(CardBuyVO cardBuyVO,ParkCardCoupons parkCardCoupons){
logger.info("[开始保存月卡/年卡信息],入参="+JSONObject.toJSONString(cardBuyVO));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
boolean insertFlg = false;
boolean insertDetailFlg = false;
Order order = new Order();
try{
String parkId = parkCardCoupons.getParkId();
ParkingLot parkingLot = ParkingLot.dao.findFirst("select * from parking_lot t where t.pl_no = ?",parkId );
order.setParkName(parkingLot.getPlName());
order.setOrderId(SequenceUtil.getNextOrderId(SequenceTypeEnum.ORDER_CARD_BUY.value()));
//** 订单类型: 1:停车订单,2:年卡订单, 3:月卡订单 wangfs Add . */
order.setOrderType(Integer.valueOf(cardBuyVO.getOrderType()));
order.setOrderState(OrderTypeEnum.ORDER_TYPE_2.value());
order.setParkId(parkId);
order.setCarNumber(cardBuyVO.getCarNum());
order.setCustPersonId(cardBuyVO.getPersonCustId());
order.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
order.setOrderPayedFee(BigDecimal.valueOf(Long.valueOf("0")));//已付费用
order.setOrderNotPayFee(StringKit.isNotBlank(cardBuyVO.getTotleMoney()) ? new BigDecimal(cardBuyVO.getTotleMoney()) : BigDecimal.ZERO); //未支付费用(本次应付金额)
order.setOrderTotalFee(StringKit.isNotBlank(cardBuyVO.getTotleMoney()) ? new BigDecimal(cardBuyVO.getTotleMoney()) : BigDecimal.ZERO); //总金额
order.setRemark("微信公众号购买卡");
order.setCreateDate(new Date());
order.setOrderResource("微信公众号购买卡");
order.setOrderTitle("购买卡订单");
insertFlg =order.save();
/**插入卡订单明细表.*/
if(insertFlg){
OrderDetailCard orderDetailCard = new OrderDetailCard();
orderDetailCard.setPersonCardId(Long.valueOf(cardBuyVO.getPersonCardId()));
orderDetailCard.setOrderId(order.getOrderId());
orderDetailCard.setParkCardId(Long.valueOf(cardBuyVO.getParkLotCardId()));
orderDetailCard.setCardType(parkCardCoupons.getGoodsType());
orderDetailCard.setCardTypeRemark(parkCardCoupons.getGoodsTypeRemark());
orderDetailCard.setBuyNum(Integer.valueOf(cardBuyVO.getBuyNum()));
orderDetailCard.setCardAmount(parkCardCoupons.getGoodsAmount());
orderDetailCard.setEffDate(format.parse(cardBuyVO.getStartDate())); //卡的开始日期
orderDetailCard.setExpDate(format.parse(cardBuyVO.getEndDate())); //卡的结束日期
orderDetailCard.setOrderDetailType(cardBuyVO.getOrderDetailType());
orderDetailCard.setRemark("微信公众号购买卡");
orderDetailCard.setCreateDate(new Date());
insertDetailFlg = orderDetailCard.save();
}
}catch (Exception e) {
e.printStackTrace();
}
return (insertFlg == insertDetailFlg == true) ? order.getOrderId() : "";
}
/**
* 查询待支付的订单信息.<br/>
* @param orderId
* @return
*/
public CardOrderVO queryNotPayCardOrder(String orderId){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
CardOrderVO cardOrderVO = new CardOrderVO();
StringBuffer sql = new StringBuffer("select a.order_id,a.park_id,a.car_number,a.order_not_pay_fee,a.order_title");
sql.append(" from td_b_order a ");
sql.append(" where 1=1 and a.order_state=2");
sql.append(" and a.order_id=?");
//1.查询订单
Order order = new Order().findFirst(sql.toString(), orderId);
//2.查询订单明细
StringBuffer sqlStr = new StringBuffer("select a.order_id,a.card_type,a.card_type_remark,a.buy_num,a.eff_date,a.exp_date");
sqlStr.append(" from td_b_order_detail_card a ");
sqlStr.append(" where 1=1 ");
sqlStr.append(" and a.order_id=?");
OrderDetailCard orderDetailCard = new OrderDetailCard().findFirst(sqlStr.toString(), orderId);
BizResult<ParkLotCardVO> result=null;
if(StringKit.isNotBlank(order.getParkId())){
//查询停车场id
ParkLotService parkLotService = Duang.duang(ParkLotService.class);
result = parkLotService.queryParkLotForpklNo(order.getParkId());
}
if(order != null && orderDetailCard != null ){
cardOrderVO.setOrderId(orderId);
cardOrderVO.setOrderType(orderDetailCard.getCardType());
cardOrderVO.setOrderTypeRemark(orderDetailCard.getCardTypeRemark());
cardOrderVO.setBuyNum(orderDetailCard.getBuyNum());
cardOrderVO.setStartDate(format.format(orderDetailCard.getEffDate()));
cardOrderVO.setEndDate(format.format(orderDetailCard.getExpDate()));
cardOrderVO.setCarNum(order.getCarNumber());
cardOrderVO.setTotleMoney(order.getOrderNotPayFee().toString());
if(result.getData() != null){
cardOrderVO.setParkName(result.getData().getParkName());
cardOrderVO.setParkaddress(result.getData().getAddress());
}
}
return cardOrderVO;
}
}