zyy
2025-07-18 c8b031a405ebd2b450f5098bb37e5e63390f364c
新增贷款,优化
44 files modified
1 files added
1811 ■■■■■ changed files
src/main/java/com/nq/common/ServerResponse.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/StockInkApiController.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/UserPositionCheckDzController.java 66 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/backend/AdminController.java 42 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/backend/AdminStockAiController.java 15 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/dk/DkController.java 43 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/echo/EChoController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/dao/DkMapper.java 5 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/dao/StockMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/enums/EUserAssets.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/DkModel.java 87 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/StockAI.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/StockAIOrder.java 5 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/StockAIOrderPosition.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/User.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/UserPosition.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/IDkServices.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/IStockService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/IUserAssetsServices.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/IUserPositionService.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/AgentUserServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/ApplyLeverServicesimpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/DkServices.java 234 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/FundsAppendServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/FundsApplyServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/MandatoryLiquidationService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/PayServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/StockAiServiceImpl.java 73 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/StockServiceImpl.java 27 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserAssetsServices.java 28 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserFundsPositionServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserFuturesPositionServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserIndexPositionServiceImpl.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java 607 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserRechargeServiceImpl.java 58 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserServiceImpl.java 127 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java 78 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/utils/timeutil/DateTimeUtil.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/vo/dk/DkModelVo.java 84 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/vo/stock/StockVOQuery.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/vo/user/UserInfoVO.java 6 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/DkMapper.xml 56 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/StockMapper.xml 5 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/UserMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/common/ServerResponse.java
@@ -111,4 +111,9 @@
    public static <T> ServerResponse<T> createByErrorCodeMsg(int errorcode, String errormsg) {
        return new ServerResponse(errorcode, errormsg);
    }
    public static <T> ServerResponse<T> createByErrorCodeMsg(int errorcode, String errormsg, HttpServletRequest request) {
        return new ServerResponse(errorcode, new GoogleTranslateUtil().translate(errormsg,request.getHeader(LANG)));
        //return new ServerResponse(errorcode, errormsg,  request);
    }
}
src/main/java/com/nq/controller/StockInkApiController.java
@@ -48,18 +48,18 @@
    public ServerResponse buyStockAi(@RequestParam(value = "id") Long id,
                                     @RequestParam(value = "buyNum") BigDecimal buyNum, HttpServletRequest request) {
        if (buyNum.compareTo(BigDecimal.ZERO) <= 0) {
            return ServerResponse.createByErrorMsg("购买金额不能小于0");
            return ServerResponse.createByErrorMsg("购买金额不能小于0", request);
        }
        buyLock.lock();
        try {
            if (buyOrderCreated.get()) {
                return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试");
                return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试", request);
            }
            buyOrderCreated.set(true);
            return stockAiService.buyStockAi(id, buyNum, request);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMsg("订单异常,请稍后重试");
            return ServerResponse.createByErrorMsg("订单异常,请稍后重试", request);
        }  finally{
            buyLock.unlock();
            buyOrderCreated.set(false);
src/main/java/com/nq/controller/UserPositionCheckDzController.java
@@ -10,6 +10,7 @@
import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
import com.nq.service.IPriceServices;
import com.nq.service.IUserPositionService;
import com.nq.service.IUserService;
import com.nq.service.UserPositionCheckDzService;
import com.nq.service.impl.UserAssetsServices;
@@ -36,22 +37,7 @@
    UserPositionCheckDzService service;
    @Autowired
    UserPositionCheckDzMapper mapper;
    @Autowired
    UserPositionMapper userPositionMapper;
    @Autowired
    UserAssetsServices userAssetsServices;
    @Autowired
    UserMapper userMapper;
    @Autowired
    IPriceServices priceServices;
    @Autowired
    StockDzMapper stockDzMapper;
    IUserPositionService userPositionService;
    //大宗交易审核列表
    @RequestMapping({"getList.do"})
@@ -87,52 +73,10 @@
    @ResponseBody
    public ServerResponse check(@RequestParam(value = "id") Integer id,
                                @RequestParam(value = "checkType") Integer checkType,
                                @RequestParam(value = "orderNum") Integer orderNum) {
                                @RequestParam(value = "orderNum") Integer orderNum, HttpServletRequest request) {
        if(checkType != 2 && (id == null || checkType == null || orderNum == null)){
            return ServerResponse.createByErrorMsg("参数不能为空");
            return ServerResponse.createByErrorMsg("参数不能为空", request);
        }
        UserPositionCheckDz userPositionCheckDz = service.getById(id);
        if(userPositionCheckDz == null){
            return ServerResponse.createByErrorMsg("订单不存在");
        }
        if(userPositionCheckDz.getCheckType() != 0){
            return ServerResponse.createByErrorMsg("订单已审核");
        }
        if(checkType == 2){
            userPositionCheckDz.setCheckType(checkType);
            service.updateById(userPositionCheckDz);
            return ServerResponse.createBySuccess("审核成功");
        }
        User user = userMapper.selectById(userPositionCheckDz.getUserId());
        StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId()));
        UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stockDz.getStockType(), user.getId());
        if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
            return ServerResponse.createByErrorMsg("用户账户有待补资金未补齐,审核失败");
        }
        BigDecimal nowPrice = stockDz.getNowPrice();
        if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
            return ServerResponse.createByErrorMsg("股票价格0,请重试");
        }
        userPositionCheckDz.setOrderNum(orderNum);
        userPositionCheckDz.setOrderTotalPrice(nowPrice.multiply(new BigDecimal(orderNum.intValue())));
        BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(userPositionCheckDz.getOrderNum()));
        BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
        BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
        if (buyAmt.compareTo(availableBalance) > 0) {
            return ServerResponse.createByErrorMsg("订单失败,配资不足");
        }
        userPositionCheckDz.setCheckType(checkType);
        service.updateById(userPositionCheckDz);
        UserPosition userPosition = Convert.convert(UserPosition.class, userPositionCheckDz);
        userPosition.setBuyOrderPrice(nowPrice);
        userPosition.setId(null);
        userPosition.setDzId(stockDz.getId());
        userPositionMapper.insert(userPosition);
        userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"","");
        return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓");
        return userPositionService.checkDz(id, checkType, orderNum ,request);
    }
}
src/main/java/com/nq/controller/backend/AdminController.java
@@ -13,6 +13,7 @@
import com.nq.utils.PropertiesUtil;
import java.math.BigDecimal;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -177,31 +178,40 @@
    }
    /**
     * 后台贷款列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("queryDk.do")
    @ResponseBody
    public ServerResponse queryDk() {
        return ServerResponse.createBySuccess(this.iDkServices.queryDk());
    public ServerResponse queryDk(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
        return iDkServices.queryDk(pageNum, pageSize);
    }
    /**
     * 审核
     * @param dkId    id
     * @param spMoney 审核金额
     * @param state   状态
     * @param message 提示
     * @return
     */
    @RequestMapping("dksp.do")
    @ResponseBody
    public ServerResponse dksp(@RequestParam("dkId") Integer dkid,
                               @RequestParam("spMoney") Integer spMoney,
    public ServerResponse dksp(@RequestParam("dkId") Integer dkId,
                               @RequestParam(value = "spMoney", required = false) BigDecimal spMoney,
                               @RequestParam("state") Integer state,
                               @RequestParam("dkMessage") String message) {
        if (iDkServices.dksp(spMoney, message,state, dkid)) {
            return ServerResponse.createByErrorMsg("Successed");
        } else {
            return ServerResponse.createByErrorMsg("Fail");
                               @RequestParam(value = "message", required = false) String message) {
        if (state == 1) { //通过
            if (spMoney == null) {
                return ServerResponse.createByErrorMsg("输入审核金额");
            }
        }
        return iDkServices.dkSp(spMoney, message,state, dkId);
    }
    @RequestMapping("addDkjg.do")
    @ResponseBody
src/main/java/com/nq/controller/backend/AdminStockAiController.java
@@ -4,6 +4,7 @@
 import com.nq.pojo.StockAI;
 import com.nq.pojo.StockAIOrderPosition;
 import com.nq.service.IStockAiService;
 import com.nq.service.IStockService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
@@ -17,6 +18,8 @@
     @Autowired
     IStockAiService stockAiService;
     @Autowired
     IStockService stockService;
     /**
      * 获取ai交易产品列表
      * @return
@@ -96,4 +99,16 @@
         return stockAiService.orderOperation(id, status);
     }
     /**
      * 根据条件查询股票code 名称 或 spell
      * @return
      */
     @PostMapping({"getStocksByKeyWords.do"})
     @ResponseBody
     public ServerResponse getStocksByKeyWords(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                               @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                               @RequestParam(value = "keyWords") String keyWords) {
         return stockService.getStocksByKeyWords(pageNum, pageSize, keyWords);
     }
 }
src/main/java/com/nq/controller/dk/DkController.java
@@ -5,12 +5,12 @@
import com.nq.service.IDkServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
@Controller
@RequestMapping("/api/dk")
@@ -27,27 +27,44 @@
        return ServerResponse.createBySuccess(iDkServices.queryAll());
    }
    /**
     * 申请贷款
     * @param dkMoney  贷款金额 必填
     * @param dkPhone
     * @param dkJgId
     * @param httpServletRequest
     * @return
     */
    @RequestMapping("/dk.do")
    @ResponseBody
    public ServerResponse addDk(@RequestParam("dkMoney") String dkMoney,
                                @RequestParam("dkPhone") String dkPhone,
                                @RequestParam("dkJgId")  String dkJgId,
    public ServerResponse addDk(@RequestParam("dkMoney") BigDecimal dkMoney,
                                @RequestParam(value = "dkPhone", required = false) String dkPhone,
                                @RequestParam(value = "dkJgId", required = false)  String dkJgId,
                                HttpServletRequest httpServletRequest) {
        if (iDkServices.addDk(dkMoney, dkPhone,dkJgId, httpServletRequest)) {
            return ServerResponse.createBySuccessMsg("Successed");
        } else {
            return ServerResponse.createByErrorMsg("Fail");
        }
        return iDkServices.addDk(dkMoney, dkPhone,dkJgId, httpServletRequest);
    }
    @RequestMapping("/queryByShUserId.do")
    @ResponseBody
    public ServerResponse queryByShUserId(HttpServletRequest httpServletRequest){
        return ServerResponse.createBySuccess(iDkServices.queryByShUserId(httpServletRequest));
    public ServerResponse queryByShUserId(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                          @RequestParam(value = "state") Integer state,
            HttpServletRequest httpServletRequest){
        return iDkServices.queryByShUserId(pageNum, pageSize, state, httpServletRequest);
    }
    /**
     * 还款
     * @param id    订单id
     * @param request
     * @return
     */
    @RequestMapping("/rtDk.do")
    @ResponseBody
    public ServerResponse rtDk(@RequestParam("id") Integer id,
                                HttpServletRequest request) {
        return iDkServices.rtDk(id, request);
    }
}
src/main/java/com/nq/controller/echo/EChoController.java
@@ -3,6 +3,7 @@
import com.nq.common.ServerResponse;
import com.nq.dao.EChoMapper;
import com.nq.dao.UserAssetsMapper;
import com.nq.enums.EStockType;
import com.nq.pojo.EChoBean;
import com.nq.pojo.User;
import com.nq.pojo.UserAssets;
@@ -62,7 +63,7 @@
            }
        }
        User user = this.iUserService.getCurrentRefreshUser(request);
        UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("MEX", user.getId());
        UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId());
        if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
            return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
        }
