diff --git a/cweb/src/main/java/com/cweb/controller/order/BsOrderController.java b/cweb/src/main/java/com/cweb/controller/order/BsOrderController.java index b2cc766..5bb5ecc 100644 --- a/cweb/src/main/java/com/cweb/controller/order/BsOrderController.java +++ b/cweb/src/main/java/com/cweb/controller/order/BsOrderController.java @@ -1,6 +1,8 @@ package com.cweb.controller.order; import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -8,6 +10,7 @@ import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.BsMerchant; import com.hfkj.model.ResponseData; +import com.hfkj.model.UserSessionObject; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.service.BsMerchantService; @@ -22,6 +25,8 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; @Controller @RequestMapping(value = "/order") @@ -40,23 +45,36 @@ public class BsOrderController { @ApiOperation(value = "创建订单") public ResponseData create(@RequestBody OrderModel body) { try { + // 用户信息 + try { + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (userSession != null) { + body.setUserId(userSession.getUser().getId()); + body.setUserName(userSession.getUser().getUserName()); + body.setUserPhone(userSession.getUser().getPhone()); + } + } catch (Exception e) { + // 不做任何处理 + } + if (body == null || body.getOrderChildList().isEmpty()) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 子订单必填项校验 for (OrderChildModel orderChild : body.getOrderChildList()) { - if (orderChild.getProductType() == null || orderChild.getProductId() == null) { + if (orderChild.getProductType() == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } if (orderChild.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { if (orderChild.getProductPrice() == null || StringUtils.isBlank(orderChild.getGasOilNo()) || StringUtils.isBlank(orderChild.getGasGunNo()) + || StringUtils.isBlank(orderChild.getMerNo()) ) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 查询油站 - BsMerchant merchant = merchantService.getMerchant(orderChild.getProductId()); + BsMerchant merchant = merchantService.getMerchant(orderChild.getMerNo()); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油站"); } @@ -105,4 +123,5 @@ public class BsOrderController { } } + } diff --git a/cweb/src/main/java/com/cweb/controller/order/GasOrderController.java b/cweb/src/main/java/com/cweb/controller/order/GasOrderController.java new file mode 100644 index 0000000..f253883 --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/order/GasOrderController.java @@ -0,0 +1,76 @@ +package com.cweb.controller.order; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.model.ResponseData; +import com.hfkj.model.UserSessionObject; +import com.hfkj.service.gas.BsGasOrderService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value = "/gasOrder") +@Api(value = "加油订单业务") +public class GasOrderController { + private static Logger log = LoggerFactory.getLogger(GasOrderController.class); + @Resource + private UserCenter userCenter; + @Resource + private BsGasOrderService gasOrderService; + + @RequestMapping(value="/queryUserOilOrder",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询用户加油订单") + public ResponseData queryUserOilOrder(@RequestParam(name = "orderNo", required = false) String orderNo, + @RequestParam(name = "orderStatus", required = false) Integer orderStatus, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize) { + try { + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (userSession == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); + } + Map param = new HashMap<>(); + param.put("userId", userSession.getUser().getId()); + param.put("orderNo", orderNo); + param.put("orderStatus", orderStatus); + + PageHelper.startPage(pageNum,pageSize); + return ResponseMsgUtil.success(new PageInfo<>(gasOrderService.getGasOrderList(param))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryOilOrder",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询加油订单详情") + public ResponseData queryOilOrder(@RequestParam(name = "orderNo", required = true) String orderNo) { + try { + + return ResponseMsgUtil.success(gasOrderService.getDetailByOrderNo(orderNo)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + +} diff --git a/cweb/src/main/java/com/cweb/controller/order/OrderPayController.java b/cweb/src/main/java/com/cweb/controller/order/OrderPayController.java index 8b1d9e7..615c15b 100644 --- a/cweb/src/main/java/com/cweb/controller/order/OrderPayController.java +++ b/cweb/src/main/java/com/cweb/controller/order/OrderPayController.java @@ -72,6 +72,7 @@ public class OrderPayController { if (merPay == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户未配置支付"); } + order.setPayType(OrderPayTypeEnum.type1.getCode()); // 请求支付渠道 Map preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), body.getString("userId"), order); @@ -108,6 +109,7 @@ public class OrderPayController { if (merPay == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户未配置支付"); } + order.setPayType(OrderPayTypeEnum.type2.getCode()); // 请求支付渠道 Map preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), body.getString("userId"), order); diff --git a/service/src/main/java/com/hfkj/model/SecUserSessionObject.java b/service/src/main/java/com/hfkj/model/SecUserSessionObject.java index 75e1c39..c31ab56 100644 --- a/service/src/main/java/com/hfkj/model/SecUserSessionObject.java +++ b/service/src/main/java/com/hfkj/model/SecUserSessionObject.java @@ -1,5 +1,6 @@ package com.hfkj.model; +import com.hfkj.entity.BsMerchant; import com.hfkj.entity.SecMenu; import com.hfkj.entity.SecRole; import com.hfkj.entity.SecUser; @@ -23,6 +24,11 @@ public class SecUserSessionObject { */ private SecRole role; + /** + * 商户 + */ + private BsMerchant merchant; + /** * 菜单 */ @@ -33,9 +39,10 @@ public class SecUserSessionObject { */ private List button; - public SecUserSessionObject(SecUser account, SecRole role, List menuTree, List button){ + public SecUserSessionObject(SecUser account, SecRole role, BsMerchant merchant, List menuTree, List button){ this.account = account; this.role = role; + this.merchant = merchant; this.menuTree = menuTree; this.button = button; } diff --git a/service/src/main/java/com/hfkj/model/order/OrderChildModel.java b/service/src/main/java/com/hfkj/model/order/OrderChildModel.java index ccca8f8..8682a41 100644 --- a/service/src/main/java/com/hfkj/model/order/OrderChildModel.java +++ b/service/src/main/java/com/hfkj/model/order/OrderChildModel.java @@ -11,7 +11,10 @@ import lombok.Data; **/ @Data public class OrderChildModel extends BsOrderChild { - + /** + * 油站编号 + */ + private String merNo; /** * 油站加油员 */ diff --git a/service/src/main/java/com/hfkj/service/gas/impl/BsGasOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/gas/impl/BsGasOrderServiceImpl.java index 4f65c87..83a09fa 100644 --- a/service/src/main/java/com/hfkj/service/gas/impl/BsGasOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/gas/impl/BsGasOrderServiceImpl.java @@ -85,6 +85,10 @@ public class BsGasOrderServiceImpl implements BsGasOrderService { criteria.andOrderChildNoLike("%"+MapUtils.getString(param, "orderChildNo")+"%"); } + if (MapUtils.getLong(param, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(param, "userId")); + } + if (StringUtils.isNotBlank(MapUtils.getString(param, "userPhone"))) { criteria.andUserPhoneLike("%"+MapUtils.getString(param, "userPhone")+"%"); } diff --git a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java index 3f61333..1afb818 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java @@ -53,7 +53,7 @@ public class OrderCreateService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知油品类型"); } // 查询油站 - BsMerchant merchant = merchantService.getMerchant(orderChild.getProductId()); + BsMerchant merchant = merchantService.getMerchant(orderChild.getMerNo()); if (merchant == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油站"); } @@ -64,6 +64,7 @@ public class OrderCreateService { GasPayPriceModel priceModel = gasService.refuelPriceCompute(orderChild.getProductPrice(), merchant.getMerNo(), orderChild.getGasOilNo(),false); BsGasOrder gasOrder = new BsGasOrder(); + gasOrder.setMerNo(merchant.getMerNo()); gasOrder.setChannelType(merchant.getSourceType()); gasOrder.setOrderNo(orderChild.getOrderNo()); gasOrder.setOrderChildNo(orderChild.getChildOrderNo()); @@ -121,6 +122,7 @@ public class OrderCreateService { gasOrderService.addGasOrder(gasOrder); + orderChild.setMerNo(merchant.getMerNo()); orderChild.setProductName(merchant.getMerName()); orderChild.setProductImg(merchant.getMerLogo()); orderChild.setProductSpecName("默认"); diff --git a/service/src/main/java/com/hfkj/service/sec/impl/SecUserServiceImpl.java b/service/src/main/java/com/hfkj/service/sec/impl/SecUserServiceImpl.java index 6b8633d..8b4468b 100644 --- a/service/src/main/java/com/hfkj/service/sec/impl/SecUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/sec/impl/SecUserServiceImpl.java @@ -8,12 +8,11 @@ import com.hfkj.common.security.SessionObject; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.MD5Util; import com.hfkj.dao.SecUserMapper; -import com.hfkj.entity.SecMenu; -import com.hfkj.entity.SecRole; -import com.hfkj.entity.SecUser; -import com.hfkj.entity.SecUserExample; +import com.hfkj.entity.*; import com.hfkj.model.MenuTreeModel; import com.hfkj.model.SecUserSessionObject; +import com.hfkj.service.BsMerchantService; +import com.hfkj.service.gas.BsGasStaffService; import com.hfkj.service.sec.SecMenuService; import com.hfkj.service.sec.SecRoleService; import com.hfkj.service.sec.SecUserLoginLogService; @@ -51,6 +50,10 @@ public class SecUserServiceImpl implements SecUserService { private SecRoleService secRoleService; @Resource private SecMenuService secMenuService; + @Resource + private BsMerchantService merchantService; + @Resource + private BsGasStaffService gasStaffService; @Override public void editUser(SecUser data) { @@ -162,10 +165,23 @@ public class SecUserServiceImpl implements SecUserService { // 角色按钮 List button = secMenuService.queryRoleMenu(role.getId(), SecMenuTypeEnum.type2); + // 获取商户信息 + BsMerchant merchant = null; + if (user.getObjectType().equals(SecUserObjectTypeEnum.type2.getCode())){ + merchant = merchantService.getMerchant(user.getObjectId()); + } else if (user.getObjectType().equals(SecUserObjectTypeEnum.type3.getCode())){ + // 查询油站员工 + BsGasStaff gasStaff = gasStaffService.getStaffDetailById(user.getObjectId()); + if (gasStaff != null) { + merchant = merchantService.getMerchant(gasStaff.getMerId()); + } + } + + // token 生成格式:账户id + 时间戳 String token = AESEncodeUtil.aesEncrypt(user.getId()+"_"+System.currentTimeMillis(), "O8gTZ6wIovDPjhsaz0zAoqZmm3jtjIcO"); - SessionObject sessionObject = new SessionObject(token, new SecUserSessionObject(user, role, menuTree, button)); + SessionObject sessionObject = new SessionObject(token, new SecUserSessionObject(user, role, merchant, menuTree, button)); userCenter.save(sessionObject); // 异步记录登录信息