/** 晒单录入操作 */
  @RequestMapping("/orderInput.json")
  @ResponseBody
  public JsonResult orderInput(
      Long dynamicId,
      Long userId,
      @RequestParam(value = "stockCode") String[] stockCodes,
      @RequestParam(value = "num") Long[] nums,
      @RequestParam(value = "tradeType") String[] tradeTypes,
      @RequestParam(value = "tradePrice") Double[] tradePrices,
      String auditDesc,
      Long parentGroupId,
      HttpServletRequest request) {
    // 查询晒单的动态记录
    UserDynamicInfo userDynamicInfo = userDynamicInfoService.findById(dynamicId);
    userDynamicInfo.setAuditDesc(auditDesc);

    List<Trade> trades = new ArrayList<Trade>();
    for (int i = 0; i < stockCodes.length; i++) {
      String stockCode = stockCodes[i];
      Trade trade = new Trade();
      trade.setUserId(userId);

      Stock stock = stockService.findByStockCode(stockCode);
      trade.setStockId(stock.getStockId());
      trade.setStockCode(stockCode);
      trade.setStockName(stock.getStockName());
      if (tradePrices != null && tradePrices.length > i) {
        trade.setTradePrice(tradePrices[i]);
      }
      if (nums != null && nums.length > i) {
        trade.setTradeNumber(nums[i]);
      }
      trade.setTurnoverAmount(
          MathUtil.mul(
              (trade.getTradePrice() == null ? 0 : trade.getTradePrice()), trade.getTradeNumber()));
      trade.setTradeType(tradeTypes[i]);
      trade.setIsRevoke(TradeIsRevokeEnum.N.getCode());
      trade.setTradeDate(userDynamicInfo.getCreateDate());
      trade.setTradeTime(userDynamicInfo.getCreateDate());
      Date currDate = new java.util.Date();
      trade.setCreateDate(currDate);
      trade.setUpdateDate(currDate);
      trade.setTradeDate(currDate);
      trade.setTradeTime(currDate);
      trade.setShareholderCode(stock.getStockCode());
      trades.add(trade);
    }
    // 添加晒单
    userDynamicInfoService.addOrder(userDynamicInfo, trades, userId, parentGroupId);

    // return jsonResultHelper.buildFailJsonResult(UserDynamicInfoResultCode.SIGN_ERROR);
    return jsonResultHelper.buildSuccessJsonResult(true);
  }
  /** 晒单作废操作 */
  @RequestMapping("/orderInputCancel.json")
  @ResponseBody
  public JsonResult orderInputCancel(Long dynamicId, String auditDesc) {
    // 查询晒单的动态记录
    UserDynamicInfo userDynamicInfo = userDynamicInfoService.findById(dynamicId);
    userDynamicInfo.setAuditDesc(auditDesc);

    // 将此条记录修改成审批通过
    userDynamicInfo.setAuditDate(new java.util.Date());
    userDynamicInfo.setAuditName(AuthUtil.getUserName());
    userDynamicInfo.setAuditStatus(UserDynamicInfoAuditStatusEnum.D.getCode());
    userDynamicInfo.setIsInput(UserDynamicInfoIsInputEnum.Y.getCode());
    userDynamicInfoService.update(userDynamicInfo);
    return jsonResultHelper.buildSuccessJsonResult(null);
  }
  /**
   * 晒单信息屏蔽
   *
   * @param dynamic_id
   * @return
   */
  @RequestMapping("/orderCancel.json")
  @ResponseBody
  public String orderCancel(Long dynamic_id, String auditDesc) {
    logger.info("晒单信息屏蔽: dynamic_id", dynamic_id);
    String status = "1";
    try {
      UserDynamicInfo userDynamicInfo = userDynamicInfoService.findById(dynamic_id);
      userDynamicInfo.setAuditStatus(UserDynamicInfoAuditStatusEnum.D.getCode());
      userDynamicInfo.setAuditDesc(auditDesc);
      userDynamicInfo.setAuditDate(new Date());
      Long userId = AuthUtil.getUserId();
      UUser user = uUserService.findById(userId);
      userDynamicInfo.setAuditName(user.getFullname());
      userDynamicInfoService.update(userDynamicInfo);
    } catch (Exception e) {
      e.printStackTrace();
      status = "2";
      logger.error("晒单信息屏蔽异常: dynamic_id=" + dynamic_id, e);
    }

    return status;
  }
  /** 晒单录入页面 */
  @RequestMapping("/orderInput.html")
  public String orderInput(Long dynamicId, Model model) {
    logger.info("晒单录入界面: {}", dynamicId);
    // 查询晒单的动态记录
    UserDynamicInfo userDynamicInfo = userDynamicInfoService.findById(dynamicId);
    // 查询用户信息
    User user = userService.findById(userDynamicInfo.getUserId());
    // 查询用户的持仓
    UserStockPosition userStockPositionParam = new UserStockPosition();
    userStockPositionParam.setUserId(user.getUserId());
    List<UserStockPosition> stockPositions = userStockPositionService.find(userStockPositionParam);

    String[] paths = userDynamicInfo.getImagePath().split(";");
    model.addAttribute("paths", paths);
    model.addAttribute("sail_web_url", sail_web_url);
    model.addAttribute("userDynamicInfo", userDynamicInfo);
    model.addAttribute("user", user);
    model.addAttribute("stockPositions", stockPositions);

    if (UserTypeEnum.getByCode(user.getType()).equals(UserTypeEnum.CATTLE)) {
      return "/dynamic/order/orderInput";
    } else {
      // 查询跟投的组合
      MyGroup voteGroup = myGroupService.findById(userDynamicInfo.getGroupId());
      // 查询组合的用户
      User voteGroupUser = userService.findById(voteGroup.getUserId());
      // 查询跟投的组合的股票明细
      List<Map<String, Object>> voteGroupDetails =
          myGroupDetailService.findAndCurrPrice(voteGroup.getGroupId());

      model.addAttribute("voteGroup", voteGroup);
      model.addAttribute("voteGroupUser", voteGroupUser);
      model.addAttribute("voteGroupDetails", voteGroupDetails);
      return "/dynamic/order/orderInputVote";
    }
  }