src/main/java/com/nq/dao/DkMapper.java
@@ -4,8 +4,10 @@
import com.nq.pojo.DkModel;
import com.nq.vo.dk.DkModelVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.List;
@Mapper
@@ -14,6 +16,7 @@
    List<DkModelVo>  queryDk();
    int countByUserIdAndRStatus(@Param("userId") String userId, @Param("rStatus") Integer rStatus);
    List<DkModelVo>  queryByShUserId(String  id);
    BigDecimal sumSpMoneyByUserIdAndRStatus(@Param("userId") String userId);
}
src/main/java/com/nq/dao/StockMapper.java
@@ -7,6 +7,7 @@
import com.nq.pojo.StockDz;
import com.nq.pojo.StockSetting;
import com.nq.vo.stock.StockVOQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
@@ -61,4 +62,5 @@
  List<StockDz> findStockTypeDz(@Param("orderBy") String orderBy, @Param("keyWords") String keyWords , @Param("formatDate") String formatDate);
  List<StockVOQuery> findStocksQuery(@Param("keyWords") String keyWords);
}
src/main/java/com/nq/enums/EUserAssets.java
@@ -20,7 +20,11 @@
    TOP_UP("TOP_UP","充值"),
    BUY_AI("BUY_AI","购买AI产品"),
    BUY_AI_REJECT("BUY_AI_REJECT","拒绝买入AI产品申请"),
    AI_SETTLEMENT("AI_SETTLEMENT","结算AI产品订单"),
    AI_SETTLEMENT("AI_SETTLEMENT","结算AI产品订单本金"),
    AI_SETTLEMENT_INT("AI_SETTLEMENT_INT","结算AI产品订单利息"),
    DK("DK","发放贷款"),
    RT_DK("RT_DK","归还贷款"),
    RT_DK_INT("RT_DK_INT","归还贷款利息"),
    ;
    private String  code;
