【九月打卡】第19天 多端全栈项目实战
标签:
SpringBoot
课程名称:多端全栈项目实战:商业级代驾全流程落地
课程章节: 华夏代驾全栈小程序实战
课程讲师: 神思者
课程内容:
前端实时上传gps定位
今天编写bff-cusomer子系统 上面是这个系统的时序图
然后是编写form类
@Data@Schema(description = "查询符合某个订单接单的司机列表的表单")public class SearchBefittingDriverAboutOrderForm { @NotBlank(message = "startPlaceLatitude不能为空") @Pattern(regexp = "^(([1-8]\\d?)|([1-8]\\d))(\\.\\d{1,18})|90|0(\\.\\d{1,18})?$", message = "startPlaceLatitude内容不正确") @Schema(description = "订单起点的纬度") private String startPlaceLatitude; @NotBlank(message = "startPlaceLongitude不能为空") @Pattern(regexp = "^(([1-9]\\d?)|(1[0-7]\\d))(\\.\\d{1,18})|180|0(\\.\\d{1,18})?$", message = "startPlaceLongitude内容不正确") @Schema(description = "订单起点的经度") private String startPlaceLongitude; @NotBlank(message = "endPlaceLatitude不能为空") @Pattern(regexp = "^(([1-8]\\d?)|([1-8]\\d))(\\.\\d{1,18})|90|0(\\.\\d{1,18})?$", message = "endPlaceLatitude内容不正确") @Schema(description = "订单终点的纬度") private String endPlaceLatitude; @NotBlank(message = "endPlaceLongitude不能为空") @Pattern(regexp = "^(([1-9]\\d?)|(1[0-7]\\d))(\\.\\d{1,18})|180|0(\\.\\d{1,18})?$", message = "endPlaceLongitude内容不正确") @Schema(description = "订单起点的经度") private String endPlaceLongitude; @NotBlank(message = "mileage不能为空") @Pattern(regexp = "^[1-9]\\d*\\.\\d+$|^0\\.\\d*[1-9]\\d*$|^[1-9]\\d*$", message = "mileage内容不正确") @Schema(description = "预估里程") private String mileage;}
然后是编写fegin 去调用 之前声明的api
@FeignClient(value = "hxds-mps")public interface MpsServiceApi { @PostMapping("/driver/location/searchBefittingDriverAboutOrder") public R searchBefittingDriverAboutOrder(SearchBefittingDriverAboutOrderForm form); }
接下来是编写service
创建一个form对象然后将接口中传过来的值 封装进去
SearchBefittingDriverAboutOrderForm form_3 = new SearchBefittingDriverAboutOrderForm(); form_3.setStartPlaceLatitude(startPlaceLatitude); form_3.setStartPlaceLongitude(startPlaceLongitude); form_3.setEndPlaceLatitude(endPlaceLatitude); form_3.setEndPlaceLongitude(endPlaceLongitude); form_3.setMileage(mileage); r = mpsServiceApi.searchBefittingDriverAboutOrder(form_3); ArrayList<HashMap> list = (ArrayList<HashMap>) r.get("result");
通过list 判断是否有符合条件的司机
如果有则插入订单
if (list.size() > 0) { /* * 生成订单记录 */ InsertOrderForm form_4 = new InsertOrderForm(); form_4.setUuid(IdUtil.simpleUUID()); form_4.setCustomerId(customerId); form_4.setStartPlace(startPlace); form_4.setStartPlaceLatitude(startPlaceLatitude); form_4.setStartPlaceLongitude(startPlaceLongitude); form_4.setEndPlace(endPlace); form_4.setEndPlaceLatitude(endPlaceLatitude); form_4.setEndPlaceLongitude(endPlaceLongitude); form_4.setExpectsMileage(mileage); form_4.setExpectsFee(expectsFee); form_4.setFavourFee(favourFee); form_4.setDate(new DateTime().toDateStr()); form_4.setChargeRuleId(Long.parseLong(chargeRuleId)); form_4.setCarPlate(form.getCarPlate()); form_4.setCarType(form.getCarType()); form_4.setBaseMileage(baseMileage); form_4.setBaseMileagePrice(baseMileagePrice); form_4.setExceedMileagePrice(exceedMileagePrice); form_4.setBaseMinute(baseMinute); form_4.setExceedMinutePrice(exceedMinutePrice); form_4.setBaseReturnMileage(baseReturnMileage); form_4.setExceedReturnPrice(exceedReturnPrice); r = odrServiceApi.insert(form_4); String orderId = MapUtil.getStr(r, "result"); //TODO 发送订单消息给相关的司机 result.put("orderId",orderId); result.replace("count",list.size()); } return result;
在controller里面需要做一下修改 原来返回的数据是int数据
现在返回的是一个hashmap 所以需要做以下修改
@RestController@RequestMapping("/order")@Tag(name = "OrderController", description = "订单模块Web接口")public class OrderController { @Resource private OrderService orderService; @PostMapping("/createNewOrder") @Operation(summary = "创建新订单") @SaCheckLogin public R createNewOrder(@RequestBody @Valid CreateNewOrderForm form){ long customerId = StpUtil.getLoginIdAsLong(); form.setCustomerId(customerId); HashMap result =orderService.createNewOrder(form); return R.ok().put("result",result); }}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