44 files modified
1 files added
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | 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"}) |
| | |
| | | @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); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.nq.utils.PropertiesUtil; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 后台贷款列表 |
| | | * @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 |
| | | public ServerResponse insertDkJg(@RequestParam("name") String name){ |
| | |
| | | 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.*; |
| | |
| | | |
| | | @Autowired |
| | | IStockAiService stockAiService; |
| | | @Autowired |
| | | IStockService stockService; |
| | | /** |
| | | * 获取ai交易产品列表 |
| | | * @return |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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") |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | |
| | | 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 |
| | |
| | | |
| | | List<DkModelVo> queryDk(); |
| | | |
| | | int countByUserIdAndRStatus(@Param("userId") String userId, @Param("rStatus") Integer rStatus); |
| | | |
| | | List<DkModelVo> queryByShUserId(String id); |
| | | BigDecimal sumSpMoneyByUserIdAndRStatus(@Param("userId") String userId); |
| | | } |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | List<StockDz> findStockTypeDz(@Param("orderBy") String orderBy, @Param("keyWords") String keyWords , @Param("formatDate") String formatDate); |
| | | |
| | | List<StockVOQuery> findStocksQuery(@Param("keyWords") String keyWords); |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | } |
| | |
| | | public class StockAI { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | //@GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | @TableId(type = IdType.AUTO,value = "id") |
| | | private Integer id; |
| | | |
| | | //股票类型 |
| | |
| | | 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; |
| | | |
| | |
| | | public class StockAIOrder { |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | //@GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | @TableId(type = IdType.AUTO,value = "id") |
| | | private Integer id; |
| | | |
| | | //用户id |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | /** |
| | | * 建仓时间 |
| | | */ |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date creatDate; |
| | | |
| | | /** |
| | |
| | | private String lever; |
| | | private String fundRatio; |
| | | |
| | | |
| | | //信用分 |
| | | private Integer creditScore; |
| | | //贷款额度 |
| | | private BigDecimal loanLimit; |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | * @return |
| | | */ |
| | | ServerResponse getIndicesAndKData(String pid, String stockType); |
| | | |
| | | ServerResponse getStocksByKeyWords(int pageNum, int pageSize, String keyWords); |
| | | } |
| | |
| | | * @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交易 |
| | |
| | | * @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; |
| | | |
| | | /** |
| | | * 根据汇率转换金额 |
| | |
| | | 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; |
| | |
| | | ServerResponse getDzOrderList(int pageNum, int pageSize, Integer status, HttpServletRequest request); |
| | | |
| | | ServerResponse getMyPositionProfitAndLose(HttpServletRequest request); |
| | | |
| | | ServerResponse checkDz(Integer id, Integer checkType, Integer orderNum, HttpServletRequest request); |
| | | } |
| | |
| | | } |
| | | |
| | | /*代理账户扣款*/ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse updateAgentAmt(Integer agentId, Integer amt, Integer direction) { |
| | | if (agentId == null || amt == null || direction == null) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ServerResponse examineApplyLever(String id,String states, HttpServletRequest request) { |
| | | ApplyLever applyLever = applyLeverMapper.selectById(id); |
| | |
| | | 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) { |
| | | public ServerResponse addDk(BigDecimal dkMoney, String phone, String dkjgId, HttpServletRequest request) { |
| | | try { |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | | return false; |
| | | 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(user.getId() + ""); |
| | | dkModel.setCreateTime(DateTimeUtil.strToDate(DateTimeUtil.dateToStr(new Date()))); |
| | | dkModel.setDkMoney(dkMoney); |
| | | 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 true; |
| | | return ServerResponse.createBySuccess("贷款申请成功", request); |
| | | } catch (Exception e) { |
| | | log.error("IDkServices addDk error", e); |
| | | } |
| | | 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) { |
| | | |
| | | |
| | | @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 false; |
| | | 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(state + ""); |
| | | dkModel.setSpMoney(shMoney + ""); |
| | | } |
| | | dkModel.setDkState(String.valueOf(state)); |
| | | dkMapper.updateById(dkModel); |
| | | return true; |
| | | return ServerResponse.createBySuccess("贷款审核成功"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("IDkServices dksp error", e); |
| | | } |
| | | 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 |
| | |
| | | return mapper.queryAll(); |
| | | } |
| | | |
| | | |
| | | public List<DkModelVo> queryByShUserId(HttpServletRequest httpServletRequest) { |
| | | /** |
| | | * 贷款记录 |
| | | * @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); |
| | | return dkMapper.queryByShUserId(user.getId()+""); |
| | | 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 |
| | |
| | | /** |
| | | * 配资追加申请-保存 |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse save(FundsAppend model, HttpServletRequest request) { |
| | | int ret = 0; |
| | | if(model.getApplyId() == null || model.getApplyId() == 0){ |
| | |
| | | IFundsSettingService iFundsSettingService; |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse insert(FundsApply model, HttpServletRequest request) throws Exception { |
| | | int ret = 0; |
| | | if (model == null) { |
| | |
| | | /** |
| | | * 配资申请-审核 |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse audit(FundsApply model, HttpServletRequest request) throws Exception { |
| | | return ServerResponse.createByErrorMsg("操作失败"); |
| | | } |
| | |
| | | @Resource |
| | | UserPositionMapper userPositionMapper; |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void RealTimeDataProcess(EStockType eStockType, StockRealTimeBean timeBean) { |
| | | QueryWrapper<UserPosition> upQuery = new QueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | |
| | | @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); |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Service("iStockAiService") |
| | |
| | | * @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()); |
| | |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | } |
| | | return ServerResponse.createBySuccess("操作成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | |
| | | @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) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse orderOperation(Long id, String status) { |
| | | try { |
| | | Object lock = locks.computeIfAbsent(id, k -> new Object()); |
| | |
| | | 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("只能结算申请通过订单"); |
| | |
| | | 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()); |
| | |
| | | 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; |
| | | |
| | |
| | | } |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | @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); |
| | |
| | | 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())); |
| | |
| | | } |
| | | |
| | | |
| | | 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); |
| | | //如果不是墨西哥币需要转换金额 |
| | |
| | | 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(); |
| | |
| | | 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()); |
| | |
| | | /** |
| | | * 分仓交易-入仓 |
| | | */ |
| | | @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"); |
| | | } |
| | |
| | | /* |
| | | * 分仓交易-用户平仓操作 |
| | | * */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse sellFunds(String positionSn, int doType) throws Exception { |
| | | log.info("【用户交易平仓】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType)); |
| | | |
| | |
| | | @Autowired |
| | | ISiteProductService iSiteProductService; |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse buyFutures(Integer futuresId, Integer buyNum, Integer buyType, Integer lever, HttpServletRequest request) throws Exception { |
| | | |
| | | |
| | |
| | | @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 { |
| | | |
| | | |
| | |
| | | * @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("参数不能为空"); |
| | |
| | | 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!"); |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | |
| | | |
| | | @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); |
| | | try { |
| | | synchronized (user.getId()){ |
| | | if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) { |
| | | return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request); |
| | |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | } |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse sell(String positionSn, int doType) { |
| | | try { |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在"); |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | private ServerResponse<Object> getObjectServerResponse(HttpServletRequest request, UserPosition userPosition, BigDecimal nowPrice, BigDecimal siitteBuyFee, Stock stock) { |
| | | try { |
| | | userPosition.setSellOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setSellOrderPrice(nowPrice); |
| | | userPosition.setSellOrderTime(new Date()); |
| | |
| | | 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 { |
| | | //判断股票是否在可交易时间段 |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse closingStayTask(UserPosition position, Integer stayDays) throws Exception { |
| | | log.info("=================closingStayTask===================="); |
| | | log.info("修改留仓费,持仓id={},持仓天数={}", position.getId(), stayDays); |
| | |
| | | * @Date: 2022/10/26 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse newStockToPosition(Integer id,BigDecimal amountToBeCovered) { |
| | | try { |
| | | UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id); |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("无该申购记录"); |
| | |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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 { |
| | | |
| | | /*实名认证开关开启*/ |
| | |
| | | * @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(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void stockConstraint(List<UserPosition> list) { |
| | | try { |
| | | //SiteSetting siteSetting = iSiteSettingService.getSiteSetting(); |
| | |
| | | |
| | | //平仓 |
| | | private void extracted(UserPosition position, BigDecimal nowPrice, Stock stock,Integer liquidation) { |
| | | 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())); |
| | |
| | | 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()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse chargeSuccess(UserRecharge userRecharge) throws Exception { |
| | | log.info("充值订单 确认成功操作 id = {}", userRecharge.getId()); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse updateState(Integer chargeId, Integer state) throws Exception { |
| | | UserRecharge userRecharge = this.userRechargeMapper.selectById(chargeId); |
| | | |
| | |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | | |
| | | try { |
| | | User user = this.userMapper.selectById(userId); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("找不到用户"); |
| | |
| | | return ServerResponse.createBySuccessMsg("生成订单成功!"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("生成订单失败,请重试"); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @Resource |
| | | StockOptionMapper stockOptionMapper; |
| | | |
| | | @Autowired |
| | | DkMapper dkMapper; |
| | | |
| | | |
| | | @Autowired |
| | | IUserService userService; |
| | |
| | | StockMapper stockMapper; |
| | | @Autowired |
| | | IUserPositionService iUserPositionService; |
| | | @Autowired |
| | | IUserBankService iUserBankService; |
| | | @Resource |
| | | AgentUserMapper agentUserMapper; |
| | | @Resource |
| | |
| | | IUserIndexPositionService iUserIndexPositionService; |
| | | @Autowired |
| | | ISiteIndexSettingService iSiteIndexSettingService; |
| | | @Autowired |
| | | StockPoll stockPoll; |
| | | |
| | | @Autowired |
| | | StockSubscribeMapper stockSubscribeMapper; |
| | |
| | | MoneyLogMapper mapper; |
| | | |
| | | @Resource |
| | | IUserPositionService userPositionService; |
| | | @Resource |
| | | SiteAmtTransLogMapper siteAmtTransLogMapper; |
| | | @Autowired |
| | | IUserFuturesPositionService iUserFuturesPositionService; |
| | | @Autowired |
| | | ISiteFuturesSettingService iSiteFuturesSettingService; |
| | | @Autowired |
| | | IStockFuturesService iStockFuturesService; |
| | | |
| | | @Autowired |
| | | ISiteMessageService iSiteMessageService; |
| | | |
| | | @Autowired |
| | | private ApplyLeverMapper applyLeverMapper; |
| | |
| | | |
| | | @Override |
| | | public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest request) { |
| | | try { |
| | | User user = userService.getCurrentUser(request); |
| | | UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId()); |
| | | BigDecimal amtBig = new BigDecimal(amt); |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @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"); |
| | | } |
| | | |
| | | |
| | | User user = new User(); |
| | | user.setAccountType(accountType); |
| | |
| | | return ServerResponse.createBySuccessMsg("Success"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("User addition failure"); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @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"); |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse insert(UserStockSubscribeAddIn model, HttpServletRequest request) throws Exception { |
| | | int ret = 0; |
| | | if (model == null) { |
| | |
| | | * admin 新股申购-添加和修改 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception { |
| | | int ret = 0; |
| | | if( model.getId() != null ){ |
| | |
| | | * 新股申购-用户提交金额 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse userSubmit(Integer id,HttpServletRequest request) { |
| | | try { |
| | | int ret = 0; |
| | | String property = PropertiesUtil.getProperty("user.cookie.name"); |
| | | String header = request.getHeader(property); |
| | |
| | | } |
| | | } |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | /** |
| | | * 新股申购-删除 |
| | |
| | | @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"); |
| | |
| | | } |
| | | |
| | | |
| | | @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); |
| | |
| | | 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; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算 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*/ |
| | | } |
| | | } |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | 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; |
| | | } |
| | | } |
| New file |
| | |
| | | |
| | | 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; |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | private String usTotalAssets; |
| | | |
| | | //信用分 |
| | | private Integer creditScore; |
| | | //剩余贷款额度 |
| | | private BigDecimal loanLimit; |
| | | //待还款金额 |
| | | private BigDecimal refundAmount; |
| | | |
| | | |
| | | } |
| | |
| | | <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 |
| | |
| | | d.dk_state, |
| | | d.dk_phone, |
| | | d.dk_message, |
| | | u.agent_name |
| | | 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> |
| | |
| | | </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> |
| | |
| | | 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> |
| | | |
| | | |