src/main/java/com/nq/pojo/DkModel.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.data.annotation.Transient;
import org.springframework.format.annotation.DateTimeFormat;
@@ -11,102 +12,36 @@
import java.util.Date;
@TableName("dk")
@Data
public class DkModel {
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    //贷款金额
    private  String  dkMoney;
    //审核金额
    private String spMoney;
    private String dkUserId;
    //贷款状态:0 申请中  1 审批通过  2审核拒绝  3贷款发放成功
    private String dkState;
    //提示
    private String dkMessage;
    private String dkPhone;
    private String dkJgId;
    public String getDkJgId() {
        return dkJgId;
    }
    public void setDkJgId(String dkJgId) {
        this.dkJgId = dkJgId;
    }
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    public Integer getId() {
        return id;
    }
    //放款时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date loanTime;
    public void setId(Integer id) {
        this.id = id;
    }
    public String getDkMoney() {
        return dkMoney;
    }
    public void setDkMoney(String dkMoney) {
        this.dkMoney = dkMoney;
    }
    public String getSpMoney() {
        return spMoney;
    }
    public void setSpMoney(String spMoney) {
        this.spMoney = spMoney;
    }
    public String getDkUserId() {
        return dkUserId;
    }
    public void setDkUserId(String dkUserId) {
        this.dkUserId = dkUserId;
    }
    public String getDkState() {
        return dkState;
    }
    public void setDkState(String dkState) {
        this.dkState = dkState;
    }
    public String getDkMessage() {
        return dkMessage;
    }
    public void setDkMessage(String dkMessage) {
        this.dkMessage = dkMessage;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getDkPhone() {
        return dkPhone;
    }
    public void setDkPhone(String dkPhone) {
        this.dkPhone = dkPhone;
    }
    //还款状态:0未还款 1已还款
    private Integer dkRefundState;
}
src/main/java/com/nq/pojo/StockAI.java
@@ -20,7 +20,8 @@
public class StockAI {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO,value = "id")
    private Integer id;
    //股票类型
src/main/java/com/nq/pojo/StockAIOrder.java
@@ -1,5 +1,7 @@
package com.nq.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@@ -19,7 +21,8 @@
public class StockAIOrder {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO,value = "id")
    private Integer id;
    //用户id
src/main/java/com/nq/pojo/StockAIOrderPosition.java
@@ -1,5 +1,7 @@
package com.nq.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@@ -20,11 +22,12 @@
public class StockAIOrderPosition {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO,value = "id")
    private Integer id;
    //ai交易产品订单id
    private Long stockAiOrderId;
    private Integer stockAiOrderId;
    //建仓股票id
    private Integer stockId;
@@ -42,6 +45,7 @@
    /**
     * 建仓时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date creatDate;
    /**
src/main/java/com/nq/pojo/User.java
@@ -38,4 +38,10 @@
    private String lever;
    private String fundRatio;
    //信用分
    private Integer creditScore;
    //贷款额度
    private BigDecimal loanLimit;
}
src/main/java/com/nq/pojo/UserPosition.java
@@ -19,6 +19,7 @@
public class UserPosition implements Serializable {
    @TableId(type = IdType.AUTO,value = "id")
    private Integer id;
    //0正常股票 1新股 3大宗
    private Integer positionType;
    private String positionSn;
    private Integer userId;
src/main/java/com/nq/service/IDkServices.java
@@ -1,27 +1,31 @@
package com.nq.service;
import com.nq.common.ServerResponse;
import com.nq.pojo.DkJgBean;
import com.nq.pojo.DkModel;
import com.nq.vo.dk.DkModelVo;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
public interface IDkServices {
    boolean addDk(String dkMoney, String phone,String dkjgId ,HttpServletRequest request);
    ServerResponse addDk(BigDecimal dkMoney, String phone, String dkjgId , HttpServletRequest request);
    List<DkModelVo> queryDk();
    ServerResponse queryDk(int pageNum, int pageSize);
    boolean dksp(Integer shMoney,String message,Integer state,Integer dkId);
    ServerResponse dkSp(BigDecimal spMoney,String message,Integer state,Integer dkId);
    ServerResponse rtDk(Integer id, HttpServletRequest request);
    List<DkJgBean>  queryAll();
    List<DkModelVo> queryByShUserId(HttpServletRequest httpServletRequest);
    ServerResponse queryByShUserId(int pageNum, int pageSize, Integer state, HttpServletRequest httpServletRequest);
    int inserDkJG(String dkjgName);
src/main/java/com/nq/service/IStockService.java
@@ -124,4 +124,6 @@
   * @return
   */
  ServerResponse getIndicesAndKData(String pid, String stockType);
  ServerResponse getStocksByKeyWords(int pageNum, int pageSize, String keyWords);
}
src/main/java/com/nq/service/IUserAssetsServices.java
@@ -45,7 +45,7 @@
     * @param  desc   描述
     * @param   descType 购买类型  充值   持仓  平仓   提现
     * */
    Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType);
    Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType) throws Exception;
    /**
     * ai交易
@@ -56,7 +56,7 @@
     * @param buyAmount
     * @return
     */
    Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount);
    Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount) throws Exception;
    /**
     * 根据汇率转换金额
src/main/java/com/nq/service/IUserPositionService.java
@@ -6,6 +6,7 @@
import com.nq.vo.position.PositionProfitVO;
import com.nq.vo.position.PositionVO;
import com.nq.vo.position.UserPositionVO;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
import java.util.List;
@@ -89,4 +90,6 @@
  ServerResponse getDzOrderList(int pageNum, int pageSize, Integer status, HttpServletRequest request);
  ServerResponse getMyPositionProfitAndLose(HttpServletRequest request);
  ServerResponse checkDz(Integer id, Integer checkType, Integer orderNum, HttpServletRequest request);
}
src/main/java/com/nq/service/impl/AgentUserServiceImpl.java
@@ -462,7 +462,7 @@
    }
    /*代理账户扣款*/
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse updateAgentAmt(Integer agentId, Integer amt, Integer direction) {
        if (agentId == null || amt == null || direction == null) {
            return ServerResponse.createByErrorMsg("参数不能为空");
src/main/java/com/nq/service/impl/ApplyLeverServicesimpl.java
@@ -50,7 +50,7 @@
        }
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ServerResponse examineApplyLever(String  id,String states, HttpServletRequest request) {
        ApplyLever applyLever = applyLeverMapper.selectById(id);
src/main/java/com/nq/service/impl/DkServices.java
@@ -1,68 +1,210 @@
package com.nq.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.common.ResponseCode;
import com.nq.common.ServerResponse;
import com.nq.dao.DkJGMapper;
import com.nq.dao.DkMapper;
import com.nq.pojo.DkJgBean;
import com.nq.pojo.DkModel;
import com.nq.pojo.User;
import com.nq.dao.StockConfigMapper;
import com.nq.dao.UserMapper;
import com.nq.enums.EStockType;
import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
import com.nq.service.IDkServices;
import com.nq.service.IUserAssetsServices;
import com.nq.service.IUserService;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.vo.dk.DkModelVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class DkServices implements IDkServices {
    @Autowired
    DkMapper dkMapper;
    private static final Logger log = LoggerFactory.getLogger(DkServices.class);
    private final ConcurrentHashMap<Long, Object> locks = new ConcurrentHashMap<>();
    @Autowired
    DkMapper dkMapper;
    @Autowired
    DkJGMapper mapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    StockConfigMapper stockConfigMapper;
    @Autowired
    IUserService iUserService;
    @Autowired
    IUserAssetsServices iUserAssetsServices;
    /**
     * 申请贷款
     * @param dkMoney
     * @param phone
     * @param dkjgId
     * @param request
     * @return
     */
    @Override
    public boolean addDk(String dkMoney, String phone, String dkjgId, HttpServletRequest request) {
        User user = this.iUserService.getCurrentRefreshUser(request);
        if (user == null) {
            return false;
    public ServerResponse addDk(BigDecimal dkMoney, String phone, String dkjgId, HttpServletRequest request) {
        try {
            User user = this.iUserService.getCurrentRefreshUser(request);
            if (user == null) {
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", request);
            }
            if (user.getLoanLimit() == null || user.getLoanLimit().compareTo(BigDecimal.ZERO) <= 0) {
                System.out.println(user.getLoanLimit());
                return ServerResponse.createByErrorMsg("无贷款额度",request);
            }
            if (user.getLoanLimit().compareTo(dkMoney) < 0) {
                return ServerResponse.createByErrorMsg("最大贷款额度为:" + user.getLoanLimit() ,request);
            }
            String userId = String.valueOf(user.getId());
            //查询是否有未还款记录
            if (dkMapper.countByUserIdAndRStatus(userId, 0) > 0 ) {
                return ServerResponse.createByErrorMsg("已申请贷款,请勿重复申请!", request);
            }
            DkModel dkModel = new DkModel();
            dkModel.setDkUserId(userId);
            dkModel.setCreateTime(new Date());
            dkModel.setDkMoney(String.valueOf(dkMoney));
            dkModel.setDkState("0");
            dkModel.setDkRefundState(0);
            dkModel.setDkJgId(dkjgId);
            dkModel.setDkPhone(phone);
            dkMapper.insert(dkModel);
            return ServerResponse.createBySuccess("贷款申请成功", request);
        } catch (Exception e) {
            log.error("IDkServices addDk error", e);
        }
        DkModel dkModel = new DkModel();
        dkModel.setDkUserId(user.getId() + "");
        dkModel.setCreateTime(DateTimeUtil.strToDate(DateTimeUtil.dateToStr(new Date())));
        dkModel.setDkMoney(dkMoney);
        dkModel.setDkState("0");
        dkModel.setDkJgId(dkjgId);
        dkModel.setDkPhone(phone);
        dkMapper.insert(dkModel);
        return true;
        return ServerResponse.createByError();
    }
    @Override
    public List<DkModelVo> queryDk() {
        return dkMapper.queryDk();
    public ServerResponse queryDk(int pageNum, int pageSize) {
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<DkModelVo> dkModelVoList = dkMapper.queryDk();
            PageInfo<DkModelVo> pageInfo = new PageInfo<>(dkModelVoList);
            return ServerResponse.createBySuccess(pageInfo);
        } catch (Exception e) {
            log.error("IDkServices queryDk error", e);
        }
        return ServerResponse.createByError();
    }
    /**
     * 贷款审核
     * @param spMoney
     * @param message
     * @param state
     * @param dkId
     * @return
     */
    @Override
    public boolean dksp(Integer shMoney, String message, Integer state, Integer dkId) {
        DkModel dkModel = dkMapper.selectById(dkId);
        if (dkModel == null) {
            return false;
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse dkSp(BigDecimal spMoney, String message, Integer state, Integer dkId) {
        try {
            DkModel dkModel = dkMapper.selectById(dkId);
            if (dkModel == null) {
                return ServerResponse.createByErrorMsg("无贷款记录");
            }
            String userId = String.valueOf(dkModel.getDkUserId());
            Object lock = locks.computeIfAbsent(Long.valueOf(userId), k -> new Object());
            synchronized (lock){
                User user = userMapper.selectById(Integer.valueOf(userId));
                if (user == null) {
                    return ServerResponse.createByErrorMsg("无用户信息");
                }
                if (state == 1) { //通过
                    if (user.getLoanLimit() == null || user.getLoanLimit().compareTo(BigDecimal.ZERO) <= 0) {
                        return ServerResponse.createByErrorMsg("无贷款额度");
                    }
                    if (user.getLoanLimit().compareTo(spMoney) < 0) {
                        return ServerResponse.createByErrorMsg("审核金额超出贷款额度:" + user.getLoanLimit());
                    }
                    dkModel.setSpMoney(String.valueOf(spMoney));
                    dkModel.setLoanTime(new Date());
                    //扣除用户贷款
                    user.setLoanLimit(user.getLoanLimit().subtract(spMoney));
                    //发放贷款金额 墨西哥账户
                    iUserAssetsServices.aiAvailableBalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.DK, spMoney);
                    userMapper.updateById(user);
                } else if (state == 2) { //拒绝
                    dkModel.setDkMessage(message);
                }
                dkModel.setDkState(String.valueOf(state));
                dkMapper.updateById(dkModel);
                return ServerResponse.createBySuccess("贷款审核成功");
            }
        } catch (Exception e) {
            log.error("IDkServices dksp error", e);
        }
        dkModel.setDkMessage(message);
        dkModel.setDkState(state + "");
        dkModel.setSpMoney(shMoney + "");
        dkMapper.updateById(dkModel);
        return true;
        return ServerResponse.createByError();
    }
    /**
     * 还款
     * @param id
     * @param request
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse rtDk(Integer id, HttpServletRequest request) {
        try {
            DkModel dkModel = dkMapper.selectById(id);
            if (dkModel == null) {
                return ServerResponse.createByErrorMsg("无贷款记录", request);
            }
            if (!dkModel.getDkState().equals("1")) {
                return ServerResponse.createByErrorMsg("未审核通过记录不能还款", request);
            }
            String userId = String.valueOf(dkModel.getDkUserId());
            Object lock = locks.computeIfAbsent(Long.valueOf(userId), k -> new Object());
            synchronized (lock){
                User user = userMapper.selectById(Integer.valueOf(userId));
                if (user == null) {
                    return ServerResponse.createByErrorMsg("无用户信息", request);
                }
                UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId());
                //应该还款金额
                BigDecimal amount = new BigDecimal(dkModel.getSpMoney());
                if(userAssets.getAvailableBalance().compareTo(amount) < 0){
                    return ServerResponse.createByErrorMsg("可用余额不足:" +  userAssets.getAvailableBalance(), request);
                }
                dkModel.setDkRefundState(1);
                //查看贷款利息
                StockConfig stockConfig = stockConfigMapper.selectOne(new QueryWrapper<StockConfig>().eq("c_key", "loan_interest"));
                if (stockConfig != null) {
                    long day = DateTimeUtil.getDaysRoundedUp(dkModel.getLoanTime());
                    //利息 利率*贷款金额*借款天数
                    BigDecimal intAmount = new BigDecimal(stockConfig.getCValue()).multiply(amount).multiply(BigDecimal.valueOf(day));
                    iUserAssetsServices.aiAvailableBalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.RT_DK_INT, intAmount);
                }
                //还款
                iUserAssetsServices.aiAvailableBalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.RT_DK, amount);
                dkMapper.updateById(dkModel);
                return ServerResponse.createBySuccess("贷款审核成功", request);
            }
        } catch (Exception e) {
            log.error("IDkServices rtDk error", e);
        }
        return ServerResponse.createByError();
    }
    @Override
@@ -70,10 +212,32 @@
        return mapper.queryAll();
    }
    public List<DkModelVo> queryByShUserId(HttpServletRequest httpServletRequest) {
        User user = this.iUserService.getCurrentRefreshUser(httpServletRequest);
        return dkMapper.queryByShUserId(user.getId()+"");
    /**
     * 贷款记录
     * @param pageNum
     * @param pageSize
     * @param httpServletRequest
     * @return
     */
    @Override
    public ServerResponse queryByShUserId(int pageNum, int pageSize, Integer state, HttpServletRequest httpServletRequest) {
        try {
            User user = this.iUserService.getCurrentRefreshUser(httpServletRequest);
            if (user == null) {
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", httpServletRequest);
            }
            PageHelper.startPage(pageNum,pageSize);
            List<DkModel> dkModelList = dkMapper.selectList(new QueryWrapper<DkModel>()
                    .eq("dk_user_id", String.valueOf(user.getId()))
                    .eq(state != null,"dk_state", state)
                    .orderByDesc("create_time")
            );
            PageInfo<DkModel> pageInfo = new PageInfo<>(dkModelList);
            return ServerResponse.createBySuccess(pageInfo);
        } catch (Exception e) {
            log.error("IDkServices queryByShUserId error", e);
        }
        return ServerResponse.createByError();
    }
    @Override
src/main/java/com/nq/service/impl/FundsAppendServiceImpl.java
@@ -65,7 +65,7 @@
    /**
     * 配资追加申请-保存
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse save(FundsAppend model, HttpServletRequest request) {
        int ret = 0;
        if(model.getApplyId() == null || model.getApplyId() == 0){
src/main/java/com/nq/service/impl/FundsApplyServiceImpl.java
@@ -47,7 +47,7 @@
    IFundsSettingService iFundsSettingService;
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse insert(FundsApply model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if (model == null) {
@@ -121,7 +121,7 @@
    /**
     * 配资申请-审核
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
     public ServerResponse audit(FundsApply model, HttpServletRequest request) throws Exception {
        return  ServerResponse.createByErrorMsg("操作失败");
     }
src/main/java/com/nq/service/impl/MandatoryLiquidationService.java
@@ -21,7 +21,7 @@
    @Resource
    UserPositionMapper userPositionMapper;
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void RealTimeDataProcess(EStockType eStockType, StockRealTimeBean timeBean) {
        QueryWrapper<UserPosition>  upQuery  = new QueryWrapper<>();
src/main/java/com/nq/service/impl/PayServiceImpl.java
@@ -391,7 +391,7 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse flyPay(Integer payType, String payAmt, String currency, HttpServletRequest request) {
        User user = iUserService.getCurrentUser(request);
        SitePay sitePay  = sitePayMapper.selectById(payType);
src/main/java/com/nq/service/impl/StockAiServiceImpl.java
@@ -25,7 +25,6 @@
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@Service("iStockAiService")
@@ -74,33 +73,33 @@
     * @return
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyStockAi(Long id, BigDecimal buyNum, HttpServletRequest request) {
        try {
            User user = iUserService.getCurrentUser(request);
            if (user == null ){
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", request);
            }
            Object lock = locks.computeIfAbsent(Long.valueOf(user.getId()), k -> new Object());
            synchronized (lock){
                SiteProduct siteProduct = iSiteProductService.getProductSetting();
                if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
                    return ServerResponse.createByErrorMsg("订单失败,请先实名认证");
                    return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request);
                }
                if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
                    return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定");
                    return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request);
                }
                StockAI stockAI = stockAiMapper.selectById(id);
                if (stockAI == null) {
                    return ServerResponse.createByErrorMsg("订单失败,AI股票不存在");
                    return ServerResponse.createByErrorMsg("订单失败,AI股票不存在", request);
                }
                if (!stockAI.getStatus().equals(EStockAIStatus.online.getValue())) {
                    return ServerResponse.createByErrorMsg("订单失败,AI股票已下架");
                    return ServerResponse.createByErrorMsg("订单失败,AI股票已下架", request);
                }
                if(buyNum.compareTo(stockAI.getMinPrice()) < 0){
                    return ServerResponse.createByErrorMsg("最低购买数量" + stockAI.getMinPrice());
                    return ServerResponse.createByErrorMsg("最低购买数量" + stockAI.getMinPrice(), request);
                }
                //获取用户账户
                UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId());
@@ -118,17 +117,13 @@
                    buyNum = iUserAssetsServices.exchangeAmountByRate(buyNum, exchangeRate.getRata());
                }*/
                if(buyNum.compareTo(userAssets.getAvailableBalance()) > 0){
                    return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance());
                    return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request);
                }
                if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
                    return ServerResponse.createByErrorMsg("请先缴清待补资金");
                    return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
                }
                Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), user.getId(), EUserAssets.BUY_AI, buyNum, null);
                if (!flag)  {
                    return ServerResponse.createByErrorMsg("扣款失败,无法转换货币");
                }
                iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), user.getId(), EUserAssets.BUY_AI, buyNum);
                StockAIOrder stockAIOrder = new StockAIOrder();
                stockAIOrder.setUserId(user.getId());
                stockAIOrder.setStockAiId(id);
