1
zj
2024-07-12 bc9801d6adf582325e8213df11f597f82deda973
src/main/java/project/admin/AdminFuturesOrderController.java
@@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@@ -21,9 +22,12 @@
import kernel.web.PageActionSupport;
import project.Constants;
import project.futures.AdminFuturesOrderService;
import project.futures.FuturesOrder;
import project.futures.FuturesOrderService;
import project.futures.FuturesRedisKeys;
import project.item.ItemService;
import project.item.model.Item;
import project.redis.RedisHandler;
/**
 * 交割合约单
@@ -31,264 +35,305 @@
@RestController
public class AdminFuturesOrderController extends PageActionSupport {
   @Autowired
   private ItemService itemService;
   @Autowired
   private FuturesOrderService futuresOrderService;
   @Autowired
   private AdminFuturesOrderService adminFuturesOrderService;
    @Autowired
    private ItemService itemService;
   private final String action = "normal/adminFuturesOrderAction!";
   private Logger logger = LoggerFactory.getLogger(AdminFuturesOrderController.class);
   /**
    * 获取 交割合约单 列表
    *
    * symbol_para 币种
    * direction_para 方向
    * volume_para 下单金额
    * symbol_map 上线币种
    */
   @RequestMapping(action + "list.action")
   public ModelAndView list(HttpServletRequest request) {
      String pageNoStr = request.getParameter("pageNo");
      String message = request.getParameter("message");
      String error = request.getParameter("error");
      String status_para = request.getParameter("status_para");
      String rolename_para = request.getParameter("rolename_para");
      String name_para = request.getParameter("name_para");
      String order_no_para = request.getParameter("order_no_para");
      String symbol_para = request.getParameter("symbol_para");
      String direction_para = request.getParameter("direction_para");
      String volume_para = request.getParameter("volume_para");
    @Autowired
    private FuturesOrderService futuresOrderService;
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.setViewName("futures_order_list");
      Map<String, String> symbol_map = new HashMap<String, String>();
    protected RedisHandler redisHandler;
      int pageNo=1;
      Page page=null;
      int pageSize=30;
      try {
         List<Item> items = this.itemService.cacheGetAll();
         for (Item item : items) {
            symbol_map.put(item.getSymbol(), item.getSymbol());
         }
         pageNo=checkAndSetPageNo(pageNoStr);
    @Autowired
    private AdminFuturesOrderService adminFuturesOrderService;
         Double volume_para_double = null;
         if (StringUtils.isNullOrEmpty(volume_para)) {
            volume_para_double = null;
         } else {
            if (!StringUtils.isDouble(volume_para)) {
               throw new BusinessException("下单金额不是浮点数");
            }
            if (Double.valueOf(volume_para).doubleValue() < 0) {
               throw new BusinessException("下单金额不能小于0");
            }
            volume_para_double = Double.valueOf(volume_para).doubleValue();
         }
         String loginPartyId = this.getLoginPartyId();
         page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, status_para,
               rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
    private final String action = "normal/adminFuturesOrderAction!";
         List<Map> list = page.getElements();
         for (int i = 0; i < list.size(); i++) {
            Map map = list.get(i);
            if (null == map.get("rolename")) {
               map.put("roleNameDesc", "");
            } else {
               String roleName = map.get("rolename").toString();
               map.put("roleNameDesc",Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
            }
         }
    private Logger logger = LoggerFactory.getLogger(AdminFuturesOrderController.class);
      } catch (BusinessException e) {
         modelAndView.addObject("error", e.getMessage());
         return modelAndView;
      } catch (Throwable t) {
         logger.error(" error ", t);
         modelAndView.addObject("error", "[ERROR] " + t.getMessage());
         return modelAndView;
      }
    /**
     * 获取 交割合约单 列表
     * <p>
     * symbol_para 币种
     * direction_para 方向
     * volume_para 下单金额
     * symbol_map 上线币种
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        String pageNoStr = request.getParameter("pageNo");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String status_para = request.getParameter("status_para");
        String rolename_para = request.getParameter("rolename_para");
        String name_para = request.getParameter("name_para");
        String order_no_para = request.getParameter("order_no_para");
        String symbol_para = request.getParameter("symbol_para");
        String direction_para = request.getParameter("direction_para");
        String volume_para = request.getParameter("volume_para");
      modelAndView.addObject("pageNo", pageNo);
      modelAndView.addObject("pageSize", pageSize);
      modelAndView.addObject("page", page);
      modelAndView.addObject("message", message);
      modelAndView.addObject("error", error);
      modelAndView.addObject("status_para", status_para);
      modelAndView.addObject("rolename_para", rolename_para);
      modelAndView.addObject("name_para", name_para);
      modelAndView.addObject("order_no_para", order_no_para);
      modelAndView.addObject("symbol_para", symbol_para);
      modelAndView.addObject("direction_para", direction_para);
      modelAndView.addObject("volume_para", volume_para);
      modelAndView.addObject("symbol_map", symbol_map);
      return modelAndView;
   }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("futures_order_list");
   /**
    * 获取 交割合约单 列表
    *
    * symbol_para 币种
    * direction_para 方向
    * volume_para 下单金额
    */
   @RequestMapping(action + "holdings_list.action")
   public ModelAndView holdings_list(HttpServletRequest request) {
      String pageNoStr = request.getParameter("pageNo");
      String message = request.getParameter("message");
      String error = request.getParameter("error");
      String rolename_para = request.getParameter("rolename_para");
      String name_para = request.getParameter("name_para");
      String order_no_para = request.getParameter("order_no_para");
      String symbol_para = request.getParameter("symbol_para");
      String direction_para = request.getParameter("direction_para");
      String volume_para = request.getParameter("volume_para");
        Map<String, String> symbol_map = new HashMap<String, String>();
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.setViewName("futures_holdings_list");
        int pageNo = 1;
        Page page = null;
        int pageSize = 30;
        try {
            List<Item> items = this.itemService.cacheGetAll();
            for (Item item : items) {
                symbol_map.put(item.getSymbol(), item.getSymbol());
            }
      int pageNo=1;
      int pageSize=30;
      try {
         pageNo=checkAndSetPageNo(pageNoStr);
         if (StringUtils.isNullOrEmpty(volume_para)) {
            throw new BusinessException("下单金额必填");
         }
         if (!StringUtils.isDouble(volume_para)) {
            throw new BusinessException("下单金额不是浮点数");
         }
         if (Double.valueOf(volume_para).doubleValue() <= 0) {
            throw new BusinessException("下单金额不能小于等于0");
         }
         double volume_para_double = Double.valueOf(volume_para).doubleValue();
         String loginPartyId = this.getLoginPartyId();
         page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, "submitted",
               rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
            pageNo = checkAndSetPageNo(pageNoStr);
         List<Map> list = page.getElements();
         for (int i = 0; i < list.size(); i++) {
            Map map = list.get(i);
            if (null == map.get("rolename")) {
               map.put("roleNameDesc", "");
            } else {
               String roleName = map.get("rolename").toString();
               map.put("roleNameDesc",
                     Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
            }
         }
            Double volume_para_double = null;
            if (StringUtils.isNullOrEmpty(volume_para)) {
                volume_para_double = null;
            } else {
                if (!StringUtils.isDouble(volume_para)) {
                    throw new BusinessException("下单金额不是浮点数");
                }
                if (Double.valueOf(volume_para).doubleValue() < 0) {
                    throw new BusinessException("下单金额不能小于0");
                }
      } catch (BusinessException e) {
         modelAndView.addObject("error", e.getMessage());
         return modelAndView;
      } catch (Throwable t) {
         logger.error(" error ", t);
         modelAndView.addObject("error", "[ERROR] " + t.getMessage());
         return modelAndView;
      }
                volume_para_double = Double.valueOf(volume_para).doubleValue();
            }
      modelAndView.addObject("pageNo",pageNo);
      modelAndView.addObject("pageSize",pageSize);
      modelAndView.addObject("page", page);
      modelAndView.addObject("message", message);
      modelAndView.addObject("error", error);
      modelAndView.addObject("rolename_para", rolename_para);
      modelAndView.addObject("name_para", name_para);
      modelAndView.addObject("order_no_para", order_no_para);
      modelAndView.addObject("symbol_para", symbol_para);
      modelAndView.addObject("direction_para", direction_para);
      modelAndView.addObject("volume_para", volume_para);
      return modelAndView;
   }
            String loginPartyId = this.getLoginPartyId();
            page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, status_para,
                    rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
   /**
    * ajax定时获取表
    *
    * symbol_para 币种
    * direction_para 方向
    * volume_para 下单金额
    */
   @RequestMapping(action + "getValue.action")
   public String getValue(HttpServletRequest request) {
      String pageNoStr = request.getParameter("pageNo");
      String rolename_para = request.getParameter("rolename_para");
      String name_para = request.getParameter("name_para");
      String order_no_para = request.getParameter("order_no_para");
      String symbol_para = request.getParameter("symbol_para");
      String direction_para = request.getParameter("direction_para");
      String volume_para = request.getParameter("volume_para");
      int pageNo=1;
      Page page=null;
      int pageSize=30;
      try {
         pageNo=checkAndSetPageNo(pageNoStr);
         if (StringUtils.isNullOrEmpty(volume_para)) {
            throw new BusinessException("下单金额必填");
         }
         if (!StringUtils.isDouble(volume_para)) {
            throw new BusinessException("下单金额不是浮点数");
         }
         if (Double.valueOf(volume_para).doubleValue() <= 0) {
            throw new BusinessException("下单金额不能小于等于0");
         }
         double volume_para_double = Double.valueOf(volume_para).doubleValue();
         String loginPartyId = this.getLoginPartyId();
         page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, "submitted",
               rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
            List<Map> list = page.getElements();
            for (int i = 0; i < list.size(); i++) {
                Map map = list.get(i);
                if (null == map.get("rolename")) {
                    map.put("roleNameDesc", "");
                } else {
                    String roleName = map.get("rolename").toString();
                    map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
                }
            }
      } catch (BusinessException e) {
         return JsonUtils.getJsonString(new ArrayList());
      } catch (Throwable t) {
         logger.error(" error ", t);
         return JsonUtils.getJsonString(new ArrayList());
      }
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
      return JsonUtils.getJsonString(page.getElements());
   }
        modelAndView.addObject("pageNo", pageNo);
        modelAndView.addObject("pageSize", pageSize);
        modelAndView.addObject("page", page);
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        modelAndView.addObject("status_para", status_para);
        modelAndView.addObject("rolename_para", rolename_para);
        modelAndView.addObject("name_para", name_para);
        modelAndView.addObject("order_no_para", order_no_para);
        modelAndView.addObject("symbol_para", symbol_para);
        modelAndView.addObject("direction_para", direction_para);
        modelAndView.addObject("volume_para", volume_para);
        modelAndView.addObject("symbol_map", symbol_map);
        return modelAndView;
    }
   /**
    * orderProfitLoss
    *
    * profit_loss 盈利还是亏损
    */
   @RequestMapping(action + "orderProfitLoss.action")
   public ModelAndView orderProfitLoss(HttpServletRequest request) {
      String order_no = request.getParameter("order_no");
      String profit_loss = request.getParameter("profit_loss");
    /**
     * 获取 交割合约单 列表
     * <p>
     * symbol_para 币种
     * direction_para 方向
     * volume_para 下单金额
     */
    @RequestMapping(action + "holdings_list.action")
    public ModelAndView holdings_list(HttpServletRequest request) {
        String pageNoStr = request.getParameter("pageNo");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String rolename_para = request.getParameter("rolename_para");
        String name_para = request.getParameter("name_para");
        String order_no_para = request.getParameter("order_no_para");
        String symbol_para = request.getParameter("symbol_para");
        String direction_para = request.getParameter("direction_para");
        String volume_para = request.getParameter("volume_para");
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.setViewName("redirect:/" + action + "list.action");
      try {
         String error = this.futuresOrderService.saveOrderPorfitOrLoss(order_no, profit_loss, this.getUsername_login());
         if (StringUtils.isNotEmpty(error)) {
            throw new BusinessException(error);
         }
      } catch (BusinessException e) {
         modelAndView.addObject("error", e.getMessage());
         return modelAndView;
      } catch (Throwable t) {
         logger.error(" error ", t);
         modelAndView.addObject("error", "[ERROR] " + t.getMessage());
         return modelAndView;
      }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("futures_holdings_list");
      modelAndView.addObject("message", "操作成功");
      return modelAndView;
   }
        int pageNo = 1;
        int pageSize = 30;
        try {
            pageNo = checkAndSetPageNo(pageNoStr);
            if (StringUtils.isNullOrEmpty(volume_para)) {
                throw new BusinessException("下单金额必填");
            }
            if (!StringUtils.isDouble(volume_para)) {
                throw new BusinessException("下单金额不是浮点数");
            }
            if (Double.valueOf(volume_para).doubleValue() <= 0) {
                throw new BusinessException("下单金额不能小于等于0");
            }
            double volume_para_double = Double.valueOf(volume_para).doubleValue();
            String loginPartyId = this.getLoginPartyId();
            page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, "submitted",
                    rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
            List<Map> list = page.getElements();
            for (int i = 0; i < list.size(); i++) {
                Map map = list.get(i);
                if (null == map.get("rolename")) {
                    map.put("roleNameDesc", "");
                } else {
                    String roleName = map.get("rolename").toString();
                    map.put("roleNameDesc",
                            Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
                }
            }
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
        modelAndView.addObject("pageNo", pageNo);
        modelAndView.addObject("pageSize", pageSize);
        modelAndView.addObject("page", page);
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        modelAndView.addObject("rolename_para", rolename_para);
        modelAndView.addObject("name_para", name_para);
        modelAndView.addObject("order_no_para", order_no_para);
        modelAndView.addObject("symbol_para", symbol_para);
        modelAndView.addObject("direction_para", direction_para);
        modelAndView.addObject("volume_para", volume_para);
        return modelAndView;
    }
    /**
     * ajax定时获取表
     * <p>
     * symbol_para 币种
     * direction_para 方向
     * volume_para 下单金额
     */
    @RequestMapping(action + "getValue.action")
    public String getValue(HttpServletRequest request) {
        String pageNoStr = request.getParameter("pageNo");
        String rolename_para = request.getParameter("rolename_para");
        String name_para = request.getParameter("name_para");
        String order_no_para = request.getParameter("order_no_para");
        String symbol_para = request.getParameter("symbol_para");
        String direction_para = request.getParameter("direction_para");
        String volume_para = request.getParameter("volume_para");
        int pageNo = 1;
        Page page = null;
        int pageSize = 30;
        try {
            pageNo = checkAndSetPageNo(pageNoStr);
            if (StringUtils.isNullOrEmpty(volume_para)) {
                throw new BusinessException("下单金额必填");
            }
            if (!StringUtils.isDouble(volume_para)) {
                throw new BusinessException("下单金额不是浮点数");
            }
            if (Double.valueOf(volume_para).doubleValue() <= 0) {
                throw new BusinessException("下单金额不能小于等于0");
            }
            double volume_para_double = Double.valueOf(volume_para).doubleValue();
            String loginPartyId = this.getLoginPartyId();
            page = this.adminFuturesOrderService.pagedQuery(pageNo, pageSize, "submitted",
                    rolename_para, loginPartyId, name_para, order_no_para, symbol_para, direction_para, volume_para_double);
        } catch (BusinessException e) {
            return JsonUtils.getJsonString(new ArrayList());
        } catch (Throwable t) {
            logger.error(" error ", t);
            return JsonUtils.getJsonString(new ArrayList());
        }
        return JsonUtils.getJsonString(page.getElements());
    }
    /**
     * orderProfitLoss
     * <p>
     * profit_loss 盈利还是亏损
     */
    @RequestMapping(action + "orderProfitLoss.action")
    public ModelAndView orderProfitLoss(HttpServletRequest request) {
        String order_no = request.getParameter("order_no");
        String profit_loss = request.getParameter("profit_loss");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/" + action + "list.action");
        try {
            String error = this.futuresOrderService.saveOrderPorfitOrLoss(order_no, profit_loss, this.getUsername_login());
            if (StringUtils.isNotEmpty(error)) {
                throw new BusinessException(error);
            }
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
        modelAndView.addObject("message", "操作成功");
        return modelAndView;
    }
    /**
     * 交割合约一键场控
     * <p>
     * profit_loss 盈利还是亏损
     */
    @RequestMapping(action + "orderProfitLossList.action")
    public ModelAndView orderProfitLossList(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/" + action + "list.action");
        String stringOrderNo = request.getParameter("orderNos");
        String action = request.getParameter("action");
        logger.info("orderNos:"+stringOrderNo.toString()+"-----action:"+action);
        String[] orderNos = stringOrderNo.split(",");
        List<String> errorList = new ArrayList<>();
        try {
            for (String orderNo : orderNos) {
                logger.info("------->"+orderNo);
                String error = this.futuresOrderService.saveOrderPorfitOrLoss(orderNo, action, this.getUsername_login());
                if (StringUtils.isNotEmpty(error)) {
                    error = "订单号:"+orderNo+",原因:"+error;
                    errorList.add(error);
                }
            }
            if(errorList.size() > 0){
                throw new BusinessException("部分订单操作失败:"+errorList.toString());
            }
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error("  error  ", t);
            modelAndView.addObject("error", "[ERROR]  " + t.getMessage());
            return modelAndView;
        }
        modelAndView.addObject("message", "操作成功");
        return modelAndView;
    }
}