1
zj
2024-07-12 bc9801d6adf582325e8213df11f597f82deda973
1
9 files modified
717 ■■■■■ changed files
src/main/java/kernel/util/Arith.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/project/admin/AdminFuturesOrderController.java 525 ●●●● patch | view | raw | blame | history
src/main/java/project/contract/ContractOrder.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/project/contract/internal/ContractApplyOrderServiceImpl.java 48 ●●●● patch | view | raw | blame | history
src/main/java/project/contract/internal/ContractOrderServiceImpl.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/project/contract/job/ContractOrderCalculationServiceImpl.java 40 ●●●●● patch | view | raw | blame | history
src/main/java/project/project/web/api/ContractApplyOrderController.java 67 ●●●●● patch | view | raw | blame | history
src/main/java/project/web/admin/kyc/AdminKycController.java 3 ●●●● patch | view | raw | blame | history
src/main/webapp/kyc_list.jsp 2 ●●● patch | view | raw | blame | history
src/main/java/kernel/util/Arith.java
@@ -1,5 +1,7 @@
package kernel.util;
import kotlin.jvm.internal.MagicApiIntrinsics;
import java.math.BigDecimal;
public class Arith{
@@ -20,7 +22,7 @@
        BigDecimal b1 = new BigDecimal(Double.toString(v1));  
        BigDecimal b2 = new BigDecimal(Double.toString(v2));  
        return b1.add(b2).doubleValue();  
    }
    }
    /** 
     * 提供精确的减法运算。 
     * @param v1 被减数 
@@ -31,7 +33,7 @@
        BigDecimal b1 = new BigDecimal(Double.toString(v1));  
        BigDecimal b2 = new BigDecimal(Double.toString(v2));  
        return b1.subtract(b2).doubleValue();  
    }
    }
    /** 
     * 提供精确的乘法运算。 
     * @param v1 被乘数 
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;
    }
}
src/main/java/project/contract/ContractOrder.java
@@ -149,17 +149,7 @@
    private Double volume_open;
    public Double getChange_ratio() {
        if (STATE_SUBMITTED.equals(state)) {
            change_ratio = Arith.div(Arith.sub(Arith.add(Arith.add(amount_close, profit), deposit), deposit_open),
                    deposit_open);
        } else {
            change_ratio = Arith.div(Arith.sub(Arith.add(amount_close, deposit), deposit_open), deposit_open);
        }
        change_ratio = Arith.mul(change_ratio, 100);
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.valueOf(df.format(change_ratio));
        return change_ratio;
    }
    public Serializable getPartyId() {
src/main/java/project/contract/internal/ContractApplyOrderServiceImpl.java
@@ -93,30 +93,30 @@
            }
        }
        List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
                order.getSymbol(), order.getDirection());
        for (int i = 0; i < order_state0_list.size(); i++) {
            Double source_lever_rate = order.getLever_rate();
            source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
            Double target_lever_rate = order_state0_list.get(i).getLever_rate();
            target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
            if (source_lever_rate.compareTo(target_lever_rate) != 0) {
                throw new BusinessException("存在不同杠杆的持仓单");
            }
        }
        List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
                order.getSymbol(), "open", order.getDirection());
        for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
            Double source_lever_rate = order.getLever_rate();
            source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
            Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate();
            target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
            if (source_lever_rate.compareTo(target_lever_rate) != 0) {
                throw new BusinessException("存在不同杠杆的持仓单");
            }
        }
//        List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
//                order.getSymbol(), order.getDirection());
//        for (int i = 0; i < order_state0_list.size(); i++) {
//            Double source_lever_rate = order.getLever_rate();
//            source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
//
//            Double target_lever_rate = order_state0_list.get(i).getLever_rate();
//            target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
//            if (source_lever_rate.compareTo(target_lever_rate) != 0) {
//                throw new BusinessException("存在不同杠杆的持仓单");
//            }
//        }
//        List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
//                order.getSymbol(), "open", order.getDirection());
//        for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
//            Double source_lever_rate = order.getLever_rate();
//            source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
//
//            Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate();
//            target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
//            if (source_lever_rate.compareTo(target_lever_rate) != 0) {
//                throw new BusinessException("存在不同杠杆的持仓单");
//            }
//        }
        order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
        order.setUnit_amount(item.getUnit_amount());
src/main/java/project/contract/internal/ContractOrderServiceImpl.java
@@ -1,13 +1,8 @@
package project.contract.internal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
@@ -465,14 +460,15 @@
    }
    public Map<String, Object> bulidOne(ContractOrder order) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss  a", Locale.ENGLISH);
        DecimalFormat df = new DecimalFormat("#.##");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("order_no", order.getOrder_no());
        map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName());
        map.put("symbol", order.getSymbol());
        map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
        map.put("create_time", simpleDateFormat.format(order.getCreate_time()));
        if (order.getClose_time() != null) {
            map.put("close_time", DateUtils.format(order.getClose_time(), DateUtils.DF_yyyyMMddHHmmss));
            map.put("close_time", simpleDateFormat.format(order.getClose_time()));
        } else {
            map.put("close_time", "");
        }
src/main/java/project/contract/job/ContractOrderCalculationServiceImpl.java
@@ -1,5 +1,6 @@
package project.contract.job;
import java.text.DecimalFormat;
import java.util.List;
import org.slf4j.Logger;
@@ -21,6 +22,8 @@
    private ContractOrderService contractOrderService;
    private DataService dataService;
    private WalletService walletService;
    public final static String STATE_SUBMITTED = "submitted";
    public final static String STATE_CREATED = "created";
    /**
     * 平仓线 110%(订金价值 /收益=110%)
     */