@@ -138,7 +133,7 @@
                stockAIOrder.setRealEarning(BigDecimal.valueOf(0));
                stockAIOrder.setStatus(EStockAIOrderStatus.wait.getStatus());   //等待审核
                stockAiOrderMapper.insert(stockAIOrder);
                return ServerResponse.createBySuccessMsg("下单成功");
                return ServerResponse.createBySuccessMsg("下单成功", request);
            }
        } catch (Exception e) {
            log.error("StockAiService buyStockAiList  {}", e.getMessage());
@@ -159,7 +154,7 @@
        try {
            User user = iUserService.getCurrentUser(request);
            if (user == null ){
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
                return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", request);
            }
            PageHelper.startPage(pageNum, pageSize);
            List<StockAiOrderTypeVO> stockAIOrders = stockAiOrderMapper.getStockAiOrderList(user.getId(), status);
@@ -228,6 +223,7 @@
            }
            return ServerResponse.createBySuccess("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
        }
        return ServerResponse.createByError();
@@ -275,7 +271,7 @@
    @Override
    public ServerResponse openPosition(StockAIOrderPosition model) {
        try {
            Object lock = locks.computeIfAbsent(model.getStockAiOrderId(), k -> new Object());
            Object lock = locks.computeIfAbsent(Long.valueOf(model.getStockAiOrderId()), k -> new Object());
            synchronized (lock) {
                StockAIOrder stockAIOrder = stockAiOrderMapper.selectById(model.getStockAiOrderId());
                if (stockAIOrder == null) {
@@ -310,6 +306,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse orderOperation(Long id, String status) {
        try {
            Object lock = locks.computeIfAbsent(id, k -> new Object());
@@ -331,21 +328,7 @@
                    StockAI stockAI = stockAiMapper.selectById(stockAIOrder.getStockAiId());
                    //买入金额
                    BigDecimal buyNum =  stockAIOrder.getBuyAmount();
                    /*//如果不是墨西哥币需要转换金额
                    if (!stockAI.getStockType().equals(EStockType.MX.getCode())) {
                        EStockType stockType = EStockType.getEStockTypeByCode(stockAI.getStockType());
                        ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency(stockType.getSymbol(), EStockType.MX.getSymbol())
                                .orElse(null);
                        if (exchangeRate == null) {
                            return ServerResponse.createByErrorMsg("请先设置当前货币汇率");
                        }
                        //转换为墨西哥币
                        buyNum = iUserAssetsServices.exchangeAmountByRate(buyNum, exchangeRate.getRata());
                    }*/
                    Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.BUY_AI_REJECT, buyNum, null);
                    if (!flag)  {
                        return ServerResponse.createByErrorMsg("扣款失败,无法转换货币");
                    }
                    iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.BUY_AI_REJECT, buyNum);
                } else if (status.equals(EStockAIOrderStatus.finished.getStatus())) {
                    if (!stockAIOrder.getStatus().equals(EStockAIOrderStatus.passed.getStatus())) {
                        return ServerResponse.createByErrorMsg("只能结算申请通过订单");
@@ -366,26 +349,10 @@
                        amount = amount.add(earningsSUM);
                    }*/
                    StockAI stockAI = stockAiMapper.selectById(stockAIOrder.getStockAiId());
                    //收益+本金
                    BigDecimal amount = stockAIOrder.getBuyAmount().add(stockAIOrder.getRealEarning());
                    //需要解冻金额
                    BigDecimal buyAmount = stockAIOrder.getBuyAmount();
                    /*//如果不是墨西哥币需要转换金额
                    if (!stockAI.getStockType().equals(EStockType.MX.getCode())) {
                        EStockType stockType = EStockType.getEStockTypeByCode(stockAI.getStockType());
                        ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency(stockType.getSymbol(), EStockType.MX.getSymbol())
                                .orElse(null);
                        if (exchangeRate == null) {
                            return ServerResponse.createByErrorMsg("请先设置当前货币汇率");
                        }
                        //转换为墨西哥币
                        amount = iUserAssetsServices.exchangeAmountByRate(amount, exchangeRate.getRata());
                        buyAmount = iUserAssetsServices.exchangeAmountByRate(buyAmount, exchangeRate.getRata());
                    }*/
                    Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.AI_SETTLEMENT, amount, buyAmount);
                    if (!flag)  {
                        return ServerResponse.createByErrorMsg("扣款失败,无法转换货币");
                    }
                    //归还本金
                    iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.AI_SETTLEMENT, stockAIOrder.getBuyAmount());
                    //收益
                    iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.AI_SETTLEMENT_INT, stockAIOrder.getRealEarning());
                }
                stockAIOrder.setStatus(status);
                stockAIOrder.setAuditDate(new Date());
src/main/java/com/nq/service/impl/StockServiceImpl.java
@@ -23,6 +23,7 @@
import com.nq.utils.stock.qq.QqStockApi;
import com.nq.utils.stock.sina.StockApi;
import com.nq.vo.stock.*;
import com.nq.vo.stock.ai.StockAiOrderVO;
import com.nq.vo.stock.k.MinDataVO;
import com.nq.vo.stock.k.echarts.EchartsDataVO;
@@ -817,4 +818,30 @@
        }
        return ServerResponse.createByError();
    }
    /**
     * 搜索
     * @param pageNum
     * @param pageSize
     * @param keyWords
     * @return
     */
    @Override
    public ServerResponse getStocksByKeyWords(int pageNum, int pageSize, String keyWords) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<StockVOQuery> stocks = stockMapper.findStocksQuery(keyWords);
            // 获取分页信息
            PageInfo<StockVOQuery> pageInfo = new PageInfo<>(stocks);
            /*if (!pageInfo.getList().isEmpty()) {
            }*/
            return ServerResponse.createBySuccess(pageInfo);
        } catch (Exception e) {
            log.error("StockAiService getStocksByKeyWords error", e);
        }
        return ServerResponse.createByError();
    }
}
src/main/java/com/nq/service/impl/UserAssetsServices.java
@@ -176,7 +176,7 @@
    @Override
    public Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType) {
    public Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType) throws Exception {
        //UserAssets userAssets = assetsByTypeAndUserId(accetType,userId);
        //查询墨西哥账户
        UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId);
@@ -188,6 +188,9 @@
            if (exchangeRate != null) {
                //转换为墨西哥币
                amount = exchangeAmountByRate(amount, exchangeRate.getRata());
            } else {
                log.error("availablebalanceChange ExchangeRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol());
                throw new Exception("货币转换汇率未设置");
            }
        }
        UserPosition userPosition = userPositionMapper.selectOne(new LambdaQueryWrapper<UserPosition>().gt(UserPosition::getAmountToBeCovered, BigDecimal.ZERO).eq(UserPosition::getUserId,userAssets.getUserId()));
@@ -310,7 +313,7 @@
    }
    public Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount) {
    public Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount) throws Exception {
        //查询墨西哥账户
        UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId);
        //如果不是墨西哥币需要转换金额
@@ -321,9 +324,9 @@
            if (exchangeRate != null) {
                //转换为墨西哥币
                amount = exchangeAmountByRate(amount, exchangeRate.getRata());
                buyAmount = exchangeAmountByRate(buyAmount, exchangeRate.getRata());
            } else {
                return false;
                log.error("ExchangeRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol());
                throw new Exception("货币转换汇率未设置");
            }
        }
        String before = userAssets.getAvailableBalance().toString();
@@ -339,10 +342,23 @@
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount));
        } else if (eUserAssets.getCode().equals(EUserAssets.AI_SETTLEMENT.getCode())) {
            //解除购买冻结金额
            userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(buyAmount.negate()));
            //归还可用金额(购买金额+收益)
            userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(amount.negate()));
            //归还购买金额
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount));
        } else if (eUserAssets.getCode().equals(EUserAssets.AI_SETTLEMENT_INT.getCode())) {
            //收益
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount));
        } else if(eUserAssets.getCode().equals(EUserAssets.DK.getCode())) {
            //发放贷款金额
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount));
        } else if(eUserAssets.getCode().equals(EUserAssets.RT_DK.getCode())) {
            //归还贷款
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount.negate()));
        } else if(eUserAssets.getCode().equals(EUserAssets.RT_DK_INT.getCode())) {
            //贷款利息
            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount.negate()));
        }
        String after = userAssets.getAvailableBalance().toString();
        MoneyLog moneyLog = new MoneyLog();
        moneyLog.setDescs(eUserAssets.getDesc());
src/main/java/com/nq/service/impl/UserFundsPositionServiceImpl.java
@@ -121,7 +121,7 @@
    /**
     * 分仓交易-入仓
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyFunds(Integer stockId, Integer buyNum, Integer buyType, Integer lever, Integer subaccountNumber, HttpServletRequest request)  throws Exception {
        return ServerResponse.createBySuccess("Order successful");
    }
@@ -129,7 +129,7 @@
    /*
    * 分仓交易-用户平仓操作
    * */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse sellFunds(String positionSn, int doType) throws Exception {
        log.info("【用户交易平仓】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
src/main/java/com/nq/service/impl/UserFuturesPositionServiceImpl.java
@@ -65,7 +65,7 @@
    @Autowired
    ISiteProductService iSiteProductService;
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyFutures(Integer futuresId, Integer buyNum, Integer buyType, Integer lever, HttpServletRequest request) throws Exception {
src/main/java/com/nq/service/impl/UserIndexPositionServiceImpl.java
@@ -68,7 +68,7 @@
    @Autowired
    CurrencyUtils currencyUtils;
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyIndex(Integer indexId, Integer buyNum, Integer buyType, Integer lever,BigDecimal profitTarget,BigDecimal stopTarget, HttpServletRequest request) throws Exception {
@@ -85,7 +85,7 @@
     * @return
     * @throws Exception
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyIndexOrder(Integer indexId, Integer buyNum, Integer buyType, Integer lever,BigDecimal profitTarget,BigDecimal stopTarget,Integer userId) throws Exception {
        if (indexId == null || buyNum == null || buyType == null) {
            return ServerResponse.createByErrorMsg("参数不能为空");
@@ -244,7 +244,7 @@
        return ServerResponse.createByErrorMsg("删除失败");
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse sellIndex(String positionSn, int doType) throws Exception {
        log.info("【用户交易平仓指数】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
        return ServerResponse.createBySuccessMsg("Closed position successfully!");
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -16,11 +16,9 @@
import com.google.common.collect.Lists;
import com.nq.common.ServerResponse;
import com.nq.utils.*;
import com.nq.utils.redis.RedisKeyUtil;
import com.nq.utils.stock.BuyAndSellUtils;
import com.nq.utils.stock.GeneratePosition;
import com.nq.utils.stock.GetStayDays;
import com.nq.utils.stock.pinyin.GetPyByChinese;
import com.nq.utils.stock.sina.StockApi;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.vo.agent.AgentIncomeVO;
@@ -30,7 +28,6 @@
import com.nq.vo.position.PositionVO;
import com.nq.vo.position.UserPositionVO;
import com.nq.vo.stock.StockListVO;
import com.nq.vo.stock.ai.StockAiOrderTypeVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -43,9 +40,6 @@
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -135,112 +129,116 @@
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) {
        SiteProduct siteProduct = iSiteProductService.getProductSetting();
        User user = this.iUserService.getCurrentRefreshUser(request);
        synchronized (user.getId()){
            if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
                return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request);
            }
            // 手续费率
            BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
        try {
            synchronized (user.getId()){
                if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
                    return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request);
                }
                // 手续费率
                BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
            if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
                return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request);
            }
                if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
                    return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request);
                }
            Stock stock = stockMapper.selectByPrimaryKey(stockId);
            if (stock == null) {
                return ServerResponse.createByErrorMsg("订单失败,股票代码不存在", request);
            }
            //判断股票是否在可交易时间段
            Boolean b = tradingHourService.timeCheck(stock.getStockCode(), stock.getStockType());
            if (!b) {
                return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request);
            }
                Stock stock = stockMapper.selectByPrimaryKey(stockId);
                if (stock == null) {
                    return ServerResponse.createByErrorMsg("订单失败,股票代码不存在", request);
                }
                //判断股票是否在可交易时间段
                Boolean b = tradingHourService.timeCheck(stock.getStockCode(), stock.getStockType());
                if (!b) {
                    return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request);
                }
            StockConfig mainBuyConfig =  iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode());
                StockConfig mainBuyConfig =  iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode());
            if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
                return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request);
            }
                if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
                    return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request);
                }
            UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId());
            StockConfig maxBuyConfig =  iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode());
            if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
                return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request);
            }
            if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
                return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
            }
            if (stock.getIsLock() != 0) {
                return ServerResponse.createByErrorMsg("订单失败,股票被锁定", request);
            }
                UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId());
                StockConfig maxBuyConfig =  iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode());
                if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
                    return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request);
                }
                if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
                    return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
                }
                if (stock.getIsLock() != 0) {
                    return ServerResponse.createByErrorMsg("订单失败,股票被锁定", request);
                }
            if (!priceServices.isLimitUpBuy(stock.getStockCode())) {
                return ServerResponse.createByErrorMsg("暂无配额", request);
            }
                if (!priceServices.isLimitUpBuy(stock.getStockCode())) {
                    return ServerResponse.createByErrorMsg("暂无配额", request);
                }
            //股票类型 现价 数据源的处理
            BigDecimal nowPrice = priceServices.getNowPrice(stock.getStockCode());
                //股票类型 现价 数据源的处理
                BigDecimal nowPrice = priceServices.getNowPrice(stock.getStockCode());
            if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
                return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
            }
                if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
                    return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
                }
            BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
            BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
                BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
                BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
            BigDecimal   fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
            BigDecimal availableBalance =  fundratio.multiply(userAssets.getAvailableBalance());
            if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
                return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
            }
            UserPosition userPosition = new UserPosition();
            if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) {
                userPosition.setProfitTargetPrice(profitTarget);
            }
            if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) {
                userPosition.setStopTargetPrice(stopTarget);
            }
            userPosition.setPositionType(user.getAccountType());
            userPosition.setPositionSn(KeyUtils.getUniqueKey());
            userPosition.setUserId(user.getId());
            userPosition.setNickName(user.getRealName());
            userPosition.setAgentId(user.getAgentId());
            userPosition.setStockCode(stock.getStockCode());
            userPosition.setStockName(stock.getStockName());
            userPosition.setStockGid(stock.getStockType());
            userPosition.setStockSpell(stock.getStockSpell());
            userPosition.setBuyOrderId(GeneratePosition.getPositionId());
            userPosition.setBuyOrderTime(new Date());
            userPosition.setBuyOrderPrice(nowPrice);
            userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
            userPosition.setOrderNum(buyNum);
            if (stock.getStockPlate() != null) {
                userPosition.setStockPlate(stock.getStockPlate());
            }
            userPosition.setIsLock(Integer.valueOf(0));
            userPosition.setOrderLever(lever);
            userPosition.setOrderTotalPrice(buyAmt);
            // 手续费
                BigDecimal   fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
                BigDecimal availableBalance =  fundratio.multiply(userAssets.getAvailableBalance());
                if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
                    return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
                }
                UserPosition userPosition = new UserPosition();
                if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) {
                    userPosition.setProfitTargetPrice(profitTarget);
                }
                if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) {
                    userPosition.setStopTargetPrice(stopTarget);
                }
                userPosition.setPositionType(user.getAccountType());
                userPosition.setPositionSn(KeyUtils.getUniqueKey());
                userPosition.setUserId(user.getId());
                userPosition.setNickName(user.getRealName());
                userPosition.setAgentId(user.getAgentId());
                userPosition.setStockCode(stock.getStockCode());
                userPosition.setStockName(stock.getStockName());
                userPosition.setStockGid(stock.getStockType());
                userPosition.setStockSpell(stock.getStockSpell());
                userPosition.setBuyOrderId(GeneratePosition.getPositionId());
                userPosition.setBuyOrderTime(new Date());
                userPosition.setBuyOrderPrice(nowPrice);
                userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
                userPosition.setOrderNum(buyNum);
                if (stock.getStockPlate() != null) {
                    userPosition.setStockPlate(stock.getStockPlate());
                }
                userPosition.setIsLock(Integer.valueOf(0));
                userPosition.setOrderLever(lever);
                userPosition.setOrderTotalPrice(buyAmt);
                // 手续费
            userPosition.setOrderFee(orderFree);
            userPosition.setOrderSpread(BigDecimal.ZERO);
            userPosition.setSpreadRatePrice(BigDecimal.ZERO);
            BigDecimal profit_and_lose = new BigDecimal("0");
            userPosition.setProfitAndLose(profit_and_lose);
            userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree));
            userPosition.setOrderStayDays(Integer.valueOf(0));
            userPosition.setOrderStayFee(BigDecimal.ZERO);
            userPositionMapper.insert(userPosition);
            iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
            iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", "");
            return ServerResponse.createBySuccessMsg("下单成功", request);
                userPosition.setOrderFee(orderFree);
                userPosition.setOrderSpread(BigDecimal.ZERO);
                userPosition.setSpreadRatePrice(BigDecimal.ZERO);
                BigDecimal profit_and_lose = new BigDecimal("0");
                userPosition.setProfitAndLose(profit_and_lose);
                userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree));
                userPosition.setOrderStayDays(Integer.valueOf(0));
                userPosition.setOrderStayFee(BigDecimal.ZERO);
                userPositionMapper.insert(userPosition);
                iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
                iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", "");
                return ServerResponse.createBySuccessMsg("下单成功", request);
            }
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
    }
