|  | @@ -11,14 +11,18 @@ import com.ym.mec.biz.dal.dto.ReplacementPayDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.page.ReplacementInstrumentActivityQueryInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.page.ReplacementInstrumentQueryInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.page.QueryInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  | +import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import com.ym.mec.util.http.HttpUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
	
		
			
				|  | @@ -29,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrumentActivity> implements ReplacementInstrumentActivityService {
 | 
	
	
		
			
				|  | @@ -66,6 +71,14 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private ReplacementInstrumentCooperationDao replacementInstrumentCooperationDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | +    private GoodsDao goodsDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private GoodsService goodsService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysPaymentConfigService sysPaymentConfigService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SellOrderDao sellOrderDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private QuestionnaireUserResultDao questionnaireUserResultDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private QuestionnaireQuestionDao questionnaireQuestionDao;
 | 
	
	
		
			
				|  | @@ -86,6 +99,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          if (sysUser == null) {
 | 
	
		
			
				|  |  |              throw new BizException("用户信息获取失败,请重新登陆");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        replacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  |          replacementInstrumentActivity.setUserId(sysUser.getId());
 | 
	
		
			
				|  |  |          //如果用户是43分部,那么修改用户信息
 | 
	
		
			
				|  |  |          if (sysUser.getOrganId() == 43) {
 | 
	
	
		
			
				|  | @@ -96,9 +110,9 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |                  sysUserFeignService.updateSysUser(sysUser);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.getByCooperationId(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  | +        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.get(replacementInstrumentActivity.getReplacementInstrumentCooperationId());
 | 
	
		
			
				|  |  |          //如果提交过调查问卷,那么覆盖之前的记录
 | 
	
		
			
				|  |  | -        ReplacementInstrumentActivity activity = replacementInstrumentActivityDao.findByUserId(replacementInstrumentActivity.getCooperationOrganId(), sysUser.getId(),replacementInstrumentCooperation.getTopicId());
 | 
	
		
			
				|  |  | +        ReplacementInstrumentActivity activity = replacementInstrumentActivityDao.findByUserId(replacementInstrumentActivity.getCooperationOrganId(), sysUser.getId(),replacementInstrumentCooperation.getId());
 | 
	
		
			
				|  |  |          if (replacementInstrumentCooperation != null && replacementInstrumentCooperation.getOpenPay().equals(YesOrNoEnum.YES)) {
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setOpenFlag(1);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -119,7 +133,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //已开启缴费推送购买链接
 | 
	
		
			
				|  |  |          if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
 | 
	
		
			
				|  |  | -            ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | +            //换成商品列表中商品4.25
 | 
	
		
			
				|  |  | +            Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
 | 
	
		
			
				|  |  |              Map<Integer, String> userMap = new HashMap<>();
 | 
	
		
			
				|  |  |              Map<Integer, String> userPhoneMap = new HashMap<>();
 | 
	
		
			
				|  |  |              Integer userId = replacementInstrumentActivity.getUserId();
 | 
	
	
		
			
				|  | @@ -127,11 +142,11 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
 | 
	
		
			
				|  |  |              userMap.put(userId, userId.toString());
 | 
	
		
			
				|  |  |              sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
 | 
	
		
			
				|  |  | -                    userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", replacementInstrument.getBrand(), "");
 | 
	
		
			
				|  |  | +                    userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              userPhoneMap.put(replacementInstrumentActivity.getUserId(), replacementInstrumentActivity.getMobileNo());
 | 
	
		
			
				|  |  |              sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
 | 
	
		
			
				|  |  | -                    userPhoneMap, null, 0, null, "STUDENT", replacementInstrument.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
 | 
	
		
			
				|  |  | +                    userPhoneMap, null, 0, null, "STUDENT", goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return replacementInstrumentActivity;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -145,10 +160,11 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          if (sysUser == null) {
 | 
	
		
			
				|  |  |              throw new BizException("用户信息获取失败,请重新登陆");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        replacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  |          replacementInstrumentActivity.setUserId(sysUser.getId());
 | 
	
		
			
				|  |  |          //如果用户是43分部,那么修改用户信息
 | 
	
		
			
				|  |  | +        CooperationOrgan cooperationOrgan = cooperationOrganService.get(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  |          if (sysUser.getOrganId() == 43) {
 | 
	
		
			
				|  |  | -            CooperationOrgan cooperationOrgan = cooperationOrganService.get(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  |              if (cooperationOrgan != null) {
 | 
	
		
			
				|  |  |                  sysUser.setOrganId(cooperationOrgan.getOrganId());
 | 
	
		
			
				|  |  |                  sysUser.setUpdateTime(new Date());
 | 
	
	
		
			
				|  | @@ -156,9 +172,11 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          Integer topicId = replacementInstrumentActivity.getTopicId();
 | 
	
		
			
				|  |  | -        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.getByCooperationId(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  | +        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.get(replacementInstrumentActivity.getReplacementInstrumentCooperationId());
 | 
	
		
			
				|  |  |          //如果提交过调查问卷,那么覆盖之前的记录
 | 
	
		
			
				|  |  | -        ReplacementInstrumentActivity activity = replacementInstrumentActivityDao.findByUserId(replacementInstrumentActivity.getCooperationOrganId(), sysUser.getId(),replacementInstrumentCooperation.getTopicId());
 | 
	
		
			
				|  |  | +        ReplacementInstrumentActivity activity = replacementInstrumentActivityDao.findByUserId(replacementInstrumentActivity.getCooperationOrganId(),
 | 
	
		
			
				|  |  | +                sysUser.getId(),
 | 
	
		
			
				|  |  | +                replacementInstrumentCooperation.getId());
 | 
	
		
			
				|  |  |          if (replacementInstrumentCooperation != null && replacementInstrumentCooperation.getOpenPay().equals(YesOrNoEnum.YES)) {
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setOpenFlag(1);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -184,14 +202,18 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              sendPush = true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if(questionnaireUserResultList != null && questionnaireUserResultList.size() > 0){
 | 
	
		
			
				|  |  | +            for (QuestionnaireUserResult result : questionnaireUserResultList) {
 | 
	
		
			
				|  |  | +                result.setUserId(sysUser.getId());
 | 
	
		
			
				|  |  | +                result.setQuestionnaireTopicId(topicId);
 | 
	
		
			
				|  |  | +                result.setActiveType(QuestionnaireActiveTypeEnum.REPLACEMENT);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //新增问卷结果
 | 
	
		
			
				|  |  | -            questionnaireUserResultDao.batchInsert(questionnaireUserResultList,
 | 
	
		
			
				|  |  | -                    QuestionnaireActiveTypeEnum.REPLACEMENT.getCode(),
 | 
	
		
			
				|  |  | -                    topicId,activity.getId());
 | 
	
		
			
				|  |  | +            questionnaireUserResultDao.batchInsert1(questionnaireUserResultList);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //已开启缴费推送购买链接
 | 
	
		
			
				|  |  |          if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
 | 
	
		
			
				|  |  | -            ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | +            //换成商品列表中商品4.25
 | 
	
		
			
				|  |  | +            Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
 | 
	
		
			
				|  |  |              Map<Integer, String> userMap = new HashMap<>();
 | 
	
		
			
				|  |  |              Map<Integer, String> userPhoneMap = new HashMap<>();
 | 
	
		
			
				|  |  |              Integer userId = replacementInstrumentActivity.getUserId();
 | 
	
	
		
			
				|  | @@ -199,18 +221,19 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
 | 
	
		
			
				|  |  |              userMap.put(userId, userId.toString());
 | 
	
		
			
				|  |  |              sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
 | 
	
		
			
				|  |  | -                    userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", replacementInstrument.getBrand(), "");
 | 
	
		
			
				|  |  | +                    userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              userPhoneMap.put(replacementInstrumentActivity.getUserId(), replacementInstrumentActivity.getMobileNo());
 | 
	
		
			
				|  |  |              sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
 | 
	
		
			
				|  |  | -                    userPhoneMap, null, 0, null, "STUDENT", replacementInstrument.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
 | 
	
		
			
				|  |  | +                    userPhoneMap, null, 0, null, "STUDENT", goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return replacementInstrumentActivity;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public ReplacementInstrumentActivity findByUserId(Integer cooperationOrganId, Integer userId,Integer topicId) {
 | 
	
		
			
				|  |  | -        return replacementInstrumentActivityDao.findByUserId(cooperationOrganId, userId,topicId);
 | 
	
		
			
				|  |  | +    public ReplacementInstrumentActivity findByUserId(Integer cooperationOrganId, Integer userId,Integer cooperationId) {
 | 
	
		
			
				|  |  | +        return replacementInstrumentActivityDao.findByUserId(cooperationOrganId, userId,cooperationId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -248,6 +271,10 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          ReplacementInstrumentActivity replacementInstrumentActivity = replacementInstrumentActivityDao.getLock(replacementPayDto.getId());
 | 
	
		
			
				|  |  |          Integer userId = replacementInstrumentActivity.getUserId();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if (replacementInstrumentActivity.getGoodsId() == null) {
 | 
	
		
			
				|  |  | +            throw new BizException("数据维护中,请稍后支付");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //处理关闭订单
 | 
	
		
			
				|  |  |          if (replacementInstrumentActivity.getPayStatus().equals(1) && replacementPayDto.getRePay()) {
 | 
	
		
			
				|  |  |              StudentPaymentOrder oldOrder = studentPaymentOrderService.getUserReplacementIngOrder(userId, replacementInstrumentActivity.getId());
 | 
	
	
		
			
				|  | @@ -258,10 +285,10 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | -        BigDecimal orderAmount = replacementInstrument.getSalePrice();
 | 
	
		
			
				|  |  | +        Goods goods = goodsDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | +        BigDecimal orderAmount = goods.getGroupPurchasePrice();
 | 
	
		
			
				|  |  |          BigDecimal amount = replacementPayDto.getAmount(); //扣除余额之前的金额
 | 
	
		
			
				|  |  | -        if (amount.compareTo(replacementInstrument.getSalePrice()) != 0) {
 | 
	
		
			
				|  |  | +        if (amount.compareTo(orderAmount) != 0) {
 | 
	
		
			
				|  |  |              throw new BizException("商品价格不符");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -408,6 +435,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |                  rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  |                  sysUserCashAccountDetailService.insert(paymentDetail);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            //添加sell_order
 | 
	
		
			
				|  |  | +            this.addSellOrder(studentPaymentOrder, replacementInstrumentActivity);
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  contractService.transferProduceContract(userId, null);
 | 
	
		
			
				|  |  |              } catch (Exception e) {
 | 
	
	
		
			
				|  | @@ -439,7 +468,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |      public ReplacementInstrumentActivityStatDto getInfo(Integer id) {
 | 
	
		
			
				|  |  |          ReplacementInstrumentActivityStatDto info = replacementInstrumentActivityDao.getInfo(id);
 | 
	
		
			
				|  |  |          if (info != null && info.getOpenFlag().equals(0)) {
 | 
	
		
			
				|  |  | -            ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationDao.getByCooperationId(info.getCooperationOrganId());
 | 
	
		
			
				|  |  | +            ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationDao.get(info.getReplacementInstrumentCooperationId());
 | 
	
		
			
				|  |  |              if (byCooperationId != null && byCooperationId.getOpenPay().equals(YesOrNoEnum.YES)) {
 | 
	
		
			
				|  |  |                  info.setOpenFlag(1);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -465,6 +494,67 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          return pageInfo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private List<SellOrder> addSellOrder(StudentPaymentOrder order, ReplacementInstrumentActivity replacementInstrumentActivity) {
 | 
	
		
			
				|  |  | +        if (replacementInstrumentActivity.getGoodsId() == null) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<Goods> goodies = new ArrayList<>();
 | 
	
		
			
				|  |  | +        Goods goods = goodsDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | +        goodies.add(goods);
 | 
	
		
			
				|  |  | +        if (goods.getComplementGoodsIdList() != null) {
 | 
	
		
			
				|  |  | +            goodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Map<Integer, BigDecimal> groupPurchasePriceMap = goodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
 | 
	
		
			
				|  |  | +        BigDecimal goodsTotalPrice = goodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +        Map<Integer, GoodsType> goodsTypeMap = goodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getType));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Integer> goodsIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        goodsIds.add(goods.getId());
 | 
	
		
			
				|  |  | +        List<SellOrder> sellOrders = goodsService.subtractStock(goodsIds, accountType);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BigDecimal hasRouteSellOrderExpectAmount = BigDecimal.ZERO; //已分配预计金额
 | 
	
		
			
				|  |  | +        BigDecimal hasRouteSellOrderBalance = BigDecimal.ZERO; //已分配余额
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        int i = 1;
 | 
	
		
			
				|  |  | +        for (SellOrder sellOrder : sellOrders) {
 | 
	
		
			
				|  |  | +            BigDecimal sellOrderExpectAmount = order.getExpectAmount().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : groupPurchasePriceMap.get(sellOrder.getGoodsId()).multiply(order.getExpectAmount()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
 | 
	
		
			
				|  |  | +            BigDecimal sellOrderBalance = order.getExpectAmount().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : groupPurchasePriceMap.get(sellOrder.getGoodsId()).multiply(order.getBalancePaymentAmount()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
 | 
	
		
			
				|  |  | +            if (i == sellOrders.size()) {
 | 
	
		
			
				|  |  | +                sellOrderExpectAmount = order.getExpectAmount().subtract(hasRouteSellOrderExpectAmount);
 | 
	
		
			
				|  |  | +                sellOrderBalance = order.getBalancePaymentAmount().subtract(hasRouteSellOrderBalance);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            sellOrder.setOrganId(order.getOrganId());
 | 
	
		
			
				|  |  | +            sellOrder.setTransNo(order.getTransNo());
 | 
	
		
			
				|  |  | +            sellOrder.setOrderId(order.getId());
 | 
	
		
			
				|  |  | +            sellOrder.setCooperationOrganId(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  | +            sellOrder.setOrderNo(order.getOrderNo());
 | 
	
		
			
				|  |  | +            sellOrder.setActualAmount(sellOrderExpectAmount.subtract(sellOrderBalance));
 | 
	
		
			
				|  |  | +            sellOrder.setBalanceAmount(sellOrderBalance);
 | 
	
		
			
				|  |  | +            sellOrder.setExpectAmount(sellOrderExpectAmount);
 | 
	
		
			
				|  |  | +            sellOrder.setNum(1);
 | 
	
		
			
				|  |  | +            sellOrder.setUserId(order.getUserId());
 | 
	
		
			
				|  |  | +            sellOrder.setPaymentChannel(order.getPaymentChannel());
 | 
	
		
			
				|  |  | +            sellOrder.setMerNo(order.getMerNos());
 | 
	
		
			
				|  |  | +            sellOrder.setSellTime(order.getCreateTime());
 | 
	
		
			
				|  |  | +            sellOrder.setCreateIme(new Date());
 | 
	
		
			
				|  |  | +            sellOrder.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +            if (goodsTypeMap.get(sellOrder.getGoodsId()).equals(GoodsType.INSTRUMENT)) {
 | 
	
		
			
				|  |  | +                sellOrder.setType(SellTypeEnum.INSTRUMENT);
 | 
	
		
			
				|  |  | +            } else if (goodsTypeMap.get(sellOrder.getGoodsId()).equals(GoodsType.ACCESSORIES)) {
 | 
	
		
			
				|  |  | +                sellOrder.setType(SellTypeEnum.ACCESSORIES);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                sellOrder.setType(SellTypeEnum.OTHER);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            i++;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (sellOrders.size() > 0) {
 | 
	
		
			
				|  |  | +            sellOrderDao.batchInsert(sellOrders);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return sellOrders;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void resultSync(){
 | 
	
		
			
				|  |  |          //获取所有问卷结果
 | 
	
	
		
			
				|  | @@ -496,11 +586,13 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public ReplacementInstrumentActivity queryUserInfo(Integer cooperationOrganId,SysUser user,Integer topicId) {
 | 
	
		
			
				|  |  | -        ReplacementInstrumentActivity replacementInstrumentActivity = findByUserId(cooperationOrganId, user.getId(),topicId);
 | 
	
		
			
				|  |  | +    public ReplacementInstrumentActivity queryUserInfo(Integer cooperationOrganId,SysUser user,Integer cooperationId) {
 | 
	
		
			
				|  |  | +        ReplacementInstrumentActivity replacementInstrumentActivity = findByUserId(cooperationOrganId, user.getId(),cooperationId);
 | 
	
		
			
				|  |  | +        ReplacementInstrumentCooperation cooperation = replacementInstrumentCooperationDao.get(cooperationId);
 | 
	
		
			
				|  |  |          if (replacementInstrumentActivity == null) {
 | 
	
		
			
				|  |  |              Student student = studentService.get(user.getId());
 | 
	
		
			
				|  |  |              replacementInstrumentActivity = new ReplacementInstrumentActivity();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setUserId(user.getId());
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setClasses(student.getCurrentClass());
 | 
	
		
			
				|  |  |              if (student.getCurrentGradeNum() != null) {
 | 
	
	
		
			
				|  | @@ -512,14 +604,15 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |              if (StringUtils.isNotEmpty(subjectIdList)) {
 | 
	
		
			
				|  |  |                  replacementInstrumentActivity.setSubjectId(Integer.parseInt(subjectIdList.split(",")[0]));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            replacementInstrumentActivity.setTopicId(cooperation.getTopicId());
 | 
	
		
			
				|  |  | +            replacementInstrumentActivity.setReplacementInstrumentCooperationId(cooperationId);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          replacementInstrumentActivity.setMobileNo(user.getPhone());
 | 
	
		
			
				|  |  |          CooperationOrgan cooperationOrgan = cooperationOrganService.get(cooperationOrganId);
 | 
	
		
			
				|  |  |          if (cooperationOrgan != null) {
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setCooperationOrganName(cooperationOrgan.getName());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.getByCooperationId(cooperationOrganId);
 | 
	
		
			
				|  |  | -        replacementInstrumentActivity.setShowQuestion(replacementInstrumentCooperation.getShowQuestion());
 | 
	
		
			
				|  |  | +        replacementInstrumentActivity.setShowQuestion(cooperation.getShowQuestion());
 | 
	
		
			
				|  |  |          return replacementInstrumentActivity;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |