118 lines
4.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Integer> 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<OrderVo> orderVoList = orderService.selectAll(userName);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, orderVoList, locale);
}
/**
* 删除订单
* @param idList
* @return
*/
@RequestMapping(value = "/del", method = RequestMethod.POST)
public String delOrder(@RequestBody List<Integer> 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<Integer> idList) {
Locale locale = LocaleContextHolder.getLocale();
if (null != idList) {
List<RemoteEntity> 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<Integer> 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<Integer> idList, HttpServletResponse response, HttpServletRequest request) {
Locale locale = LocaleContextHolder.getLocale();
orderService.downloadTxt(idList, response, request);
}
}