@@ -287,61 +285,65 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse sell(String positionSn, int doType) {
        UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
        if (userPosition == null) {
            return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
        }
        BigDecimal siitteBuyFee = iSiteSettingService.getSiteSetting().getBuyFee();
        Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
        if(null == stock){
            return ServerResponse.createByErrorMsg("股票不存在,平仓失败");
        }
        Boolean b = tradingHourService.timeCheck(userPosition.getStockCode(), stock.getStockType());
        if (!b) {
            return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内");
        }
        User user = this.userMapper.selectById(userPosition.getUserId());
        if (user == null) {
            return ServerResponse.createByErrorMsg("平仓失败,用户不存在");
        }
        if (user.getIsLock() == 1) {
            return ServerResponse.createByErrorMsg("账户已被限制交易");
        }
        if (userPosition.getSellOrderId() != null) {
            return ServerResponse.createByErrorMsg("平仓失败, 订单已平仓");
        }
        if (1 == userPosition.getIsLock().intValue()) {
            return ServerResponse.createByErrorMsg("this order is closed " + userPosition.getLockMsg());
        }
        //Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
        BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode());
        if (nowPrice.compareTo(new BigDecimal("0")) != 1) {
            return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
        }
        userPosition.setSellOrderId(GeneratePosition.getPositionId());
        userPosition.setSellOrderPrice(nowPrice);
        userPosition.setSellOrderTime(new Date());
        try {
            UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
            if (userPosition == null) {
                return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
            }
            BigDecimal siitteBuyFee = iSiteSettingService.getSiteSetting().getBuyFee();
            Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
            if(null == stock){
                return ServerResponse.createByErrorMsg("股票不存在,平仓失败");
            }
            Boolean b = tradingHourService.timeCheck(userPosition.getStockCode(), stock.getStockType());
            if (!b) {
                return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内");
            }
            User user = this.userMapper.selectById(userPosition.getUserId());
            if (user == null) {
                return ServerResponse.createByErrorMsg("平仓失败,用户不存在");
            }
            if (user.getIsLock() == 1) {
                return ServerResponse.createByErrorMsg("账户已被限制交易");
            }
            if (userPosition.getSellOrderId() != null) {
                return ServerResponse.createByErrorMsg("平仓失败, 订单已平仓");
            }
            if (1 == userPosition.getIsLock().intValue()) {
                return ServerResponse.createByErrorMsg("this order is closed " + userPosition.getLockMsg());
            }
            //Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
            BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode());
            if (nowPrice.compareTo(new BigDecimal("0")) != 1) {
                return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
            }
            userPosition.setSellOrderId(GeneratePosition.getPositionId());
            userPosition.setSellOrderPrice(nowPrice);
            userPosition.setSellOrderTime(new Date());
        BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum()));
        BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
        userPositionMapper.updateById(userPosition);
        userAssetsServices.availablebalanceChange(stock.getStockType(),
                userPosition.getUserId(), EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
                userPosition.getOrderTotalPrice(), "", "");
        userAssetsServices.availablebalanceChange(stock.getStockType(),
                userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
                xsPrice, "", "");
            BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum()));
            BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
            userPositionMapper.updateById(userPosition);
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    userPosition.getUserId(), EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
                    userPosition.getOrderTotalPrice(), "", "");
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
                    xsPrice, "", "");
        PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode()));
        userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
                profitVO.getAllProfitAndLose(), "", "");
        return ServerResponse.createBySuccessMsg("平仓成功!");
            PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode()));
            userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
                    profitVO.getAllProfitAndLose(), "", "");
            return ServerResponse.createBySuccessMsg("平仓成功!");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse sell(String positionSn, int doType, Integer number,HttpServletRequest request) {
        UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
        if (userPosition == null) {
@@ -434,32 +436,36 @@
    }
    private ServerResponse<Object> getObjectServerResponse(HttpServletRequest request, UserPosition userPosition, BigDecimal nowPrice, BigDecimal siitteBuyFee, Stock stock) {
        userPosition.setSellOrderId(GeneratePosition.getPositionId());
        userPosition.setSellOrderPrice(nowPrice);
        userPosition.setSellOrderTime(new Date());
        try {
            userPosition.setSellOrderId(GeneratePosition.getPositionId());
            userPosition.setSellOrderPrice(nowPrice);
            userPosition.setSellOrderTime(new Date());
        BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum()));
        BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
        userPosition.setOrderFee(userPosition.getOrderFee().add(xsPrice));
        userPositionMapper.updateById(userPosition);
        userAssetsServices.availablebalanceChange(stock.getStockType(),
                userPosition.getUserId(),
                EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
                userPosition.getOrderTotalPrice(), "", "");
        userAssetsServices.availablebalanceChange(stock.getStockType(),
                userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
                xsPrice, "", "");
            BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum()));
            BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
            userPosition.setOrderFee(userPosition.getOrderFee().add(xsPrice));
            userPositionMapper.updateById(userPosition);
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    userPosition.getUserId(),
                    EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
                    userPosition.getOrderTotalPrice(), "", "");
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
                    xsPrice, "", "");
        PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition,
                priceServices.getNowPrice(userPosition.getStockCode()));
            PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition,
                    priceServices.getNowPrice(userPosition.getStockCode()));
        userAssetsServices.availablebalanceChange(stock.getStockType(),
                userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
                profitVO.getAllProfitAndLose(), "", "");
        return ServerResponse.createBySuccessMsg("平仓成功!", request);
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
                    profitVO.getAllProfitAndLose(), "", "");
            return ServerResponse.createBySuccessMsg("平仓成功!", request);
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ServerResponse allSell(HttpServletRequest request, String stockType) throws Exception {
        //判断股票是否在可交易时间段
@@ -1132,7 +1138,7 @@
        }
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse closingStayTask(UserPosition position, Integer stayDays) throws Exception {
        log.info("=================closingStayTask====================");
        log.info("修改留仓费,持仓id={},持仓天数={}", position.getId(), stayDays);
@@ -1309,114 +1315,119 @@
     * @Date: 2022/10/26
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse newStockToPosition(Integer id,BigDecimal amountToBeCovered) {
        UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
        if (userStockSubscribe == null) {
            return ServerResponse.createByErrorMsg("无该申购记录");
        }
        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("newlist_id", userStockSubscribe.getNewStockId()));
        if (stockSubscribe == null) {
            return ServerResponse.createByErrorMsg("该新股不存在");
        }
        try {
            UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
            if (userStockSubscribe == null) {
                return ServerResponse.createByErrorMsg("无该申购记录");
            }
            StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("newlist_id", userStockSubscribe.getNewStockId()));
            if (stockSubscribe == null) {
                return ServerResponse.createByErrorMsg("该新股不存在");
            }
        Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, userStockSubscribe.getNewCode()));
        String stockType;
        UserPosition userPosition = new UserPosition();
            Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, userStockSubscribe.getNewCode()));
            String stockType;
            UserPosition userPosition = new UserPosition();
        if(null == stock){
            userPosition.setStockCode(stockSubscribe.getCode());
            userPosition.setStockSpell(stockSubscribe.getName());
            stockType = stockSubscribe.getStockType();
        }else{
            userPosition.setStockCode(stock.getStockCode());
            userPosition.setStockSpell(stock.getStockSpell());
            stockType = stock.getStockType();
        }
            if(null == stock){
                userPosition.setStockCode(stockSubscribe.getCode());
                userPosition.setStockSpell(stockSubscribe.getName());
                stockType = stockSubscribe.getStockType();
            }else{
                userPosition.setStockCode(stock.getStockCode());
                userPosition.setStockSpell(stock.getStockSpell());
                stockType = stock.getStockType();
            }
        userPosition.setPositionType(1);
        userPosition.setPositionSn(KeyUtils.getUniqueKey());
        userPosition.setUserId(userStockSubscribe.getUserId());
        userPosition.setNickName(userStockSubscribe.getRealName());
        userPosition.setAgentId(userStockSubscribe.getAgentId());
            userPosition.setPositionType(1);
            userPosition.setPositionSn(KeyUtils.getUniqueKey());
            userPosition.setUserId(userStockSubscribe.getUserId());
            userPosition.setNickName(userStockSubscribe.getRealName());
            userPosition.setAgentId(userStockSubscribe.getAgentId());
        userPosition.setStockName(userStockSubscribe.getNewName());
            userPosition.setStockName(userStockSubscribe.getNewName());
