嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceI...

171 lines
6.5 KiB

package com.hai.service.impl;
import com.hai.dao.*;
import com.hai.entity.*;
import com.hai.model.UserInfoModel;
import com.hai.service.*;
import com.hai.service.HighDiscountPackageService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* @serviceName HighDiscountPackageServiceImpl.java
* @author Sum1Dream
* @version 1.0.0
* @Description // 优惠券包 接口
* @createTime 12:21 下午 2021/11/25
**/
@Service("highDiscountPackageService")
public class HighDiscountPackageServiceImpl implements HighDiscountPackageService {
@Resource
private HighDiscountPackageMapper highDiscountPackageMapper;
@Resource
private HighDiscountPackageRecordMapper highDiscountPackageRecordMapper;
@Resource
private HighDiscountPackageDetailsService highDiscountPackageDetailsService;
@Resource
private HighDiscountAgentRelService highDiscountAgentRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Resource
private HighDiscountInventoryRecordMapper highDiscountInventoryRecordMapper;
@Resource
private HighDiscountPackageActualMapper discountPackageActualMapper;
@Resource
private HighDiscountPackageDiscountActualMapper discountPackageDiscountActualMapper;
@Override
public List<HighDiscountPackage> getDiscountPackageList(Map<String, Object> map) {
HighDiscountPackageExample example = new HighDiscountPackageExample();
HighDiscountPackageExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "companyId") != null) {
criteria.andCompanyIdEqualTo(MapUtils.getInteger(map, "companyId"));
}
if (MapUtils.getInteger(map, "usingAttribution") != null) {
criteria.andUsingAttributionEqualTo(MapUtils.getInteger(map, "usingAttribution"));
}
if (MapUtils.getString(map, "title") != null) {
criteria.andTitleLike("%" + MapUtils.getString(map, "title") + "%");
}
if (MapUtils.getInteger(map, "salesType") != null) {
criteria.andSalesTypeEqualTo(MapUtils.getInteger(map, "salesType"));
}
if (MapUtils.getInteger(map, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
} else {
criteria.andStatusNotEqualTo(4);
}
example.setOrderByClause("created_time desc");
return highDiscountPackageMapper.selectByExample(example);
}
@Override
public HighDiscountPackage findDiscountPackageById(Integer id) {
return highDiscountPackageMapper.selectByPrimaryKey(id);
}
@Override
public HighDiscountPackage getCallExclusive(Integer usingAttribution , Integer companyId) {
HighDiscountPackageExample example = new HighDiscountPackageExample();
HighDiscountPackageExample.Criteria criteria = example.createCriteria();
criteria.andUsingAttributionEqualTo(usingAttribution).andStatusNotEqualTo(4).andCompanyIdEqualTo(companyId);;
return highDiscountPackageMapper.selectByExample(example).get(0);
}
@Override
public void insertDiscountPackage(HighDiscountPackage highDiscountPackage) {
highDiscountPackageMapper.insert(highDiscountPackage);
}
@Override
public void updateDiscountPackage(HighDiscountPackage highDiscountPackage) {
highDiscountPackageMapper.updateByPrimaryKey(highDiscountPackage);
}
@Override
public List<HighDiscountPackageRecord> getDiscountPackageRecordList(Map<String, Object> map) {
HighDiscountPackageRecordExample example = new HighDiscountPackageRecordExample();
HighDiscountPackageRecordExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map, "companyId") != null) {
criteria.andCompanyIdEqualTo(MapUtils.getInteger(map, "companyId"));
}
if (MapUtils.getInteger(map, "usingAttribution") != null) {
criteria.andUsingAttributionEqualTo(MapUtils.getInteger(map, "usingAttribution"));
}
if (MapUtils.getString(map, "discountPackageTitle") != null) {
criteria.andDiscountPackageTitleLike("%" + MapUtils.getString(map, "discountPackageTitle") + "%");
}
if (MapUtils.getString(map, "recordNo") != null) {
criteria.andRecordNoLike("%" + MapUtils.getString(map, "recordNo") + "%");
}
if (MapUtils.getInteger(map, "salesType") != null) {
criteria.andSalesTypeEqualTo(MapUtils.getInteger(map, "salesType"));
}
if (MapUtils.getString(map, "phone") != null) {
criteria.andExt1Like("%" + MapUtils.getString(map, "phone") + "%");
}
return highDiscountPackageRecordMapper.selectByExample(example);
}
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE)
public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel , Integer num) {
Map<String , Object> mapRule = new HashMap<>();
mapRule.put("discountPackageId", highDiscountPackage.getId());
// 查询优惠券包规则
List<HighDiscountPackageDetails> discountPackageDetailsList = highDiscountPackageDetailsService.getDiscountPackageDetailsList(mapRule);
// 生成优惠券包实际库存实体
HighDiscountPackageActual discountPackageActual = new HighDiscountPackageActual();
discountPackageActual.setDiscountPackageId(highDiscountPackage.getId());
discountPackageActual.setCreatedUserId(userInfoModel.getSecUser().getId().intValue());
// 状态: 1: 待分配 2:预分配(售卖)3:已分配
discountPackageActual.setStatus(1);
for (int i = 0; i < num; i++) {
discountPackageActual.setCreatedTime(new Date());
discountPackageActualMapper.insert(discountPackageActual);
}
// 循环 优惠券包规则详情 列表
for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) {
// 查询代理商与优惠券关系 列表
List<HighDiscountAgentRel> discountAgentRels = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue() , detailsList.getAgentId());
}
}
}