diff --git a/mallinkAdmin/src/main/java/com/simple/controller/WxCampaignController.java b/mallinkAdmin/src/main/java/com/simple/controller/WxCampaignController.java index 6a2885621..247470358 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/WxCampaignController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/WxCampaignController.java @@ -6,7 +6,12 @@ import com.simple.common.Result; import com.simple.common.ResultData; import com.simple.domain.po.WxCampaign; import com.simple.domain.po.WxCoupon; +import com.simple.domain.po.WxCouponChannel; +import com.simple.domain.vo.WxCouponChannelVo; +import com.simple.enums.EnumCouponChannelType; +import com.simple.enums.EnumCouponStatus; import com.simple.service.WxCampaignService; +import com.simple.service.WxCouponChannelService; import com.simple.service.WxCouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -29,9 +34,13 @@ public class WxCampaignController extends BaseController { @Autowired private WxCampaignService wxCampaignService; + @Autowired private WxCouponService wxCouponService; + @Autowired + private WxCouponChannelService wxCouponChannelService; + private Logger logger = Logger.getLogger(WxCampaignController.class); @ApiOperation("分页列表接口") @@ -92,18 +101,13 @@ public class WxCampaignController extends BaseController public ResultData findById(Long id) { WxCampaign wxCampaign = wxCampaignService.getById(id); if (wxCampaign != null) { - List list = new ArrayList<>(); - List templist = JSON.parseArray(wxCampaign.getCouponIds(), String.class); - for (String temp : templist - ) { - list.add(Long.parseLong(temp)); - } - WxCoupon wxCoupon = new WxCoupon(); - wxCoupon.setTenantId(getTenantId()); - wxCoupon.setIds(list); - wxCoupon.setStatus(0); - List couponlist = wxCouponService.findList(wxCoupon); - wxCampaign.setCoupons(couponlist); + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + wxCouponChannel.setTenantId(getTenantId()); + wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannel.setSubTargetId(wxCampaign.getId()); + wxCouponChannel.setStatus(0); + List couponList = wxCouponChannelService.listAPI(wxCouponChannel); + wxCampaign.setCoupons(couponList); } return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); } diff --git a/mallinkCApi/src/main/java/com/simple/controller/WxCampaignController.java b/mallinkCApi/src/main/java/com/simple/controller/WxCampaignController.java index 99478cea9..c28ef7d45 100644 --- a/mallinkCApi/src/main/java/com/simple/controller/WxCampaignController.java +++ b/mallinkCApi/src/main/java/com/simple/controller/WxCampaignController.java @@ -6,7 +6,11 @@ import com.simple.common.Result; import com.simple.common.ResultData; import com.simple.domain.po.WxCampaign; import com.simple.domain.po.WxCoupon; +import com.simple.domain.po.WxCouponChannel; +import com.simple.domain.vo.WxCouponChannelVo; +import com.simple.enums.EnumCouponChannelType; import com.simple.service.WxCampaignService; +import com.simple.service.WxCouponChannelService; import com.simple.service.WxCouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -31,6 +35,8 @@ public class WxCampaignController extends BaseController private WxCampaignService wxCampaignService; @Autowired private WxCouponService wxCouponService; + @Autowired + private WxCouponChannelService wxCouponChannelService; private Logger logger = Logger.getLogger(WxCampaignController.class); @@ -54,18 +60,13 @@ public class WxCampaignController extends BaseController public ResultData findById(Long id) { WxCampaign wxCampaign = wxCampaignService.getById(id); if (wxCampaign != null) { - List list = new ArrayList<>(); - List templist = JSON.parseArray(wxCampaign.getCouponIds(), String.class); - for (String temp : templist - ) { - list.add(Long.parseLong(temp)); - } - WxCoupon wxCoupon = new WxCoupon(); - wxCoupon.setTenantId(getTenantId()); - wxCoupon.setIds(list); - wxCoupon.setStatus(0); - List couponlist = wxCouponService.findList(wxCoupon); - wxCampaign.setCoupons(couponlist); + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + wxCouponChannel.setTenantId(getTenantId()); + wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannel.setSubTargetId(wxCampaign.getId()); + wxCouponChannel.setStatus(0); + List couponList = wxCouponChannelService.listAPI(wxCouponChannel); + wxCampaign.setCoupons(couponList); } return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); } diff --git a/mallinkService/src/main/java/com/simple/common/ErrorCode.java b/mallinkService/src/main/java/com/simple/common/ErrorCode.java index 1b14096c5..a2f037712 100644 --- a/mallinkService/src/main/java/com/simple/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/simple/common/ErrorCode.java @@ -71,6 +71,7 @@ public enum ErrorCode{ COUPON_IS_NOT_FREE(2021, "券不免费"), COUPON_IS_TAKE_OFF(2022, "此券已下架"), + COUPON_CHANNEL_IS_EXISTED(2023, "券已投放过"), /** * 车流 2040 */ diff --git a/mallinkService/src/main/java/com/simple/domain/po/WxCampaign.java b/mallinkService/src/main/java/com/simple/domain/po/WxCampaign.java index ced30a5d3..0f1d35af8 100644 --- a/mallinkService/src/main/java/com/simple/domain/po/WxCampaign.java +++ b/mallinkService/src/main/java/com/simple/domain/po/WxCampaign.java @@ -1,5 +1,7 @@ package com.simple.domain.po; +import com.simple.domain.vo.WxCouponChannelVo; + import javax.persistence.*; import java.util.*; import java.math.*; @@ -20,13 +22,13 @@ public class WxCampaign implements Serializable { @Transient protected String sortColumns; @Transient - protected List coupons; + protected List coupons; - public List getCoupons() { + public List getCoupons() { return coupons; } - public void setCoupons(List coupons) { + public void setCoupons(List coupons) { this.coupons = coupons; } @@ -211,23 +213,23 @@ public class WxCampaign implements Serializable { public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") - ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") - ,CoverImg_ASC("`coverImg` ASC"),CoverImg_DESC("`coverImg` DESC") + ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") + ,CoverImg_ASC("`cover_img` ASC"),CoverImg_DESC("`cover_img` DESC") ,Title_ASC("`title` ASC"),Title_DESC("`title` DESC") - ,SubTitle_ASC("`subTitle` ASC"),SubTitle_DESC("`subTitle` DESC") - ,UsePrice_ASC("`usePrice` ASC"),UsePrice_DESC("`usePrice` DESC") - ,DiscountPrice_ASC("`discountPrice` ASC"),DiscountPrice_DESC("`discountPrice` DESC") + ,SubTitle_ASC("`sub_title` ASC"),SubTitle_DESC("`sub_title` DESC") + ,UsePrice_ASC("`use_price` ASC"),UsePrice_DESC("`use_price` DESC") + ,DiscountPrice_ASC("`discount_price` ASC"),DiscountPrice_DESC("`discount_price` DESC") ,Detail_ASC("`detail` ASC"),Detail_DESC("`detail` DESC") - ,ValidStartDate_ASC("`validStartDate` ASC"),ValidStartDate_DESC("`validStartDate` DESC") - ,ValidEndDate_ASC("`validEndDate` ASC"),ValidEndDate_DESC("`validEndDate` DESC") - ,ImgDetail_ASC("`imgDetail` ASC"),ImgDetail_DESC("`imgDetail` DESC") + ,ValidStartDate_ASC("`valid_start_date` ASC"),ValidStartDate_DESC("`valid_start_date` DESC") + ,ValidEndDate_ASC("`valid_end_date` ASC"),ValidEndDate_DESC("`valid_end_date` DESC") + ,ImgDetail_ASC("`img_detail` ASC"),ImgDetail_DESC("`img_detail` DESC") ,Type_ASC("`type` ASC"),Type_DESC("`type` DESC") - ,CouponIds_ASC("`couponIds` ASC"),CouponIds_DESC("`couponIds` DESC") - ,MechantId_ASC("`mechantId` ASC"),MechantId_DESC("`mechantId` DESC") - ,SortNum_ASC("`sortNum` ASC"),SortNum_DESC("`sortNum` DESC") + ,CouponIds_ASC("`coupon_ids` ASC"),CouponIds_DESC("`coupon_ids` DESC") + ,MechantId_ASC("`mechant_id` ASC"),MechantId_DESC("`mechantId` DESC") + ,SortNum_ASC("`sort_num` ASC"),SortNum_DESC("`sortNum` DESC") ,Status_ASC("`status` ASC"),Status_DESC("`status` DESC") - ,CreateTime_ASC("`createTime` ASC"),CreateTime_DESC("`createTime` DESC") - ,UpdateTime_ASC("`updateTime` ASC"),UpdateTime_DESC("`updateTime` DESC") + ,CreateTime_ASC("`create_time` ASC"),CreateTime_DESC("`create_time` DESC") + ,UpdateTime_ASC("`update_time` ASC"),UpdateTime_DESC("`update_time` DESC") ; private String value; Field(String value){ @@ -260,7 +262,7 @@ public class WxCampaign implements Serializable { sb.append(","); sb.append(fields[k].toString()); } - + this.sortColumns = sb.toString(); } public void setSortColumns(String sortColumns) diff --git a/mallinkService/src/main/java/com/simple/domain/po/WxCouponChannel.java b/mallinkService/src/main/java/com/simple/domain/po/WxCouponChannel.java index e18bb0fe5..76fb5e3fc 100644 --- a/mallinkService/src/main/java/com/simple/domain/po/WxCouponChannel.java +++ b/mallinkService/src/main/java/com/simple/domain/po/WxCouponChannel.java @@ -17,8 +17,6 @@ public class WxCouponChannel implements Serializable { @Transient protected List ids; - @Transient - protected List couponIds; @Transient protected String sortColumns; @@ -44,6 +42,15 @@ public class WxCouponChannel implements Serializable { } + @Transient + protected List couponIds; + public List getCouponIds() { + return couponIds; + } + public void setCouponIds(List couponIds) { + this.couponIds = couponIds; + } + /*租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") @@ -82,6 +89,11 @@ public class WxCouponChannel implements Serializable { /*更新时间**/ @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") private Date updateDate; + /*更新时间**/ + @io.swagger.annotations.ApiModelProperty(value="子频道ID",name="subTargetId") + private Long subTargetId; + + public String getTenantId() { return tenantId; } @@ -154,12 +166,13 @@ public class WxCouponChannel implements Serializable { public void setUpdateDate(Date _updateDate) { updateDate = _updateDate; } - public List getCouponIds() { - return couponIds; - } - public void setCouponIds(List couponIds) { - this.couponIds = couponIds; + + public Long getSubTargetId() { + return subTargetId; + } + public void setSubTargetId(Long subTargetId) { + this.subTargetId = subTargetId; } diff --git a/mallinkService/src/main/java/com/simple/enums/EnumCouponChannelType.java b/mallinkService/src/main/java/com/simple/enums/EnumCouponChannelType.java new file mode 100644 index 000000000..b47f9ef80 --- /dev/null +++ b/mallinkService/src/main/java/com/simple/enums/EnumCouponChannelType.java @@ -0,0 +1,39 @@ +package com.simple.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumCouponChannelType { + + COUPON_CHANNEL_ID_LIST(1, "列表"), + COUPON_CHANNEL_ID_TIMED(2, "限时抢购"), + COUPON_CHANNEL_ID_CAMPAIN(3, "幻灯片"), + ; + + ; + + public static EnumCouponChannelType getEnum(Integer code) { + for (EnumCouponChannelType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumCouponChannelType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/simple/service/WxCouponChannelService.java b/mallinkService/src/main/java/com/simple/service/WxCouponChannelService.java index 5adaca338..28b979882 100644 --- a/mallinkService/src/main/java/com/simple/service/WxCouponChannelService.java +++ b/mallinkService/src/main/java/com/simple/service/WxCouponChannelService.java @@ -6,6 +6,7 @@ import com.simple.domain.po.WxCouponChannel; import com.simple.domain.vo.WxCouponChannelVo; import java.util.Date; +import java.util.List; public interface WxCouponChannelService { @@ -20,7 +21,9 @@ public interface WxCouponChannelService { PageInfo listAsPage(WxCouponChannel record, Integer pageIndex, Integer pageSize); PageInfo listPageCAPI(WxCouponChannel record, Integer pageIndex, Integer pageSize); - + + List listAPI(WxCouponChannel record); + /** * 根据Id获得实体 * diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java index 21709f28f..cebe23097 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java @@ -1,13 +1,29 @@ package com.simple.service.impl; +import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.simple.common.ErrorCode; import com.simple.common.IdWorker; import com.simple.domain.po.WxCampaign; +import com.simple.domain.po.WxCoupon; +import com.simple.domain.po.WxCouponChannel; +import com.simple.enums.EnumCouponChannelStatus; +import com.simple.enums.EnumCouponChannelType; +import com.simple.enums.EnumCouponStatus; +import com.simple.exception.MallinkException; import com.simple.mapper.WxCampaignMapper; +import com.simple.mapper.WxCouponChannelMapper; import com.simple.service.WxCampaignService; +import com.simple.service.WxCouponChannelService; +import com.simple.service.WxCouponService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; @Service public class WxCampaignServiceImpl implements WxCampaignService { @@ -15,6 +31,14 @@ public class WxCampaignServiceImpl implements WxCampaignService { @Autowired WxCampaignMapper wxCampaignMapper; + @Autowired + WxCouponChannelMapper wxCouponChannelMapper; + + @Autowired + WxCouponService wxCouponService; + + @Autowired + WxCouponChannelService wxCouponChannelService; @Override public PageInfo listAsPage(WxCampaign record, Integer pageIndex, Integer pageSize) { @@ -26,16 +50,87 @@ public class WxCampaignServiceImpl implements WxCampaignService { return wxCampaignMapper.selectByPrimaryKey(id); } + @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @Override public void saveOrUpdate(WxCampaign record) { if (record.getId() == null) { - //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); IdWorker idWorker = new IdWorker(0, 0); record.setId(idWorker.nextId()); wxCampaignMapper.insertSelective(record); } else { wxCampaignMapper.updateByPrimaryKeySelective(record); } + if (record.getStatus() == 0) + addOrUpdateBatch(JSONArray.parseArray(record.getCouponIds(),String.class),record); + else + delBatch(record); + } + + public void delBatch(WxCampaign record) { + + WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); + wxCouponChannelQuery.setTenantId(record.getTenantId()); + wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannelQuery.setSubTargetId(record.getId()); + List wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); + if (wxCouponChannels.size() > 0) { + for (WxCouponChannel ch : wxCouponChannels) { + ch.setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); + wxCouponChannelMapper.updateByPrimaryKeySelective(ch); + } + } + } + + public void addOrUpdateBatch(List ids, WxCampaign record) { + + for (String couponIdStr:ids) { + Long couponId = Long.parseLong(couponIdStr); + saveOrUpdateCouponChannel(couponId,record); + } + } + + public void saveOrUpdateCouponChannel(Long couponId, WxCampaign record){ + + WxCoupon wxCoupon = wxCouponService.getById(couponId); + if (wxCoupon == null) { + throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); + } + if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) { + throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); + } + if (wxCoupon.getValidEndDate() != null && wxCoupon.getValidEndDate().after(new Date())) { + throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); + } + + WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); + wxCouponChannelQuery.setTenantId(record.getTenantId()); + wxCouponChannelQuery.setCouponId(couponId); + wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannelQuery.setSubTargetId(record.getId()); + List wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); + if(wxCouponChannels.size()>0){ + if(wxCouponChannels.get(0).getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { + wxCouponChannels.get(0).setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannels.get(0)); + } + } + else { + + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + + wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + wxCouponChannel.setCouponId(couponId); + wxCouponChannel.setMerchantId(wxCoupon.getMerchantId()); + wxCouponChannel.setType(wxCoupon.getType()); + wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannel.setTenantId(wxCoupon.getTenantId()); + wxCouponChannel.setBusiness(wxCoupon.getBusiness()); + wxCouponChannel.setTitle(wxCoupon.getTitle()); + wxCouponChannel.setSubTargetId(record.getId()); + final IdWorker idWorker = IdWorker.get(); + wxCouponChannel.setId(idWorker.nextId()); + wxCouponChannelMapper.insertSelective(wxCouponChannel); + } } @Override diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCouponChannelServiceImpl.java index 10533f3b3..3ea46f8ff 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCouponChannelServiceImpl.java @@ -165,5 +165,24 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { return new PageInfo<>(wxCouponChannelVoList); } + @Override + public List listAPI(WxCouponChannel record) { + List wxCouponChannelVoList = new ArrayList<>(); + wxCouponChannelVoList = wxCouponChannelMapper.findVoList(record); + if(wxCouponChannelVoList.isEmpty()){ + return wxCouponChannelVoList; + } + List couponIds = wxCouponChannelVoList.stream().map(p->p.getCouponId()).distinct().collect(Collectors.toList()); + WxCoupon wxCoupon = new WxCoupon(); + wxCoupon.setIds(couponIds); + List wxCoupons = wxCouponService.findList(wxCoupon); + Map couponNamesMap = wxCoupons.stream().collect(Collectors.toMap(WxCoupon::getId,p->p)); + for (WxCouponChannelVo wxcouponVo:wxCouponChannelVoList) { + if(couponNamesMap.get(wxcouponVo.getCouponId())!=null){ + wxcouponVo.setWxCoupon(couponNamesMap.get(wxcouponVo.getCouponId())); + } + } + return wxCouponChannelVoList; + } } diff --git a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml index b6193895e..85c3f401f 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml @@ -15,10 +15,11 @@ + - `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`business`,`begin_time`,`end_time`,`status`,`create_date`,`update_date` + `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`business`,`begin_time`,`end_time`,`status`,`create_date`,`update_date`,`sub_target_id` @@ -88,6 +89,10 @@ and `update_date` = #{updateDate} + + + and `sub_target_id` = #{subTargetId} + and id in @@ -137,6 +142,7 @@ +