TaxiOrderController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package com.ruoyi.app.order;
  2. import java.math.BigDecimal;
  3. import java.text.SimpleDateFormat;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletResponse;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.core.metadata.IPage;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.ruoyi.app.utils.DateUtil;
  12. import com.ruoyi.common.annotation.Anonymous;
  13. import com.ruoyi.common.annotation.RepeatSubmit;
  14. import com.ruoyi.system.domain.PosOrder;
  15. import com.ruoyi.system.domain.RiderPosition;
  16. import com.ruoyi.system.mapper.TaxiOrderMapper;
  17. import com.ruoyi.system.service.IInfoUserService;
  18. import com.ruoyi.system.service.IRiderPositionService;
  19. import com.ruoyi.system.utils.Auth;
  20. import com.ruoyi.system.utils.JwtUtil;
  21. import io.swagger.models.auth.In;
  22. import lombok.SneakyThrows;
  23. import org.springframework.security.access.prepost.PreAuthorize;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.web.bind.annotation.*;
  26. import com.ruoyi.common.annotation.Log;
  27. import com.ruoyi.common.core.controller.BaseController;
  28. import com.ruoyi.common.core.domain.AjaxResult;
  29. import com.ruoyi.common.enums.BusinessType;
  30. import com.ruoyi.system.domain.TaxiOrder;
  31. import com.ruoyi.system.service.ITaxiOrderService;
  32. import com.ruoyi.common.utils.MessageUtils;
  33. import com.ruoyi.common.utils.poi.ExcelUtil;
  34. import com.ruoyi.common.core.page.TableDataInfo;
  35. /**
  36. * TaxiOrderController
  37. *
  38. * @author ruoyi
  39. * @date 2024-01-26
  40. */
  41. @RestController
  42. @RequestMapping("/system/txorder")
  43. public class TaxiOrderController extends BaseController
  44. {
  45. @Autowired
  46. private ITaxiOrderService taxiOrderService;
  47. @Autowired
  48. private TaxiOrderMapper taxiOrderMapper;
  49. @Autowired
  50. private IInfoUserService infoUserService;
  51. @Autowired
  52. private IRiderPositionService riderPositionService;
  53. //获取订单详情
  54. @Anonymous
  55. @GetMapping("/getTxorder")
  56. public AjaxResult getTxorder(@RequestParam Long id)
  57. {
  58. TaxiOrder order = taxiOrderService.getById(id);
  59. JSONObject org = new JSONObject();
  60. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  61. org.put("id",order.getId());
  62. org.put("ddId",order.getDdId());
  63. org.put("user",infoUserService.getById(order.getUserId()));
  64. org.put("driver",infoUserService.getById(order.getDriverId()));
  65. org.put("boardingAddress",order.getBoardingAddress());
  66. org.put("intoLongitude",order.getIntoLongitude());
  67. org.put("intoLatitude",order.getIntoLatitude());
  68. org.put("downAddress",order.getDownAddress());
  69. org.put("downLongitude",order.getDownLongitude());
  70. org.put("downLatitude",order.getIntoLatitude());
  71. org.put("distance",order.getDistance());
  72. org.put("state",order.getState());
  73. org.put("taxiType",order.getTaxiType());
  74. org.put("releaseId",order.getReleaseId());
  75. org.put("orderTime",sdf.format(order.getOrderTime()));
  76. org.put("boardingTime",order.getBoardingTime());
  77. org.put("alightingTime",order.getAlightingTime());
  78. org.put("appointmentTime",order.getAppointmentTime());
  79. org.put("fare",order.getFare());
  80. org.put("highwayCosts",order.getHighwayCosts());
  81. org.put("amount",order.getAmount());
  82. org.put("estimatedDuration",order.getEstimatedDuration());
  83. org.put("notes",order.getNotes());
  84. org.put("coupon",order.getCoupon());
  85. QueryWrapper<RiderPosition> query= new QueryWrapper<>();
  86. query.eq("rider_id",order.getDriverId());
  87. org.put("RiderPosition",order.getDriverId()==null||order.getDriverId().equals("")?null:riderPositionService.getOne(query));
  88. return success(org);
  89. }
  90. //获取用户订单
  91. @Anonymous
  92. @Auth
  93. @GetMapping("/getUsTxorder")
  94. public AjaxResult getUsTxorder(@RequestHeader String token,
  95. @RequestParam Integer page,
  96. @RequestParam Integer size,
  97. @RequestParam String type,
  98. @RequestParam(defaultValue = "") String state)
  99. {
  100. JwtUtil jwtUtil = new JwtUtil();
  101. String id = jwtUtil.getusid(token);
  102. IPage<TaxiOrder> palist = new Page<>(page, size);
  103. QueryWrapper<TaxiOrder> queryWrapper= new QueryWrapper<>();
  104. queryWrapper.select().orderByDesc("order_time");
  105. if(type.equals("0")){
  106. queryWrapper.eq("user_id",id);
  107. }else {
  108. queryWrapper.eq("driver_id",id);
  109. }
  110. if(!"".equals(state)){
  111. queryWrapper.eq("state",state);
  112. }
  113. IPage<TaxiOrder> list = taxiOrderService.page(palist,queryWrapper);
  114. List<TaxiOrder> orlist = list.getRecords();
  115. JSONArray arr = new JSONArray();
  116. for(int i=0;i<orlist.size();i++){
  117. JSONObject org = new JSONObject();
  118. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  119. org.put("id",orlist.get(i).getId());
  120. org.put("ddId",orlist.get(i).getDdId());
  121. org.put("user",infoUserService.getById(orlist.get(i).getUserId()));
  122. org.put("driver",infoUserService.getById(orlist.get(i).getDriverId()));
  123. org.put("boardingAddress",orlist.get(i).getBoardingAddress());
  124. org.put("intoLongitude",orlist.get(i).getIntoLongitude());
  125. org.put("intoLatitude",orlist.get(i).getIntoLatitude());
  126. org.put("downAddress",orlist.get(i).getDownAddress());
  127. org.put("downLongitude",orlist.get(i).getDownLongitude());
  128. org.put("downLatitude",orlist.get(i).getIntoLatitude());
  129. org.put("distance",orlist.get(i).getDistance());
  130. org.put("state",orlist.get(i).getState());
  131. org.put("taxiType",orlist.get(i).getTaxiType());
  132. org.put("releaseId",orlist.get(i).getReleaseId());
  133. org.put("orderTime",sdf.format(orlist.get(i).getOrderTime()));
  134. org.put("boardingTime",orlist.get(i).getBoardingTime());
  135. org.put("alightingTime",orlist.get(i).getAlightingTime());
  136. org.put("appointmentTime",orlist.get(i).getAppointmentTime());
  137. org.put("fare",orlist.get(i).getFare());
  138. org.put("highwayCosts",orlist.get(i).getHighwayCosts());
  139. org.put("amount",orlist.get(i).getAmount());
  140. org.put("estimatedDuration",orlist.get(i).getEstimatedDuration());
  141. org.put("notes",orlist.get(i).getNotes());
  142. org.put("coupon",orlist.get(i).getCoupon());
  143. arr.add(org);
  144. }
  145. return success(arr);
  146. }
  147. //获取附近可接订单
  148. @Anonymous
  149. @GetMapping("/getFjorder")
  150. public AjaxResult getFjorder(@RequestParam BigDecimal longitude,
  151. @RequestParam BigDecimal latitude,
  152. @RequestParam Integer page,
  153. @RequestParam Integer juli)
  154. {
  155. List<TaxiOrder> list = taxiOrderMapper.getfjorder(longitude,latitude,(page-1)*20,juli);
  156. JSONArray arr = new JSONArray();
  157. for(int i=0;i<list.size();i++){
  158. JSONObject org = new JSONObject();
  159. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  160. org.put("id",list.get(i).getId());
  161. org.put("ddId",list.get(i).getDdId());
  162. org.put("user",infoUserService.getById(list.get(i).getUserId()));
  163. org.put("driver",infoUserService.getById(list.get(i).getDriverId()));
  164. org.put("boardingAddress",list.get(i).getBoardingAddress());
  165. org.put("intoLongitude",list.get(i).getIntoLongitude());
  166. org.put("intoLatitude",list.get(i).getIntoLatitude());
  167. org.put("downAddress",list.get(i).getDownAddress());
  168. org.put("downLongitude",list.get(i).getDownLongitude());
  169. org.put("downLatitude",list.get(i).getIntoLatitude());
  170. org.put("distance",list.get(i).getDistance());
  171. org.put("state",list.get(i).getState());
  172. org.put("taxiType",list.get(i).getTaxiType());
  173. org.put("releaseId",list.get(i).getReleaseId());
  174. org.put("orderTime",sdf.format(list.get(i).getOrderTime()));
  175. org.put("boardingTime",list.get(i).getBoardingTime());
  176. org.put("alightingTime",list.get(i).getAlightingTime());
  177. org.put("appointmentTime",list.get(i).getAppointmentTime());
  178. org.put("fare",list.get(i).getFare());
  179. org.put("highwayCosts",list.get(i).getHighwayCosts());
  180. org.put("amount",list.get(i).getAmount());
  181. org.put("estimatedDuration",list.get(i).getEstimatedDuration());
  182. org.put("notes",list.get(i).getNotes());
  183. org.put("coupon",list.get(i).getCoupon());
  184. arr.add(org);
  185. }
  186. return success(MessageUtils.message("no.obtained.success"), arr);
  187. }
  188. //修改订单
  189. @Anonymous
  190. @RepeatSubmit(interval = 1000, message = "请求过于频繁")
  191. @PostMapping("/SetTxorder")
  192. public AjaxResult SetTxorder(@RequestBody TaxiOrder taxiOrder)
  193. {
  194. TaxiOrder order = taxiOrderService.getById(taxiOrder.getId());
  195. if(order==null){
  196. return error(MessageUtils.message("no.order.not.exist"));
  197. }else {
  198. boolean org = taxiOrderService.saveOrUpdate(taxiOrder);
  199. if(org){
  200. return success(MessageUtils.message("no.modify.success"));
  201. }else {
  202. return error();
  203. }
  204. }
  205. }
  206. //新增订单
  207. @SneakyThrows
  208. @Anonymous
  209. @Auth
  210. @RepeatSubmit(interval = 1000, message = "请求过于频繁")
  211. @PostMapping("/addTxorder")
  212. public AjaxResult addTxorder(@RequestHeader String token ,@RequestBody TaxiOrder taxiOrder)
  213. {
  214. JwtUtil jwtUtil = new JwtUtil();
  215. String id = jwtUtil.getusid(token);
  216. DateUtil date = new DateUtil();
  217. taxiOrder.setUserId(Long.valueOf(id));
  218. taxiOrder.setReleaseId(Long.valueOf(id));
  219. taxiOrder.setDdId(date.getTimeMillis().toString());
  220. int org = taxiOrderService.insertTaxiOrder(taxiOrder);
  221. if(org==1){
  222. return success(MessageUtils.message("no.order.place.success"), taxiOrder);
  223. }else {
  224. return error();
  225. }
  226. }
  227. /**
  228. * 查询TaxiOrder列表
  229. */
  230. @PreAuthorize("@ss.hasPermi('system:txorder:list')")
  231. @GetMapping("/list")
  232. public TableDataInfo list(TaxiOrder taxiOrder)
  233. {
  234. startPage();
  235. List<TaxiOrder> list = taxiOrderService.selectTaxiOrderList(taxiOrder);
  236. return getDataTable(list);
  237. }
  238. /**
  239. * 导出TaxiOrder列表
  240. */
  241. @PreAuthorize("@ss.hasPermi('system:txorder:export')")
  242. @Log(title = "TaxiOrder", businessType = BusinessType.EXPORT)
  243. @PostMapping("/export")
  244. public void export(HttpServletResponse response, TaxiOrder taxiOrder)
  245. {
  246. List<TaxiOrder> list = taxiOrderService.selectTaxiOrderList(taxiOrder);
  247. ExcelUtil<TaxiOrder> util = new ExcelUtil<TaxiOrder>(TaxiOrder.class);
  248. util.exportExcel(response, list, MessageUtils.message("no.export.excel.taxiorder"));
  249. }
  250. /**
  251. * 获取TaxiOrder详细信息
  252. */
  253. @PreAuthorize("@ss.hasPermi('system:txorder:query')")
  254. @GetMapping(value = "/{id}")
  255. public AjaxResult getInfo(@PathVariable("id") Long id)
  256. {
  257. return success(taxiOrderService.selectTaxiOrderById(id));
  258. }
  259. /**
  260. * 新增TaxiOrder
  261. */
  262. @PreAuthorize("@ss.hasPermi('system:txorder:add')")
  263. @Log(title = "TaxiOrder", businessType = BusinessType.INSERT)
  264. @PostMapping
  265. public AjaxResult add(@RequestBody TaxiOrder taxiOrder)
  266. {
  267. return toAjax(taxiOrderService.insertTaxiOrder(taxiOrder));
  268. }
  269. /**
  270. * 修改TaxiOrder
  271. */
  272. @PreAuthorize("@ss.hasPermi('system:txorder:edit')")
  273. @Log(title = "TaxiOrder", businessType = BusinessType.UPDATE)
  274. @PutMapping
  275. public AjaxResult edit(@RequestBody TaxiOrder taxiOrder)
  276. {
  277. return toAjax(taxiOrderService.updateTaxiOrder(taxiOrder));
  278. }
  279. /**
  280. * 删除TaxiOrder
  281. */
  282. @PreAuthorize("@ss.hasPermi('system:txorder:remove')")
  283. @Log(title = "TaxiOrder", businessType = BusinessType.DELETE)
  284. @DeleteMapping("/{ids}")
  285. public AjaxResult remove(@PathVariable Long[] ids)
  286. {
  287. return toAjax(taxiOrderService.deleteTaxiOrderByIds(ids));
  288. }
  289. }