package com.xkrs.microservice.controller; import com.xkrs.microservice.common.encapsulation.PromptMessageEnum; import com.xkrs.microservice.model.entity.ecology.RemoteEntity; import com.xkrs.microservice.model.vo.OrderVo; import com.xkrs.microservice.service.OrderService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Locale; import static com.xkrs.microservice.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.microservice.common.tool.TokenUtil.getTokenUserName; /** * @author dong * @date 2021/2/2 */ @RestController @RequestMapping("/order") public class OrderController { @Resource private OrderService orderService; @Value("${home.path}") private String homePath; /** * 增加订单 * @param idList * @return */ @RequestMapping(value = "/add", method = RequestMethod.POST) public String addOrder(@RequestBody List idList, @RequestHeader(value="Authorization") String token){ Locale locale = LocaleContextHolder.getLocale(); if (null == idList || idList.size() == 0){ return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "id不能为空", locale); } String username = getTokenUserName(token); return orderService.addOrder(username, idList); } /** * 查看订单 * @return */ @RequestMapping(value = "get", method = RequestMethod.GET) public String getOrder( @RequestHeader(value="Authorization") String token){ Locale locale = LocaleContextHolder.getLocale(); String userName = getTokenUserName(token); List orderVoList = orderService.selectAll(userName); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, orderVoList, locale); } /** * 删除订单 * @param idList * @return */ @RequestMapping(value = "/del", method = RequestMethod.POST) public String delOrder(@RequestBody List idList) { Locale locale = LocaleContextHolder.getLocale(); if (null != idList) { if (orderService.delOrder(idList)) { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "success", locale); } } return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "order can not save", locale); } /** * 下载链接 * @param idList * @return */ @RequestMapping(value = "/download/one", method = RequestMethod.POST) public String downloadOne(@RequestBody List idList) { Locale locale = LocaleContextHolder.getLocale(); if (null != idList) { List list = orderService.download(idList); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, list, locale); } return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "fail", locale); } /** * 批量下载 * @param idList * @param response * @param request */ @RequestMapping(value = "/download/many", method = RequestMethod.POST) public void downloadMany(@RequestBody List idList, HttpServletResponse response, HttpServletRequest request){ Locale locale = LocaleContextHolder.getLocale(); orderService.downloadMany(idList, response, request); } /** * 批量下载 ,将下载路径写入到txt中 * @param idList * @param response * @param request */ @RequestMapping(value = "/download/txt", method = RequestMethod.POST) public void downloadTxt(@RequestBody List idList, HttpServletResponse response, HttpServletRequest request) { Locale locale = LocaleContextHolder.getLocale(); orderService.downloadTxt(idList, response, request); } }