|
|
|
@ -7,15 +7,21 @@ import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.common.security.AESEncodeUtil; |
|
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
|
import com.hai.common.utils.RedisUtil; |
|
|
|
|
import com.hai.config.CommonSysConst; |
|
|
|
|
import com.hai.dao.HighDiscountPackageAgentCodeMapper; |
|
|
|
|
import com.hai.dao.HighDiscountPackageAgentRecordMapper; |
|
|
|
|
import com.hai.dao.HighDiscountPackageAgentRelMapper; |
|
|
|
|
import com.hai.entity.*; |
|
|
|
|
import com.hai.model.HighUserModel; |
|
|
|
|
import com.hai.model.UserInfoModel; |
|
|
|
|
import com.hai.service.HighAgentService; |
|
|
|
|
import com.hai.service.HighDiscountPackageActualService; |
|
|
|
|
import com.hai.service.HighDiscountPackageAgentService; |
|
|
|
|
import com.hai.service.HighDiscountPackageService; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -43,10 +49,18 @@ public class HighDiscountPackageAgentServiceImpl implements HighDiscountPackageA |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighDiscountPackageAgentService discountPackageAgentService; |
|
|
|
|
@Resource |
|
|
|
|
private HighDiscountPackageService discountPackageService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighAgentService highAgentService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private UserCenter userCenter; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void insertDiscountPackageAgentRel(HighDiscountPackageAgentRel discountPackageAgentRel) { |
|
|
|
|
discountPackageAgentRelMapper.insert(discountPackageAgentRel); |
|
|
|
@ -272,4 +286,94 @@ public class HighDiscountPackageAgentServiceImpl implements HighDiscountPackageA |
|
|
|
|
|
|
|
|
|
return discountPackageAgentCodeMapper.selectByExample(example); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRED) |
|
|
|
|
public void recoveryDiscountPackage(JSONObject object) { |
|
|
|
|
|
|
|
|
|
// 用户信息
|
|
|
|
|
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
|
|
|
|
|
|
|
|
|
// 查询代理商
|
|
|
|
|
HighAgent agent = highAgentService.findByAgentMsgId(object.getLong("agentId")); |
|
|
|
|
// 查询优惠券包
|
|
|
|
|
HighDiscountPackage discountPackage = discountPackageService.findDiscountPackageById(object.getInteger("discountPackageId")); |
|
|
|
|
// 判断代理商状态是否正常
|
|
|
|
|
if (agent.getStatus() != 1) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "当前代理商不支持回收库存!"); |
|
|
|
|
} |
|
|
|
|
// 查询代理商与优惠券包的关联关系
|
|
|
|
|
Map<String , Object> map = new HashMap<>(); |
|
|
|
|
map.put("agentId" , object.getLong("agentId")); |
|
|
|
|
map.put("discountPackageId" , object.getLong("discountPackageId")); |
|
|
|
|
map.put("type" , 1); |
|
|
|
|
|
|
|
|
|
// 判断是否库存足够回收
|
|
|
|
|
HighDiscountPackageAgentRel discountPackageAgentRel = discountPackageAgentService.getDetailRelByMap(map); |
|
|
|
|
if (discountPackageAgentRel != null && discountPackageAgentRel.getStockCount() < object.getInteger("num") ) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存数量不足"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 录入回收记录
|
|
|
|
|
HighDiscountPackageAgentRecord discountPackageAgentRecord = new HighDiscountPackageAgentRecord(); |
|
|
|
|
discountPackageAgentRecord.setAgentId(object.getLong("agentId")); |
|
|
|
|
discountPackageAgentRecord.setAgentName(agent.getAgentName()); |
|
|
|
|
discountPackageAgentRecord.setDiscountPackageId(object.getLong("discountPackageId")); |
|
|
|
|
discountPackageAgentRecord.setDiscountPackageTitle(discountPackage.getTitle()); |
|
|
|
|
discountPackageAgentRecord.setCreateTime(new Date()); |
|
|
|
|
discountPackageAgentRecord.setUpdateTime(new Date()); |
|
|
|
|
discountPackageAgentRecord.setStatus(1); |
|
|
|
|
discountPackageAgentRecord.setType(3); |
|
|
|
|
discountPackageAgentRecord.setOpId(userInfoModel.getSecUser().getId()); |
|
|
|
|
discountPackageAgentRecord.setOpName(userInfoModel.getSecUser().getLoginName()); |
|
|
|
|
discountPackageAgentRecord.setCount(object.getInteger("num")); |
|
|
|
|
discountPackageAgentRecord.setAfterCount(discountPackageAgentRel.getStockCount()); |
|
|
|
|
discountPackageAgentRecord.setFrontCount(discountPackageAgentRel.getStockCount() - object.getInteger("num")); |
|
|
|
|
discountPackageAgentRecord.setExt1("代理商id:" + object.getLong("agentId") + "-优惠券包名称" + discountPackage.getTitle() + "-回收数量" + object.getInteger("num")); |
|
|
|
|
discountPackageAgentService.insertDiscountPackageAgentRecord(discountPackageAgentRecord); |
|
|
|
|
|
|
|
|
|
// 回收库存
|
|
|
|
|
discountPackageAgentRel.setStockCount(discountPackageAgentRel.getStockCount()-object.getInteger("num")); |
|
|
|
|
discountPackageAgentService.updateDiscountPackageAgentRel(discountPackageAgentRel); |
|
|
|
|
|
|
|
|
|
if (agent.getParentId() == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "当前代理商不支持回收库存!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询上级代理商
|
|
|
|
|
Map<String , Object> mapParent = new HashMap<>(); |
|
|
|
|
mapParent.put("agentId" , agent.getParentId()); |
|
|
|
|
mapParent.put("discountPackageId" , object.getLong("discountPackageId")); |
|
|
|
|
mapParent.put("type" , 1); |
|
|
|
|
HighDiscountPackageAgentRel discountPackageAgentRelParent = discountPackageAgentService.getDetailRelByMap(mapParent); |
|
|
|
|
|
|
|
|
|
if (discountPackageAgentRelParent == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "未查询到相关信息!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 录入回收记录
|
|
|
|
|
HighDiscountPackageAgentRecord discountPackageAgentRecordParent = new HighDiscountPackageAgentRecord(); |
|
|
|
|
discountPackageAgentRecordParent.setAgentId(object.getLong("agentId")); |
|
|
|
|
discountPackageAgentRecordParent.setAgentName(agent.getAgentName()); |
|
|
|
|
discountPackageAgentRecordParent.setDiscountPackageId(object.getLong("discountPackageId")); |
|
|
|
|
discountPackageAgentRecordParent.setDiscountPackageTitle(discountPackage.getTitle()); |
|
|
|
|
discountPackageAgentRecordParent.setCreateTime(new Date()); |
|
|
|
|
discountPackageAgentRecordParent.setUpdateTime(new Date()); |
|
|
|
|
discountPackageAgentRecordParent.setStatus(1); |
|
|
|
|
discountPackageAgentRecordParent.setType(3); |
|
|
|
|
discountPackageAgentRecordParent.setOpId(userInfoModel.getSecUser().getId()); |
|
|
|
|
discountPackageAgentRecordParent.setOpName(userInfoModel.getSecUser().getLoginName()); |
|
|
|
|
discountPackageAgentRecordParent.setCount(object.getInteger("num")); |
|
|
|
|
discountPackageAgentRecordParent.setAfterCount(discountPackageAgentRelParent.getStockCount()); |
|
|
|
|
discountPackageAgentRecordParent.setFrontCount(discountPackageAgentRelParent.getStockCount() + object.getInteger("num")); |
|
|
|
|
discountPackageAgentRecordParent.setExt1("代理商id:" + object.getLong("agentId") + "-优惠券包名称" + discountPackage.getTitle() + "-回收数量" + object.getInteger("num")); |
|
|
|
|
discountPackageAgentService.insertDiscountPackageAgentRecord(discountPackageAgentRecordParent); |
|
|
|
|
|
|
|
|
|
// 上级回收库存
|
|
|
|
|
discountPackageAgentRelParent.setStockCount(discountPackageAgentRelParent.getStockCount()+object.getInteger("num")); |
|
|
|
|
discountPackageAgentService.updateDiscountPackageAgentRel(discountPackageAgentRelParent); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|