//        StringBuffer gid = new StringBuffer();
//        gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():"");
//        gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild");
        userPosition.setStockGid(stockType);
        userPosition.setBuyOrderId(GeneratePosition.getPositionId());
        userPosition.setBuyOrderTime(new Date());
        userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice());
        userPosition.setOrderDirection("买涨");
            userPosition.setStockGid(stockType);
            userPosition.setBuyOrderId(GeneratePosition.getPositionId());
            userPosition.setBuyOrderTime(new Date());
            userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice());
            userPosition.setOrderDirection("买涨");
        userPosition.setOrderNum(userStockSubscribe.getApplyNumber());
            userPosition.setOrderNum(userStockSubscribe.getApplyNumber());
        userPosition.setIsLock(Integer.valueOf(0));
            userPosition.setIsLock(Integer.valueOf(0));
        userPosition.setOrderLever(1);
            userPosition.setOrderLever(1);
        //递延费特殊处理
        //            BigDecimal stayFee = userPosition.getOrderTotalPrice().multiply(siteSetting.getStayFee());
        BigDecimal stayFee = new BigDecimal(0);
        BigDecimal allStayFee = stayFee.multiply(new BigDecimal(1));
        userPosition.setOrderStayFee(allStayFee);
        userPosition.setOrderStayDays(1);
        userPosition.setOrderTotalPrice(userStockSubscribe.getBond());
            //递延费特殊处理
            //            BigDecimal stayFee = userPosition.getOrderTotalPrice().multiply(siteSetting.getStayFee());
            BigDecimal stayFee = new BigDecimal(0);
            BigDecimal allStayFee = stayFee.multiply(new BigDecimal(1));
            userPosition.setOrderStayFee(allStayFee);
            userPosition.setOrderStayDays(1);
            userPosition.setOrderTotalPrice(userStockSubscribe.getBond());
        //            BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4);
        // 手续费率
        BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
        BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(userStockSubscribe.getBond());
        log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt);
        userPosition.setOrderFee(buy_fee_amt);
            //            BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4);
            // 手续费率
            BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
            BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(userStockSubscribe.getBond());
            log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt);
            userPosition.setOrderFee(buy_fee_amt);
        //            BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4);
        BigDecimal buy_yhs_amt = new BigDecimal(0);
        log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt);
        userPosition.setOrderSpread(buy_yhs_amt);
            //            BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4);
            BigDecimal buy_yhs_amt = new BigDecimal(0);
            log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt);
            userPosition.setOrderSpread(buy_yhs_amt);
        BigDecimal spread_rate_amt = new BigDecimal(0);
        userPosition.setSpreadRatePrice(spread_rate_amt);
            BigDecimal spread_rate_amt = new BigDecimal(0);
            userPosition.setSpreadRatePrice(spread_rate_amt);
        BigDecimal profit_and_lose = new BigDecimal("0");
        userPosition.setProfitAndLose(profit_and_lose);
            BigDecimal profit_and_lose = new BigDecimal("0");
            userPosition.setProfitAndLose(profit_and_lose);
        BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt);
        userPosition.setAllProfitAndLose(all_profit_and_lose);
            BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt);
            userPosition.setAllProfitAndLose(all_profit_and_lose);
        userPosition.setOrderStayDays(Integer.valueOf(0));
        userPosition.setOrderStayFee(new BigDecimal("0"));
        userPosition.setAmountToBeCovered(amountToBeCovered);
        userPosition.setNewId(stockSubscribe.getNewlistId());
        int ret = 0;
        ret = this.userPositionMapper.insert(userPosition);
        UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stockType, userPosition.getUserId());
        if(null == userAssets){
            return ServerResponse.createByErrorMsg("新股转持仓失败");
        }
        userAssetsMapper.updateById(userAssets);
        iUserAssetsServices.availablebalanceChange(stockType, userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
        if (ret > 0) {
            userStockSubscribe.setStatus(5);
            userStockSubscribeMapper.update1(userStockSubscribe);
            if (userStockSubscribe.getType() == 1 || userStockSubscribe.getType() == 2) {
                User user = userMapper.selectById(userStockSubscribe.getUserId());
                ret = userMapper.updateById(user);
            userPosition.setOrderStayDays(Integer.valueOf(0));
            userPosition.setOrderStayFee(new BigDecimal("0"));
            userPosition.setAmountToBeCovered(amountToBeCovered);
            userPosition.setNewId(stockSubscribe.getNewlistId());
            int ret = 0;
            ret = this.userPositionMapper.insert(userPosition);
            UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stockType, userPosition.getUserId());
            if(null == userAssets){
                return ServerResponse.createByErrorMsg("新股转持仓失败");
            }
            userAssetsMapper.updateById(userAssets);
            iUserAssetsServices.availablebalanceChange(stockType, userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
            if (ret > 0) {
                return ServerResponse.createBySuccessMsg("新股转持仓成功");
                userStockSubscribe.setStatus(5);
                userStockSubscribeMapper.update1(userStockSubscribe);
                if (userStockSubscribe.getType() == 1 || userStockSubscribe.getType() == 2) {
                    User user = userMapper.selectById(userStockSubscribe.getUserId());
                    ret = userMapper.updateById(user);
                }
                if (ret > 0) {
                    return ServerResponse.createBySuccessMsg("新股转持仓成功");
                } else {
                    return ServerResponse.createByErrorMsg("新股转持仓失败");
                }
            } else {
                return ServerResponse.createByErrorMsg("新股转持仓失败");
            }
        } else {
            return ServerResponse.createByErrorMsg("新股转持仓失败");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
    }
@@ -1431,7 +1442,7 @@
     * @param request
     * @return
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyVipQc(String stockCode, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) throws Exception {
        /*实名认证开关开启*/
@@ -1684,7 +1695,7 @@
     * @param request
     * @return
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request) throws Exception {
        /*实名认证开关开启*/
        SiteProduct siteProduct = iSiteProductService.getProductSetting();
@@ -1798,7 +1809,7 @@
    }
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public void stockConstraint(List<UserPosition> list) {
        try {
            //SiteSetting siteSetting = iSiteSettingService.getSiteSetting();
@@ -1977,32 +1988,34 @@
    //平仓
    private void extracted(UserPosition position, BigDecimal nowPrice, Stock stock,Integer liquidation) {
        //-1强平 0未触发 1止损强平 2止盈强平
        BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.SELL_HANDLING_CHARGE.getCode()).getCValue()) ;
        BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(position.getOrderNum()));
        BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);//手续费
        // 更新订单信息
        position.setSellOrderId(GeneratePosition.getPositionId());
        position.setSellOrderPrice(nowPrice);
        position.setSellOrderTime(new Date());
        userPositionMapper.updateById(position);
        if(liquidation == -1){
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    position.getUserId(),
                    EUserAssets.CONSTRAINT_CLOSE_POSITION,
                    position.getOrderTotalPrice(), "", "");
        }else if(liquidation == 1 || liquidation == 2){
            userAssetsServices.availablebalanceChange(stock.getStockType(),
                    position.getUserId(), EUserAssets.HANDLING_CHARGE,
                    xsPrice, "", "");
            PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(position, priceServices.getNowPrice(position.getStockCode()));
            userAssetsServices.availablebalanceChange(stock.getStockType(), position.getUserId(), EUserAssets.CLOSE_POSITION,
                    profitVO.getAllProfitAndLose(), "", "");
        try {
            //-1强平 0未触发 1止损强平 2止盈强平
            BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.SELL_HANDLING_CHARGE.getCode()).getCValue()) ;
            BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(position.getOrderNum()));
            BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);//手续费
            // 更新订单信息
            position.setSellOrderId(GeneratePosition.getPositionId());
            position.setSellOrderPrice(nowPrice);
            position.setSellOrderTime(new Date());
            userPositionMapper.updateById(position);
            if(liquidation == -1){
                userAssetsServices.availablebalanceChange(stock.getStockType(),
                        position.getUserId(),
                        EUserAssets.CONSTRAINT_CLOSE_POSITION,
                        position.getOrderTotalPrice(), "", "");
            }else if(liquidation == 1 || liquidation == 2){
                userAssetsServices.availablebalanceChange(stock.getStockType(),
                        position.getUserId(), EUserAssets.HANDLING_CHARGE,
                        xsPrice, "", "");
                PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(position, priceServices.getNowPrice(position.getStockCode()));
                userAssetsServices.availablebalanceChange(stock.getStockType(), position.getUserId(), EUserAssets.CLOSE_POSITION,
                        profitVO.getAllProfitAndLose(), "", "");
            }
            log.info("强制平仓成功,订单id: {}", position.getId());
        } catch (Exception e) {
            log.info("extracted Exception {}", e.getMessage());
        }
        log.info("强制平仓成功,订单id: {}", position.getId());
    }
