diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponHistoryServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponHistoryServiceImpl.java new file mode 100644 index 0000000..b360279 --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponHistoryServiceImpl.java @@ -0,0 +1,37 @@ +package com.macro.mall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.macro.mall.mapper.SmsCouponHistoryMapper; +import com.macro.mall.model.SmsCouponHistory; +import com.macro.mall.model.SmsCouponHistoryExample; +import com.macro.mall.service.SmsCouponHistoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + * Żȯȡ¼Serviceʵ + */ +@Service +public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService { + @Autowired + private SmsCouponHistoryMapper historyMapper; + @Override + public List list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum) { + PageHelper.startPage(pageNum,pageSize); + SmsCouponHistoryExample example = new SmsCouponHistoryExample(); + SmsCouponHistoryExample.Criteria criteria = example.createCriteria(); + if(couponId!=null){ + criteria.andCouponIdEqualTo(couponId); + } + if(useStatus!=null){ + criteria.andUseStatusEqualTo(useStatus); + } + if(!StringUtils.isEmpty(orderSn)){ + criteria.andOrderSnEqualTo(orderSn); + } + return historyMapper.selectByExample(example); + } +} diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponServiceImpl.java new file mode 100644 index 0000000..1abd3ac --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/SmsCouponServiceImpl.java @@ -0,0 +1,124 @@ +package com.macro.mall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.macro.mall.dao.SmsCouponDao; +import com.macro.mall.dao.SmsCouponProductCategoryRelationDao; +import com.macro.mall.dao.SmsCouponProductRelationDao; +import com.macro.mall.dto.SmsCouponParam; +import com.macro.mall.mapper.SmsCouponMapper; +import com.macro.mall.mapper.SmsCouponProductCategoryRelationMapper; +import com.macro.mall.mapper.SmsCouponProductRelationMapper; +import com.macro.mall.model.*; +import com.macro.mall.service.SmsCouponService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + * ŻȯServiceʵ + */ +@Service +public class SmsCouponServiceImpl implements SmsCouponService { + @Autowired + private SmsCouponMapper couponMapper; + @Autowired + private SmsCouponProductRelationMapper productRelationMapper; + @Autowired + private SmsCouponProductCategoryRelationMapper productCategoryRelationMapper; + @Autowired + private SmsCouponProductRelationDao productRelationDao; + @Autowired + private SmsCouponProductCategoryRelationDao productCategoryRelationDao; + @Autowired + private SmsCouponDao couponDao; + @Override + public int create(SmsCouponParam couponParam) { + couponParam.setCount(couponParam.getPublishCount()); + couponParam.setUseCount(0); + couponParam.setReceiveCount(0); + //Żȯ + int count = couponMapper.insert(couponParam); + //ŻȯƷϵ + if(couponParam.getUseType().equals(2)){ + for(SmsCouponProductRelation productRelation:couponParam.getProductRelationList()){ + productRelation.setCouponId(couponParam.getId()); + } + productRelationDao.insertList(couponParam.getProductRelationList()); + } + //ŻȯƷϵ + if(couponParam.getUseType().equals(1)){ + for (SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()) { + couponProductCategoryRelation.setCouponId(couponParam.getId()); + } + productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList()); + } + return count; + } + + @Override + public int delete(Long id) { + //ɾŻȯ + int count = couponMapper.deleteByPrimaryKey(id); + //ɾƷ + deleteProductRelation(id); + //ɾƷ + deleteProductCategoryRelation(id); + return count; + } + + private void deleteProductCategoryRelation(Long id) { + SmsCouponProductCategoryRelationExample productCategoryRelationExample = new SmsCouponProductCategoryRelationExample(); + productCategoryRelationExample.createCriteria().andCouponIdEqualTo(id); + productCategoryRelationMapper.deleteByExample(productCategoryRelationExample); + } + + private void deleteProductRelation(Long id) { + SmsCouponProductRelationExample productRelationExample = new SmsCouponProductRelationExample(); + productRelationExample.createCriteria().andCouponIdEqualTo(id); + productRelationMapper.deleteByExample(productRelationExample); + } + + @Override + public int update(Long id, SmsCouponParam couponParam) { + couponParam.setId(id); + int count =couponMapper.updateByPrimaryKey(couponParam); + //ɾŻȯƷϵ + if(couponParam.getUseType().equals(2)){ + for(SmsCouponProductRelation productRelation:couponParam.getProductRelationList()){ + productRelation.setCouponId(couponParam.getId()); + } + deleteProductRelation(id); + productRelationDao.insertList(couponParam.getProductRelationList()); + } + //ɾŻȯƷϵ + if(couponParam.getUseType().equals(1)){ + for (SmsCouponProductCategoryRelation couponProductCategoryRelation : couponParam.getProductCategoryRelationList()) { + couponProductCategoryRelation.setCouponId(couponParam.getId()); + } + deleteProductCategoryRelation(id); + productCategoryRelationDao.insertList(couponParam.getProductCategoryRelationList()); + } + return count; + } + + @Override + public List list(String name, Integer type, Integer pageSize, Integer pageNum) { + SmsCouponExample example = new SmsCouponExample(); + SmsCouponExample.Criteria criteria = example.createCriteria(); + if(!StringUtils.isEmpty(name)){ + criteria.andNameLike("%"+name+"%"); + } + if(type!=null){ + criteria.andTypeEqualTo(type); + } + PageHelper.startPage(pageNum,pageSize); + return couponMapper.selectByExample(example); + } + + @Override + public SmsCouponParam getItem(Long id) { + return couponDao.getItem(id); + } +} \ No newline at end of file