|  | @@ -2,9 +2,7 @@ package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.CooperationOrganDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.ReplacementInstrumentDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatHead;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.ReplacementPayDto;
 | 
	
	
		
			
				|  | @@ -23,13 +21,13 @@ 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.poi.ss.formula.functions.T;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +import org.springframework.http.HttpStatus;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
	
		
			
				|  | @@ -66,9 +64,11 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |      private SysUserCashAccountDetailService sysUserCashAccountDetailService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysMessageService sysMessageService;
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private CooperationOrganService cooperationOrganService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ReplacementInstrumentCooperationDao replacementInstrumentCooperationDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private final Logger logger = LoggerFactory.getLogger(this.getClass());
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -86,23 +86,46 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          replacementInstrumentActivity.setUserId(sysUser.getId());
 | 
	
		
			
				|  |  |          //如果用户是43分部,那么修改用户信息
 | 
	
		
			
				|  |  | -        if(sysUser.getOrganId() == 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());
 | 
	
		
			
				|  |  | -            	sysUserFeignService.updateSysUser(sysUser);
 | 
	
		
			
				|  |  | +                sysUser.setOrganId(cooperationOrgan.getOrganId());
 | 
	
		
			
				|  |  | +                sysUser.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +                sysUserFeignService.updateSysUser(sysUser);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        ReplacementInstrumentCooperation replacementInstrumentCooperation = replacementInstrumentCooperationDao.getByCooperationId(replacementInstrumentActivity.getCooperationOrganId());
 | 
	
		
			
				|  |  |          //如果提交过调查问卷,那么覆盖之前的记录
 | 
	
		
			
				|  |  |          ReplacementInstrumentActivity activity = replacementInstrumentActivityDao.findByUserId(replacementInstrumentActivity.getCooperationOrganId(), sysUser.getId());
 | 
	
		
			
				|  |  | +        if (replacementInstrumentCooperation != null && replacementInstrumentCooperation.getOpenPay().equals(YesOrNoEnum.YES)) {
 | 
	
		
			
				|  |  | +            replacementInstrumentActivity.setOpenFlag(1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          if (activity != null) {
 | 
	
		
			
				|  |  | +            if (!activity.getPayStatus().equals(0)) {
 | 
	
		
			
				|  |  | +                throw new BizException("您已参与调查,谢谢参与!");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //覆盖之前的数据
 | 
	
		
			
				|  |  |              replacementInstrumentActivity.setId(activity.getId());
 | 
	
		
			
				|  |  |              replacementInstrumentActivityDao.update(replacementInstrumentActivity);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              replacementInstrumentActivityDao.insert(replacementInstrumentActivity);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //已开启缴费推送购买链接
 | 
	
		
			
				|  |  | +        if (replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
 | 
	
		
			
				|  |  | +            ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  | +            Map<Integer, String> userMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            Map<Integer, String> userPhoneMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            Integer userId = replacementInstrumentActivity.getUserId();
 | 
	
		
			
				|  |  | +            String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 | 
	
		
			
				|  |  | +            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(), "");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            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()));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          return replacementInstrumentActivity;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -141,15 +164,21 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public Map pay(ReplacementPayDto replacementPayDto) throws Exception {
 | 
	
		
			
				|  |  |          ReplacementInstrumentActivity replacementInstrumentActivity = replacementInstrumentActivityDao.getLock(replacementPayDto.getId());
 | 
	
		
			
				|  |  | -        if (replacementInstrumentActivity == null) {
 | 
	
		
			
				|  |  | -            throw new BizException("乐器置换不存在,请核查");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (replacementInstrumentActivity.getInstrumentsId() == null || replacementInstrumentActivity.getInstrumentsId() == 0) {
 | 
	
		
			
				|  |  | -            throw new BizException("没有置换的乐器,请核查");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          Integer userId = replacementInstrumentActivity.getUserId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //处理关闭订单
 | 
	
		
			
				|  |  | +        if (replacementInstrumentActivity.getPayStatus().equals(1) && replacementPayDto.getRePay()) {
 | 
	
		
			
				|  |  | +            StudentPaymentOrder oldOrder = studentPaymentOrderService.getUserReplacementIngOrder(userId, replacementInstrumentActivity.getId());
 | 
	
		
			
				|  |  | +            if (oldOrder != null) {
 | 
	
		
			
				|  |  | +                oldOrder.setStatus(DealStatusEnum.FAILED);
 | 
	
		
			
				|  |  | +                oldOrder.setMemo("用户手动关闭");
 | 
	
		
			
				|  |  | +                studentPaymentOrderService.callOrderCallBack(oldOrder);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
 | 
	
		
			
				|  |  |          BigDecimal orderAmount = replacementInstrument.getSalePrice();
 | 
	
		
			
				|  |  |          BigDecimal amount = replacementPayDto.getAmount(); //扣除余额之前的金额
 | 
	
	
		
			
				|  | @@ -326,4 +355,34 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return false;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ReplacementInstrumentActivityStatDto getInfo(Integer id) {
 | 
	
		
			
				|  |  | +        ReplacementInstrumentActivityStatDto info = replacementInstrumentActivityDao.getInfo(id);
 | 
	
		
			
				|  |  | +        if (info != null && info.getOpenFlag().equals(0)) {
 | 
	
		
			
				|  |  | +            ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationDao.getByCooperationId(info.getCooperationOrganId());
 | 
	
		
			
				|  |  | +            if (byCooperationId != null && byCooperationId.getOpenPay().equals(YesOrNoEnum.YES)) {
 | 
	
		
			
				|  |  | +                info.setOpenFlag(1);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return info;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public PageInfo<ReplacementInstrumentActivityStatDto> getPageList(ReplacementInstrumentActivityQueryInfo queryInfo) {
 | 
	
		
			
				|  |  | +        PageInfo<ReplacementInstrumentActivityStatDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
 | 
	
		
			
				|  |  | +        Map<String, Object> params = new HashMap<String, Object>();
 | 
	
		
			
				|  |  | +        MapUtil.populateMap(params, queryInfo);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<ReplacementInstrumentActivityStatDto> dataList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        int count = replacementInstrumentActivityDao.getCount(params);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (count > 0) {
 | 
	
		
			
				|  |  | +            pageInfo.setTotal(count);
 | 
	
		
			
				|  |  | +            params.put("offset", pageInfo.getOffset());
 | 
	
		
			
				|  |  | +            dataList = replacementInstrumentActivityDao.getPageList(params);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        pageInfo.setRows(dataList);
 | 
	
		
			
				|  |  | +        return pageInfo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |