|
|
@@ -0,0 +1,241 @@
|
|
|
+package com.muchinfo.mtp3century.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.muchinfo.mtp3century.service.ICommonService;
|
|
|
+import com.muchinfo.mtp3century.service.ITradingWarehouseSetService;
|
|
|
+import com.muchinfo.mtp3century.utils.AjaxResult;
|
|
|
+import com.muchinfo.mtp3common.enumtype.Constants;
|
|
|
+import com.muchinfo.mtp3common.enumtype.MessageType;
|
|
|
+import com.muchinfo.mtp3common.enumtype.SysConstants;
|
|
|
+import com.muchinfo.mtp3common.vo.PageResult;
|
|
|
+import com.muchinfo.mtp3interface.mapper.*;
|
|
|
+import com.muchinfo.mtp3pojos.entity.*;
|
|
|
+import com.muchinfo.mtp3pojos.vo.tradingmarket.MarketRunSectiionResult;
|
|
|
+import com.muchinfo.mtp3pojos.vo.tradingmarket.SpotFulfillmentDelParam;
|
|
|
+import com.muchinfo.mtp3pojos.vo.tradingmarket.SpotFulfillmentResult;
|
|
|
+import com.muchinfo.mtp3pojos.vo.tradingmarket.SpotFulfillmentViewResult;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class TradingWarehouseSetServiceImpl implements ITradingWarehouseSetService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ICommonService iCommonService;
|
|
|
+ @Resource
|
|
|
+ private ISystemmanagerMapper iSystemmanagerMapper;
|
|
|
+ @Resource
|
|
|
+ private IPerformanceplantemplateMapper iPerformanceplantemplateMapper;
|
|
|
+ @Resource
|
|
|
+ private IPerformancesteptemplateMapper iPerformancesteptemplateMapper;
|
|
|
+ @Resource
|
|
|
+ private IMarketMapper iMarketMapper;
|
|
|
+ @Resource
|
|
|
+ private IMarketrunstepdetailMapper iMarketrunstepdetailMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<SpotFulfillmentResult> querySpotFulfillment(Integer pageNum, Integer pageSize, HttpServletRequest request) {
|
|
|
+ PageResult<SpotFulfillmentResult> pageResult = new PageResult<>();
|
|
|
+ IPage<SpotFulfillmentResult> page = new Page<>(pageNum, pageSize);
|
|
|
+ IPage<SpotFulfillmentResult> resultIPage = iPerformanceplantemplateMapper.querySpotFulfillment(page, 2);
|
|
|
+ pageResult.setCode(Constants.Success_Code_Design);
|
|
|
+ pageResult.setMessage(AjaxResult.dealMsg(MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language")));
|
|
|
+ pageResult.setPages(resultIPage.getPages());
|
|
|
+ pageResult.setCurrent(resultIPage.getCurrent());
|
|
|
+ pageResult.setTotal(resultIPage.getTotal());
|
|
|
+ pageResult.setPageSize(resultIPage.getSize());
|
|
|
+ pageResult.setData(resultIPage.getRecords());
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult<SpotFulfillmentViewResult> spotFulfillmentView(Long autoid, HttpServletRequest request) {
|
|
|
+ SpotFulfillmentViewResult param = new SpotFulfillmentViewResult();
|
|
|
+ Performanceplantemplate plantemplate = iPerformanceplantemplateMapper.selectById(autoid);
|
|
|
+ param.setParam(plantemplate);
|
|
|
+ List<Performancesteptemplate> pstList = iPerformanceplantemplateMapper.getPerformanceStepByTmpId(autoid);
|
|
|
+ if (CollectionUtils.isNotEmpty(pstList)) {
|
|
|
+ pstList.sort(new Comparator<Performancesteptemplate>() {
|
|
|
+ @Override
|
|
|
+ public int compare(Performancesteptemplate arg0, Performancesteptemplate arg1) {
|
|
|
+ return arg0.getStepindex() - arg1.getStepindex();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ param.setPerformancesteps(pstList);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(Constants.Success_Code_Design, MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language"), param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult spotFulfillmentDel(SpotFulfillmentDelParam param, HttpServletRequest request) {
|
|
|
+ Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
|
|
|
+
|
|
|
+ AjaxResult ajaxResult = check(param, request);
|
|
|
+ if (ajaxResult.getCode() == 500) {
|
|
|
+ return ajaxResult;
|
|
|
+ }
|
|
|
+ if (param.getAutoid() == null) {
|
|
|
+ Performanceplantemplate plantemplate = new Performanceplantemplate();
|
|
|
+ BeanUtils.copyProperties(param, plantemplate);
|
|
|
+ plantemplate.setCreatorid(systemmanager.getAutoid());
|
|
|
+ plantemplate.setCreatetime(new Date());
|
|
|
+ if (plantemplate.getUserid() == null) {
|
|
|
+ plantemplate.setUserid(1L);
|
|
|
+ }
|
|
|
+ iPerformanceplantemplateMapper.insert(plantemplate);
|
|
|
+ for (Performancesteptemplate pst : param.getList()) {
|
|
|
+ Performancesteptemplate steptemplate = new Performancesteptemplate();
|
|
|
+ BeanUtils.copyProperties(pst, steptemplate);
|
|
|
+ steptemplate.setTemplateid(plantemplate.getAutoid());
|
|
|
+ if (steptemplate.getStepvalue() != null) {
|
|
|
+ steptemplate.setStepvalue(steptemplate.getStepvalue().divide(new BigDecimal(100)));
|
|
|
+ }
|
|
|
+ if (pst.getIsauto() == null) {
|
|
|
+ steptemplate.setIsauto(0);
|
|
|
+ }
|
|
|
+ iPerformancesteptemplateMapper.insert(steptemplate);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Performanceplantemplate plantemplate = iPerformanceplantemplateMapper.selectById(param.getAutoid());
|
|
|
+ plantemplate.setPaymenttype(param.getPaymenttype());
|
|
|
+ plantemplate.setTemplatename(param.getTemplatename());
|
|
|
+ plantemplate.setTakemode(param.getTakemode());
|
|
|
+ iPerformanceplantemplateMapper.updateById(plantemplate);
|
|
|
+ //履约步骤先删除再插入
|
|
|
+ iPerformancesteptemplateMapper.delete(new QueryWrapper<Performancesteptemplate>().eq("templateid", param.getAutoid()));
|
|
|
+ for (Performancesteptemplate pst : param.getList()) {
|
|
|
+ Performancesteptemplate steptemplate = new Performancesteptemplate();
|
|
|
+ BeanUtils.copyProperties(pst, steptemplate);
|
|
|
+ steptemplate.setTemplateid(plantemplate.getAutoid());
|
|
|
+ if (steptemplate.getStepvalue() != null) {
|
|
|
+ steptemplate.setStepvalue(steptemplate.getStepvalue().divide(new BigDecimal(100)));
|
|
|
+ }
|
|
|
+ if (pst.getIsauto() == null) {
|
|
|
+ steptemplate.setIsauto(0);
|
|
|
+ }
|
|
|
+ iPerformancesteptemplateMapper.insert(steptemplate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ajaxResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult<Market> marketrunsectiion(HttpServletRequest request) {
|
|
|
+ List<Integer> status = new ArrayList<>();
|
|
|
+ status.add(1);
|
|
|
+ status.add(2);
|
|
|
+ //处理不同的账户类型查询
|
|
|
+ Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
|
|
|
+ Long exchareaid = null;
|
|
|
+ //如果不是平台管理员
|
|
|
+ if (!SysConstants.SYS_TYPE_MANAGE.equals(systemmanager.getReletype())) {
|
|
|
+ exchareaid = systemmanager.getAreauserid();
|
|
|
+ }
|
|
|
+ List<Market> markets = iMarketMapper.getMarketsByTradeMode(exchareaid, status);
|
|
|
+ return AjaxResult.success(Constants.Success_Code_Design, MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language"), markets);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<MarketRunSectiionResult> querymarketrunsectiion(Integer pageNum, Integer pageSize, HttpServletRequest request) {
|
|
|
+ Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
|
|
|
+ Long exchareaid = null;
|
|
|
+ //如果不是平台管理员
|
|
|
+ if (!SysConstants.SYS_TYPE_MANAGE.equals(systemmanager.getReletype())) {
|
|
|
+ exchareaid = systemmanager.getAreauserid();
|
|
|
+ }
|
|
|
+ PageResult<MarketRunSectiionResult> pageResult = new PageResult<>();
|
|
|
+ IPage<MarketRunSectiionResult> page = new Page<>(pageNum, pageSize);
|
|
|
+ IPage<MarketRunSectiionResult> resultIPage = iMarketMapper.querymarketrunsectiion(page, 3, exchareaid);
|
|
|
+ pageResult.setCode(Constants.Success_Code_Design);
|
|
|
+ pageResult.setMessage(AjaxResult.dealMsg(MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language")));
|
|
|
+ pageResult.setPages(resultIPage.getPages());
|
|
|
+ pageResult.setCurrent(resultIPage.getCurrent());
|
|
|
+ pageResult.setTotal(resultIPage.getTotal());
|
|
|
+ pageResult.setPageSize(resultIPage.getSize());
|
|
|
+ pageResult.setData(resultIPage.getRecords());
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult<Map<Integer, List<Marketrunstepdetail>>> queryMarketRunSectiionById(Long markerid, HttpServletRequest request) {
|
|
|
+ List<Marketrunstepdetail> list = iMarketrunstepdetailMapper.selectList(new QueryWrapper<Marketrunstepdetail>()
|
|
|
+ .eq("marketid", markerid));
|
|
|
+ Map<Integer, List<Marketrunstepdetail>> group = new HashMap<>();
|
|
|
+ for(Marketrunstepdetail item:list){
|
|
|
+ if(item !=null && item.getTradeweekday() !=null){
|
|
|
+ if(group.containsKey(item.getTradeweekday())){
|
|
|
+ group.get(item.getTradeweekday()).add(item);
|
|
|
+ }else{
|
|
|
+ List<Marketrunstepdetail> list_ = new ArrayList<>();
|
|
|
+ list_.add(item);
|
|
|
+ group.put(item.getTradeweekday(), list_);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.success(Constants.Success_Code_Design, MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language"), group);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AjaxResult check(SpotFulfillmentDelParam param, HttpServletRequest request) {
|
|
|
+ Performanceplantemplate p = iPerformanceplantemplateMapper.selectOne(new QueryWrapper<Performanceplantemplate>()
|
|
|
+ .eq("templatename", param.getTemplatename())
|
|
|
+ .eq("autoid", param.getAutoid()));
|
|
|
+ if (p != null) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM056.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ BigDecimal buysum = BigDecimal.ZERO;
|
|
|
+ BigDecimal sellsum = BigDecimal.ZERO;
|
|
|
+ Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
|
|
+ int i = 0;
|
|
|
+ for (Performancesteptemplate pst : param.getList()) {
|
|
|
+ i++;
|
|
|
+ if (pst.getSteptypeid() == 1 || pst.getSteptypeid() == 92) {
|
|
|
+ buysum = buysum.add(pst.getStepvalue());
|
|
|
+ }
|
|
|
+ if (pst.getSteptypeid() == 2) {
|
|
|
+ sellsum = sellsum.add(pst.getStepvalue());
|
|
|
+ }
|
|
|
+ if (sellsum.compareTo(buysum) > 0) {
|
|
|
+ Object[] str = {i};
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM057.getCode(), str, request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ if (pst.getSteptypeid() == 5 && !map.containsKey(4)) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM058.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ if (pst.getSteptypeid() == 7 && !map.containsKey(6)) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM059.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ map.put(pst.getSteptypeid(), pst.getSteptypeid());
|
|
|
+ }
|
|
|
+ if (buysum.compareTo(BigDecimal.valueOf(100)) != 0) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM060.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ if (sellsum.compareTo(BigDecimal.valueOf(100)) != 0) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM061.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ i = 0;
|
|
|
+ if (map.containsKey(3)) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (map.containsKey(4)) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (map.containsKey(8)) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (i != 1) {
|
|
|
+ return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM062.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+ return AjaxResult.success(Constants.Success_Code_Design, MessageType.MESSAGE_CODE_SYSTEM001.getCode(), request.getHeader("Accept-Language"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|