@@ -53,6 +56,7 @@
                /*
                 * 0 买涨
                 */
                logger.info("当前价格:"+close+"---------价格:"+Arith.add(order.getTrade_avg_price(), order.getPips()));
                if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) {
                    settle(order, "profit", close);
                }
@@ -80,30 +84,31 @@
    /**
     * 盈亏计算
     *
     *
     * @param profit_loss  profit 盈 loss亏
     * @param currentPrice 当前点位
     */
    public void settle(ContractOrder order, String profit_loss, double currentPrice) {
        /**
         * 偏差点位
         */
        double point = Arith.div(Math.abs(Arith.sub(currentPrice, order.getTrade_avg_price())), order.getPips());
        /*
         * 根据偏 差点数和手数算出盈亏金额
         */
        double amount = Arith.mul(Arith.mul(order.getPips_amount(), point), order.getVolume());
        double mul = Arith.mul(order.getDeposit_open(), order.getLever_rate());//仓位
        double div = Arith.div(mul, order.getTrade_avg_price());//持有币的数量
        double amount = Arith.mul(div, Arith.sub(currentPrice, order.getTrade_avg_price()));
        logger.info("---------盈亏金额:"+amount);
        logger.info("---------盈亏:"+profit_loss);
        if ("profit".equals(profit_loss)) {
            /**
             * 盈 正数
             */
            order.setProfit(Arith.add(0.0D, amount));
            order.setProfit(Arith.add(0.0D, Math.abs(amount)));
        } else if ("loss".equals(profit_loss)) {
            order.setProfit(Arith.sub(0.0D, amount));
            order.setProfit(Arith.sub(0.0D,Math.abs(amount) ));
        }
        double changeRatio;
        changeRatio = Arith.mul(Arith.div(order.getProfit(), order.getDeposit_open()), 100);
        DecimalFormat df = new DecimalFormat("#.##");
        order.setChange_ratio(Double.valueOf(df.format(changeRatio)));
        /**
         * 多次平仓价格不对,后续修
         */
@@ -161,6 +166,7 @@
             * 收益
             */
            double profit = 0;
            List<ContractOrder> list = contractOrderService.findSubmitted(order.getPartyId().toString(), null, null);
            for (int i = 0; i < list.size(); i++) {
                ContractOrder close_line = list.get(i);
@@ -168,7 +174,7 @@
            }
            Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId().toString());
            double totleMoney = wallet.getMoney();
            if (Arith.add(profit, totleMoney) <= 0) {
            if (Arith.add(profit,totleMoney) <= 0) {
                /**
                 * 触发全仓强平
                 */
@@ -178,6 +184,7 @@
                    ContractOrder close_line = list.get(i);
                    if (!order.getOrder_no().equals(close_line.getOrder_no())) {
                        try {
                            while (true) {
                                if (ContractLock.add(close_line.getOrder_no())) {
                                    this.contractOrderService.saveClose(close_line.getPartyId().toString(),
@@ -188,7 +195,9 @@
                                    break;
                                }
                                ThreadUtils.sleep(500);
                            }
                        } catch (Exception e) {
                            logger.error("error:", e);
                        } finally {
@@ -207,8 +216,11 @@
                 * 低于系统默认平仓线,进行强平
                 */
                this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
                return;
            }
        }
    }
    public void setDataService(DataService dataService) {
        this.dataService = dataService;
src/main/java/project/project/web/api/ContractApplyOrderController.java
@@ -11,6 +11,7 @@
import javax.servlet.http.HttpServletRequest;
import kernel.web.ApplicationUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -323,6 +324,72 @@
    }
    /**
     * 修改止盈止损
     */
    @RequestMapping(action + "stopProfitAndLoss.action")
    public Object stopProfitAndLoss(HttpServletRequest request) throws IOException {
        String session_token = request.getParameter("session_token");
        String order_no = request.getParameter("order_no");
        String stop_price_profit = request.getParameter("stop_price_profit");
        String stop_price_loss = request.getParameter("stop_price_loss");
        ResultObject resultObject = new ResultObject();
        resultObject = this.readSecurityContextFromSession(resultObject);
        if (!"0".equals(resultObject.getCode())) {
            return resultObject;
        }
        String partyId = this.getLoginPartyId();
        boolean lock = false;
        try {
            if (!ContractLock.add(partyId)) {
                throw new BusinessException("请稍后再试");
            }
            lock = true;
            ContractOrder order = contractOrderService.findByOrderNo(order_no);
            if (order == null || !"submitted".equals(order.getState()) || !partyId.equals(order.getPartyId().toString())) {
                return resultObject;
            }
            if (StringUtils.isNullOrEmpty(stop_price_profit)) {
                stop_price_profit = "0";
            }
            if (StringUtils.isNullOrEmpty(stop_price_loss)) {
                stop_price_loss = "0";
            }
            double stop_price_profit_double = Double.valueOf(stop_price_profit).doubleValue();
            double stop_price_loss_double = Double.valueOf(stop_price_loss).doubleValue();
            Party party = this.partyService.cachePartyBy(partyId, false);
            if (!party.getEnabled()) {
                resultObject.setCode("506");
                resultObject.setMsg("用户已锁定");
                return resultObject;
            }
            order.setStop_price_profit(stop_price_profit_double);
            order.setStop_price_loss(stop_price_loss_double);
            this.contractOrderService.update(order);
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
        } finally {
            if (lock) {
                ThreadUtils.sleep(100);
                ContractLock.remove(partyId);
            }
        }
        return resultObject;
    }
    /**
     * 平仓
     * 
     * symbol 币种
src/main/java/project/web/admin/kyc/AdminKycController.java
@@ -54,8 +54,7 @@
            page = this.adminKycService.pagedQuery(pageNo, pageSize, name_para, state_para,
                    rolename_para, getLoginPartyId(), idnumber_para, email_para);
            String preImg = "https://www.coinzne.com/wap/public/showimg!showImg.action?imagePath=";
            String preImg = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath=";
            for (Map<String, Object> map : (List<Map<String, Object>>) page.getElements()) {
                map.put("name_encode", map.get("name").toString().replace("\'", "\\\'").replace("\"", "\\\""));
                map.put("nationality", Constants.COUNTRY_CODE.get(map.get("nationality")));
src/main/webapp/kyc_list.jsp
@@ -334,7 +334,7 @@
                                <button type="button" class="btn btn-light btn-block">修改</button>
                              </label>
                        </div>
                        <div class="col-md-6">
                        <div class="col-md-6">·
                            <button type="button" class="btn btn-light btn-block" onclick="submit_idimg('3')">提交</button>
                        </div>
                    </div>