@@ -2046,6 +2059,7 @@
                        if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
                            userPositionVO.setProfitAndLose(BigDecimal.ZERO);
                            userPositionVO.setProfitAndLoseParent("0%");
                            userPositionVO.setProfitAndLoseParent2(BigDecimal.ZERO);
                            userPositionVO.setIsListed(false);
                        }else{
                            userPositionVO.setIsListed(true);
@@ -2083,6 +2097,57 @@
        return ServerResponse.createByError();
    }
    @Override
    public ServerResponse checkDz(Integer id, Integer checkType, Integer orderNum, HttpServletRequest request) {
        try {
            UserPositionCheckDz userPositionCheckDz = userPositionCheckDzService.getById(id);
            if (userPositionCheckDz == null) {
                return ServerResponse.createByErrorMsg("订单不存在", request);
            }
            if (userPositionCheckDz.getCheckType() != 0) {
                return ServerResponse.createByErrorMsg("订单已审核", request);
            }
            if (checkType == 2) {
                userPositionCheckDz.setCheckType(checkType);
                userPositionCheckDzService.updateById(userPositionCheckDz);
                return ServerResponse.createBySuccess("审核成功", request);
            }
            User user = userMapper.selectById(userPositionCheckDz.getUserId());
            StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId()));
            UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stockDz.getStockType(), user.getId());
            if (userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0) {
                return ServerResponse.createByErrorMsg("用户账户有待补资金未补齐,审核失败", request);
            }
            BigDecimal nowPrice = stockDz.getNowPrice();
            if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
                return ServerResponse.createByErrorMsg("股票价格0,请重试", request);
            }
            userPositionCheckDz.setOrderNum(orderNum);
            userPositionCheckDz.setOrderTotalPrice(nowPrice.multiply(new BigDecimal(orderNum.intValue())));
            BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(userPositionCheckDz.getOrderNum()));
            BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
            BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
            if (buyAmt.compareTo(availableBalance) > 0) {
                return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
            }
            userPositionCheckDz.setCheckType(checkType);
            userPositionCheckDzService.updateById(userPositionCheckDz);
            UserPosition userPosition = Convert.convert(UserPosition.class, userPositionCheckDz);
            userPosition.setBuyOrderPrice(nowPrice);
            userPosition.setId(null);
            userPosition.setDzId(stockDz.getId());
            userPositionMapper.insert(userPosition);
            userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
            return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓", request);
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
    }
}
src/main/java/com/nq/service/impl/UserRechargeServiceImpl.java
@@ -151,7 +151,7 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse chargeSuccess(UserRecharge userRecharge) throws Exception {
        log.info("充值订单 确认成功操作 id = {}", userRecharge.getId());
@@ -290,7 +290,7 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse updateState(Integer chargeId, Integer state) throws Exception {
        UserRecharge userRecharge = this.userRechargeMapper.selectById(chargeId);
@@ -325,32 +325,36 @@
            return ServerResponse.createByErrorMsg("参数不能为空");
        }
        User user = this.userMapper.selectById(userId);
        if (user == null) {
            return ServerResponse.createByErrorMsg("找不到用户");
        try {
            User user = this.userMapper.selectById(userId);
            if (user == null) {
                return ServerResponse.createByErrorMsg("找不到用户");
            }
            UserRecharge userRecharge = new UserRecharge();
            userRecharge.setUserId(user.getId());
            userRecharge.setNickName(user.getRealName());
            userRecharge.setAgentId(user.getAgentId());
            String ordersn = KeyUtils.getRechargeOrderSn();
            userRecharge.setOrderSn(ordersn);
            userRecharge.setPayChannel(payChannel);
            userRecharge.setPayAmt(new BigDecimal(amt.intValue()));
            userRecharge.setAddTime(new Date());
            userRecharge.setPayTime(new Date());
            userRecharge.setOrderStatus(Integer.valueOf(1));
            userRecharge.setPayId(1);
            userAssetsServices.availablebalanceChange(EStockType.MX.getCode(),
                    userId,EUserAssets.TOP_UP,new BigDecimal(amt),"","");
            int insertCount = this.userRechargeMapper.insert(userRecharge);
            if (insertCount > 0) {
                return ServerResponse.createBySuccessMsg("生成订单成功!");
            }
            return ServerResponse.createByErrorMsg("生成订单失败,请重试");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
        UserRecharge userRecharge = new UserRecharge();
        userRecharge.setUserId(user.getId());
        userRecharge.setNickName(user.getRealName());
        userRecharge.setAgentId(user.getAgentId());
        String ordersn = KeyUtils.getRechargeOrderSn();
        userRecharge.setOrderSn(ordersn);
        userRecharge.setPayChannel(payChannel);
        userRecharge.setPayAmt(new BigDecimal(amt.intValue()));
        userRecharge.setAddTime(new Date());
        userRecharge.setPayTime(new Date());
        userRecharge.setOrderStatus(Integer.valueOf(1));
        userRecharge.setPayId(1);
        userAssetsServices.availablebalanceChange(EStockType.MX.getCode(),
                userId,EUserAssets.TOP_UP,new BigDecimal(amt),"","");
        int insertCount = this.userRechargeMapper.insert(userRecharge);
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("生成订单成功!");
        }
        return ServerResponse.createByErrorMsg("生成订单失败,请重试");
    }
src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -8,7 +8,6 @@
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.nq.common.ServerResponse;
import com.nq.config.StockPoll;
import com.nq.dao.*;
import com.nq.enums.EStockType;
import com.nq.enums.EUserAssets;
@@ -16,8 +15,6 @@
import com.nq.pojo.reponse.RUserAssets;
import com.nq.service.*;
import com.nq.utils.UserPointUtil;
import com.nq.utils.redis.RedisKeyUtil;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.SymmetricCryptoUtil;
import com.nq.utils.ip.IpUtils;
@@ -25,15 +22,11 @@
import com.nq.utils.redis.CookieUtils;
import com.nq.utils.redis.JsonUtil;
import com.nq.utils.redis.RedisShardedPoolUtils;
import com.nq.utils.stock.sina.StockApi;
import com.nq.vo.agent.AgentUserListVO;
import com.nq.vo.futuresposition.FuturesPositionVO;
import com.nq.vo.indexposition.IndexPositionVO;
import com.nq.vo.position.PositionProfitVO;
import com.nq.vo.position.PositionVO;
import com.nq.vo.position.UserPositionVO;
import com.nq.vo.stock.StockAdminListVO;
import com.nq.vo.stock.StockListVO;
import com.nq.vo.user.UserInfoVO;
import java.math.BigDecimal;
@@ -41,12 +34,10 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.nq.vo.user.UserOut;
import org.apache.commons.lang3.Conversion;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,6 +61,9 @@
    @Resource
    StockOptionMapper stockOptionMapper;
    @Autowired
    DkMapper dkMapper;
    @Autowired
    IUserService userService;
@@ -84,8 +78,6 @@
    StockMapper stockMapper;
    @Autowired
    IUserPositionService iUserPositionService;
    @Autowired
    IUserBankService iUserBankService;
    @Resource
    AgentUserMapper agentUserMapper;
    @Resource
@@ -104,8 +96,6 @@
    IUserIndexPositionService iUserIndexPositionService;
    @Autowired
    ISiteIndexSettingService iSiteIndexSettingService;
    @Autowired
    StockPoll stockPoll;
    @Autowired
    StockSubscribeMapper stockSubscribeMapper;
@@ -114,18 +104,11 @@
    MoneyLogMapper mapper;
    @Resource
    IUserPositionService userPositionService;
    @Resource
    SiteAmtTransLogMapper siteAmtTransLogMapper;
    @Autowired
    IUserFuturesPositionService iUserFuturesPositionService;
    @Autowired
    ISiteFuturesSettingService iSiteFuturesSettingService;
    @Autowired
    IStockFuturesService iStockFuturesService;
    @Autowired
    ISiteMessageService iSiteMessageService;
    @Autowired
    private ApplyLeverMapper applyLeverMapper;
@@ -645,16 +628,20 @@
    @Override
    public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest request) {
        User user =  userService.getCurrentUser(request);
        UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId());
        BigDecimal amtBig = new BigDecimal(amt);
        if(formAssets.getAvailableBalance().compareTo(amtBig)<0){
            return ServerResponse.createByErrorMsg("余额不足",request);
        try {
            User user =  userService.getCurrentUser(request);
            UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId());
            BigDecimal amtBig = new BigDecimal(amt);
            if(formAssets.getAvailableBalance().compareTo(amtBig)<0){
                return ServerResponse.createByErrorMsg("余额不足",request);
            }
            userAssetsServices.availablebalanceChange(fromType,user.getId(), EUserAssets.TRANSFER,amtBig.negate(),fromType+"/"+toType,"");
            amtBig = rateServices.currencyRate(EStockType.getEStockTypeByCode(fromType),EStockType.getEStockTypeByCode(toType)).multiply(amtBig);
            userAssetsServices.availablebalanceChange(toType,user.getId(),EUserAssets.TRANSFER,amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,"");
            return ServerResponse.createBySuccess();
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
        userAssetsServices.availablebalanceChange(fromType,user.getId(), EUserAssets.TRANSFER,amtBig.negate(),fromType+"/"+toType,"");
        amtBig = rateServices.currencyRate(EStockType.getEStockTypeByCode(fromType),EStockType.getEStockTypeByCode(toType)).multiply(amtBig);
        userAssetsServices.availablebalanceChange(toType,user.getId(),EUserAssets.TRANSFER,amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,"");
        return ServerResponse.createBySuccess();
    }
@@ -792,48 +779,50 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse addSimulatedAccount(Integer agentId, String phone, String pwd, String amt, Integer accountType, HttpServletRequest request) {
        if (StringUtils.isBlank(phone) || StringUtils.isBlank(pwd)) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
        }
        try {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("phone",phone);
            User dbUser = userMapper.selectOne(queryWrapper);
            if (dbUser != null) {
                return ServerResponse.createByErrorMsg("The phone number is registered");
            }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("phone",phone);
        User dbUser = userMapper.selectOne(queryWrapper);
        if (dbUser != null) {
            return ServerResponse.createByErrorMsg("The phone number is registered");
            User user = new User();
            user.setAccountType(accountType);
            user.setPhone(phone);
            user.setIsLock(Integer.valueOf(0));
            user.setIsLogin(Integer.valueOf(0));
            user.setIsActive(Integer.valueOf(0));
            user.setRegTime(new Date());
            if (accountType.intValue() == 1) {
                user.setNickName("模拟用户");
            }
            if (agentId != null) {
                AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
                user.setAgentName(agentUser.getAgentName());
                user.setAgentId(agentUser.getId());
            }
            int insertCount = this.userMapper.insert(user);
            dbUser = userMapper.selectOne(queryWrapper);
            userAssetsServices.getAvailableBalance(EStockType.MX.getCode(),dbUser.getId() );
            userAssetsServices.availablebalanceChange(EStockType.MX.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"","");
            if (insertCount > 0) {
                return ServerResponse.createBySuccessMsg("Success");
            }
            return ServerResponse.createByErrorMsg("User addition failure");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
        User user = new User();
        user.setAccountType(accountType);
        user.setPhone(phone);
        user.setIsLock(Integer.valueOf(0));
        user.setIsLogin(Integer.valueOf(0));
        user.setIsActive(Integer.valueOf(0));
        user.setRegTime(new Date());
        if (accountType.intValue() == 1) {
            user.setNickName("模拟用户");
        }
        if (agentId != null) {
            AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
            user.setAgentName(agentUser.getAgentName());
            user.setAgentId(agentUser.getId());
        }
        int insertCount = this.userMapper.insert(user);
         dbUser = userMapper.selectOne(queryWrapper);
        userAssetsServices.getAvailableBalance(EStockType.MX.getCode(),dbUser.getId() );
        userAssetsServices.availablebalanceChange(EStockType.MX.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"","");
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("Success");
        }
        return ServerResponse.createByErrorMsg("User addition failure");
    }
@@ -903,7 +892,7 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse updateAmt(Integer userId, String amt, Integer direction) {
        if (userId == null || amt == null || direction == null) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
@@ -1145,6 +1134,12 @@
        userInfoVO.setIsActive(user.getIsActive());
        userInfoVO.setAuthMsg(user.getAuthMsg());
        userInfoVO.setVaildNumber(user.getVaildNumber());
        userInfoVO.setLoanLimit(user.getLoanLimit());
        userInfoVO.setCreditScore(user.getCreditScore());
        //查询代还款金额
        BigDecimal spMoney = dkMapper.sumSpMoneyByUserIdAndRStatus(String.valueOf(user.getId()));
        userInfoVO.setRefundAmount(spMoney);
        return userInfoVO;
    }
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -76,7 +76,7 @@
     * @return
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse insert(UserStockSubscribeAddIn model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if (model == null) {
@@ -230,7 +230,7 @@
     * admin 新股申购-添加和修改
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if( model.getId() != null  ){
@@ -479,50 +479,54 @@
     * 新股申购-用户提交金额
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse userSubmit(Integer id,HttpServletRequest request) {
        int ret = 0;
        String property = PropertiesUtil.getProperty("user.cookie.name");
        String header = request.getHeader(property);
        if (header != null) {
            User user = iUserService.getCurrentRefreshUser(request);
            if(id == null){
                return ServerResponse.createByErrorMsg("参数错误",request);
            }
            UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
            if (userStockSubscribe != null && userStockSubscribe.getUserId().equals(user.getId())) {
                if(userStockSubscribe.getType()== 2 ){
                    return ServerResponse.createByErrorMsg("未中签,无需支付",request);
        try {
            int ret = 0;
            String property = PropertiesUtil.getProperty("user.cookie.name");
            String header = request.getHeader(property);
            if (header != null) {
                User user = iUserService.getCurrentRefreshUser(request);
                if(id == null){
                    return ServerResponse.createByErrorMsg("参数错误",request);
                }
                if (userStockSubscribe.getStatus() == 3) {
                    StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe())
                            .eq("newlist_id", userStockSubscribe.getNewStockId()));
                    if (stockSubscribe == null) {
                        return ServerResponse.createByErrorMsg("新股不存在",request);
                UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
                if (userStockSubscribe != null && userStockSubscribe.getUserId().equals(user.getId())) {
                    if(userStockSubscribe.getType()== 2 ){
                        return ServerResponse.createByErrorMsg("未中签,无需支付",request);
                    }
                    userStockSubscribe.setSubmitTime(DateTimeUtil.getCurrentDate());
                    userStockSubscribe.setStatus(4);
                    BigDecimal bigDecimal =  iUserAssetsServices.
                            getAvailableBalance(EStockType.US.getCode(),
                                    userStockSubscribe.getUserId());
                    if (userStockSubscribe.getStatus() == 3) {
                        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe())
                                .eq("newlist_id", userStockSubscribe.getNewStockId()));
                        if (stockSubscribe == null) {
                            return ServerResponse.createByErrorMsg("新股不存在",request);
                        }
                        userStockSubscribe.setSubmitTime(DateTimeUtil.getCurrentDate());
                        userStockSubscribe.setStatus(4);
                        BigDecimal bigDecimal =  iUserAssetsServices.
                                getAvailableBalance(EStockType.US.getCode(),
                                        userStockSubscribe.getUserId());
                    BigDecimal multiply = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(userStockSubscribe.getApplyNumber()));
                    if(bigDecimal.compareTo(multiply) <= 0){
                        return ServerResponse.createByErrorMsg("余额不足",request);
                        BigDecimal multiply = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(userStockSubscribe.getApplyNumber()));
                        if(bigDecimal.compareTo(multiply) <= 0){
                            return ServerResponse.createByErrorMsg("余额不足",request);
                        }
                        iUserAssetsServices.availablebalanceChange(stockSubscribe.getStockType(), userStockSubscribe.getUserId(),
                                EUserAssets.BUY,multiply.negate(),"","");
                        userStockSubscribe.setDbMoney(BigDecimal.ZERO);
                        userStockSubscribeMapper.update1(userStockSubscribe);
                        return  ServerResponse.createBySuccess();
                    } else {
                        return ServerResponse.createByErrorMsg("不成功的申请者不收取任何费用",request);
                    }
                    iUserAssetsServices.availablebalanceChange(stockSubscribe.getStockType(), userStockSubscribe.getUserId(),
                            EUserAssets.BUY,multiply.negate(),"","");
                    userStockSubscribe.setDbMoney(BigDecimal.ZERO);
                    userStockSubscribeMapper.update1(userStockSubscribe);
                    return  ServerResponse.createBySuccess();
                } else {
                    return ServerResponse.createByErrorMsg("不成功的申请者不收取任何费用",request);
                    return ServerResponse.createByErrorMsg("新股认购订单不存在!",request);
                }
            } else {
                return ServerResponse.createByErrorMsg("新股认购订单不存在!",request);
            }
            return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
        return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
    }
    /**
     * 新股申购-删除
src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
@@ -102,7 +102,7 @@
    @Autowired
    TransferResponseService transferResponseService;
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse outMoney(String amt, String with_Pwd,String accsetType,String bankId,HttpServletRequest request) throws Exception {
        if (StringUtils.isBlank(amt)) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
@@ -335,7 +335,7 @@
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse updateState(Integer withId, Integer state, String authMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            UserWithdraw userWithdraw = this.userWithdrawMapper.selectByPrimaryKey(withId);
src/main/java/com/nq/utils/timeutil/DateTimeUtil.java
@@ -10,7 +10,9 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
@@ -242,10 +244,57 @@
    }
    /**
     * 计算 Date 到今天的天数(不足一天按一天算)
     * @param date 要比较的日期(可为 null)
     * @return 天数(至少为 1 天)
     */
    public static long getDaysRoundedUp(Date date) {
        if (date == null) {
            return 0; // 处理 null,返回 -1 或根据业务调整
        }
        // 获取当前时间(含时分秒)
        Instant now = Instant.now();
        Instant dateInstant = date.toInstant();
        // 计算毫秒差
        long millisDiff = now.toEpochMilli() - dateInstant.toEpochMilli();
        // 如果日期在未来,直接返回 1 天
        if (millisDiff <= 0) {
            millisDiff = Math.abs(millisDiff);
            //return 1;
        }
        // 一天的毫秒数
        long millisPerDay = 24 * 60 * 60 * 1000;
        // 向上取整:不足一天按一天算
        return (long) Math.ceil((double) millisDiff / millisPerDay);
    }
    public static void main(String[] args) {
        System.out.println(dateToStr1(new Date()));
    public static void main(String[] args) throws ParseException {
        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 指定格式
        // 测试:今天(不足一天按一天算)
        Date today = new Date();
        System.out.println("今天:" + getDaysRoundedUp(today)); // 输出:1
        // 测试:昨天(23小时前)
        String str = "2025-07-15 14:10:45";
        Date date = sdf.parse(str);
        System.out.println("昨天(23小时前):" + getDaysRoundedUp(date)); // 输出:1
        // 测试:3天前(72小时)
        String str2 = "2025-07-18 16:10:45";
        Date date2 = sdf.parse(str2);
        System.out.println("3天前:" + getDaysRoundedUp(date2)); // 输出:3
        String str3 = "2025-07-19 16:10:45";
        Date date3 = sdf.parse(str3);
        System.out.println("未来(1天后):" + getDaysRoundedUp(date3)); // 输出:1*/
    }
}
src/main/java/com/nq/vo/dk/DkModelVo.java
@@ -2,10 +2,12 @@
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class DkModelVo {
    private Integer id;
@@ -29,87 +31,13 @@
    private String dkJgName;
    public String getDkJgName() {
        return dkJgName;
    }
    public void setDkJgName(String dkJgName) {
        this.dkJgName = dkJgName;
    }
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    public Integer getId() {
        return id;
    }
    //还款状态:0未还款 1已还款
    private Integer dkRefundState;
    public void setId(Integer id) {
        this.id = id;
    }
    //放款时间
    private Date loanTime;
    public String getDkMoney() {
        return dkMoney;
    }
    public void setDkMoney(String dkMoney) {
        this.dkMoney = dkMoney;
    }
    public String getSpMoney() {
        return spMoney;
    }
    public void setSpMoney(String spMoney) {
        this.spMoney = spMoney;
    }
    public String getDkUserId() {
        return dkUserId;
    }
    public void setDkUserId(String dkUserId) {
        this.dkUserId = dkUserId;
    }
    public String getDkState() {
        return dkState;
    }
    public void setDkState(String dkState) {
        this.dkState = dkState;
    }
    public String getDkMessage() {
        return dkMessage;
    }
    public void setDkMessage(String dkMessage) {
        this.dkMessage = dkMessage;
    }
    public String getDkPhone() {
        return dkPhone;
    }
    public void setDkPhone(String dkPhone) {
        this.dkPhone = dkPhone;
    }
    public String getDkUserName() {
        return dkUserName;
    }
    public void setDkUserName(String dkUserName) {
        this.dkUserName = dkUserName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
src/main/java/com/nq/vo/stock/StockVOQuery.java
New file
@@ -0,0 +1,19 @@
package com.nq.vo.stock;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class StockVOQuery {
    private int id;
    private String StockName;
    private String stockCode;
    private String stockSpell;
    private String stockType;
    private BigDecimal nowPrice;
}
src/main/java/com/nq/vo/user/UserInfoVO.java
@@ -69,6 +69,12 @@
    private String usTotalAssets;
    //信用分
    private Integer creditScore;
    //剩余贷款额度
    private BigDecimal loanLimit;
    //待还款金额
    private BigDecimal refundAmount;
}
src/main/resources/mapper/DkMapper.xml
@@ -22,9 +22,11 @@
        <result column="dk_user_id" property="dkUserId"/>
        <result column="dk_state" property="dkState"/>
        <result column="dk_message" property="dkMessage"/>
        <result  column="agent_name" property="dkUserName"/>
        <result column="dk_phone"  property="dkPhone"/>
        <result  column="real_name" property="dkUserName"/>
        <result column="phone"  property="dkPhone"/>
        <result column="dk_jg" property="dkJgName"/>
        <result column="dk_refund_state" property="dkRefundState"/>
        <result column="loan_time" property="loanTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
@@ -39,40 +41,30 @@
    <select id="queryDk" resultMap="BaseResultMap1">
        select d.id,
               d.dk_money,
               d.sp_money,
               d.create_time,
               d.dk_user_id,
               d.dk_state,
               d.dk_phone,
               d.dk_message,
               u.agent_name
            d.dk_money,
            d.sp_money,
            d.create_time,
            d.dk_user_id,
            d.dk_state,
            d.dk_phone,
            d.dk_message,
            u.real_name,
            u.phone,
            d.dk_refund_state,
            d.loan_time
        from dk d
                 join user u
                      on d.dk_user_id = u.id
        left join user u on d.dk_user_id = u.id
        ORDER BY d.create_time desc
    </select>
    <select id="countByUserIdAndRStatus" resultType="java.lang.Integer">
        select count(1) from dk
        where dk_user_id = #{userId} and dk_state = #{rStatus}
    </select>
    <select id="queryByShUserId" resultMap="BaseResultMap1" parameterType="String">
        select d.id,
               d.dk_money,
               d.sp_money,
               d.create_time,
               d.dk_user_id,
               d.dk_state,
               d.dk_message,
               d.dk_phone,
               u.agent_name,
               d.dk_jg_id,
               jg.dk_jg
        from dk d
                 join user u
                      on d.dk_user_id = u.id
                 join  dk_jg jg  on  jg.id =  d.dk_jg_id
        where d.dk_user_id = #{id}
    <select id="sumSpMoneyByUserIdAndRStatus" resultType="java.math.BigDecimal">
        SELECT IFNULL(sum(sp_money),0) FROM `dk`
        where dk_user_id = #{userId} and dk_state='1' and dk_refund_state = 0
    </select>
</mapper>
src/main/resources/mapper/StockMapper.xml
@@ -357,6 +357,11 @@
    </if>
  </select>
  <select id="findStocksQuery" resultType="com.nq.vo.stock.StockVOQuery">
    SELECT id,stock_name,stock_code,stock_spell,stock_type FROM stock
    WHERE stock_spell like concat('%',#{keyWords},'%')  or stock_name like concat('%',#{keyWords},'%')
       or stock_code like concat('%',#{keyWords},'%')
  </select>
</mapper>
src/main/resources/mapper/UserMapper.xml
@@ -32,7 +32,7 @@
    id, agent_id, agent_name, phone, user_pwd, with_pwd, nick_name, real_name, id_card, 
    account_type, is_lock, is_login,
    reg_time, reg_ip, reg_address, img1_key, img2_key, img3_key, is_active, auth_msg,
    withdrawal_Pwd,vaild_number,lever,fund_ratio
    withdrawal_Pwd,vaild_number,lever,fund_ratio,credit_score,loan_limit
  </sql>