From 94bfc268eddb57891b05531c3a524fba1c37f3a2 Mon Sep 17 00:00:00 2001 From: hupeng Date: Mon, 4 Mar 2019 17:04:56 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A4=A7=E5=B1=8F][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D,=E5=88=B8,=E5=88=B8=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E4=BD=9C=E5=BA=9F=E4=B8=8B=E6=9E=B6=E6=97=B6=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E4=B8=8B=E6=9E=B6=E5=B9=BF=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCouponChannelController.java | 28 ++----------- .../controller/WxDeviceController.java | 8 ++-- .../controller/WxScreenAdController.java | 8 ++-- .../schedule/CouponExpiringSchedule.java | 10 ++++- .../com/iformall/mapper/WxScreenAdMapper.java | 3 ++ .../service/WxCouponChannelService.java | 2 +- .../iformall/service/WxScreenAdService.java | 5 ++- .../impl/WxCouponChannelServiceImpl.java | 39 ++++++++++++++++++- .../service/impl/WxCouponServiceImpl.java | 12 +++--- .../service/impl/WxScreenAdServiceImpl.java | 34 ++++++++++++++++ .../mapper/WxCouponChannelMapper.xml | 3 +- .../resources/mapper/WxScreenAdMapper.xml | 18 ++++++++- 12 files changed, 124 insertions(+), 46 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponChannelController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponChannelController.java index 863dfea50..b7e9bfefa 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponChannelController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponChannelController.java @@ -39,6 +39,7 @@ public class WxCouponChannelController extends BaseController { @Autowired private WxCouponService wxCouponService; + @ApiOperation("分页列表接口") @GetMapping("list") @ApiImplicitParams({ @@ -62,31 +63,8 @@ public class WxCouponChannelController extends BaseController { public ResultData update(@RequestBody WxCouponChannel wxCouponChannel) { logger.debug("[" + getIpAddr() + "] WxCouponChannelController::update"); wxCouponChannel.setTenantId(getUser().getTenantId()); - if (wxCouponChannel.getCouponId() != null && wxCouponChannel.getStatus() != null) { - WxCouponChannel orignal = wxCouponChannelService.getById(wxCouponChannel.getId()); - if (orignal.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) - && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_THROW_IN.getCode())) { - - WxCoupon wxCoupon = wxCouponService.getById(orignal.getCouponId()); - if (wxCoupon == null) - return new ResultData(ErrorCode.COUPON_IS_EMPTY); - if (wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF)) - return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); - - //查找是否该券 在该频道有其他上架 - WxCouponChannel query = new WxCouponChannel(); - query.setTenantId(orignal.getTenantId()); - query.setCouponId(orignal.getCouponId()); - query.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());//已上架 - query.setTargetAd(orignal.getTargetAd()); - List list = wxCouponChannelService.listAsPage(query, 1, 1).getList(); - if (list != null && list.size() > 0) { - return new ResultData(ErrorCode.COUPON_CHANNEL_IS_EXISTED); - } - } - } - wxCouponChannelService.saveOrUpdate(wxCouponChannel); - return new ResultData(); + + return wxCouponChannelService.saveOrUpdate(wxCouponChannel); } @ApiOperation("根据id删除接口") diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceController.java index 5bd3079bc..bdd04a1ad 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceController.java @@ -42,7 +42,7 @@ public class WxDeviceController extends BaseController { @ApiOperation("添加设备") @PostMapping("add") - public Result add(@ModelAttribute WxDevice wxDevice) { + public Result add(@RequestBody WxDevice wxDevice) { WxDevice record = new WxDevice(); record.setDeviceId(wxDevice.getDeviceId()); @@ -59,7 +59,7 @@ public class WxDeviceController extends BaseController { @ApiOperation("更新设备") @PostMapping("update") - public Result update(@ModelAttribute WxDevice wxDevice) { + public Result update(@RequestBody WxDevice wxDevice) { if (wxDevice == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); if (wxDevice.getId() == null) @@ -71,7 +71,7 @@ public class WxDeviceController extends BaseController { @ApiOperation("设备详情") @GetMapping("detail") - public Result detail(Long id) { + public Result detail(@RequestParam Long id) { if (id == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); WxDevice wxDevice = wxDeviceService.getById(id); @@ -83,7 +83,7 @@ public class WxDeviceController extends BaseController { @ApiOperation("删除设备") @PostMapping("delete") - public Result delete(Long id) { + public Result delete(@RequestParam Long id) { if (id == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); WxDevice wxDevice = new WxDevice(); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxScreenAdController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxScreenAdController.java index 682eb1240..f89cb29ac 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxScreenAdController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxScreenAdController.java @@ -53,7 +53,7 @@ public class WxScreenAdController extends BaseController { @ApiOperation("添加广告") @PostMapping("add") - public Result add(@ModelAttribute WxScreenAd wxScreenAd) { + public Result add(@RequestBody WxScreenAd wxScreenAd) { wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); wxScreenAd.setTenantId(getTenantId()); wxScreenAdService.saveOrUpdate(wxScreenAd); @@ -62,7 +62,7 @@ public class WxScreenAdController extends BaseController { @ApiOperation("更新广告") @PostMapping("update") - public Result update(@ModelAttribute WxScreenAd wxScreenAd) { + public Result update(@RequestBody WxScreenAd wxScreenAd) { if (wxScreenAd == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); if (wxScreenAd.getId() == null) @@ -74,7 +74,7 @@ public class WxScreenAdController extends BaseController { @ApiOperation("广告详情") @GetMapping("detail") - public Result detail(Long id) { + public Result detail(@RequestParam Long id) { if (id == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); WxScreenAd wxScreenAd = wxScreenAdService.getById(id); @@ -93,7 +93,7 @@ public class WxScreenAdController extends BaseController { @ApiOperation("删除广告") @PostMapping("delete") - public Result delete(Long id) { + public Result delete(@RequestParam Long id) { if (id == null) return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); WxScreenAd wxScreenAd = new WxScreenAd(); diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponExpiringSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponExpiringSchedule.java index 471902c36..7fa5cca98 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponExpiringSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponExpiringSchedule.java @@ -23,6 +23,9 @@ public class CouponExpiringSchedule { @Autowired private WxCouponSendMapper wxCouponSendMapper; + @Autowired + private WxScreenAdMapper wxScreenAdMapper; + @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨00:05 作废过期券,商户禁用券 //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 @@ -41,7 +44,6 @@ public class CouponExpiringSchedule { wxCouponSendMapper.offExpiriedCouponSendByCouponStatus(); } - @Scheduled(cron = "0 10 0 * * ?") // 每天凌晨00:10 下架主动领取 //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 public void couponChannelExpiringSchedule() { @@ -51,6 +53,12 @@ public class CouponExpiringSchedule { wxCouponChannelMapper.offExpiriedCouponChannelByCouponStatus(); } + @Scheduled(cron = "0 15 0 * * ?") // 每天凌晨00:15 下架券广告 + //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 + public void screenAdExpiringSchedule() { + wxScreenAdMapper.offScreeAdByCouponChannelStatus(); + } + @Scheduled(cron = "0 0,1,2,3 0/1 * * ?") // 每小时 0, 1 ,2 ,3 分钟(整点)执行//限时抢购 //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 public void couponChannel2ExpiringSchedule() { diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxScreenAdMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxScreenAdMapper.java index 4877477ad..12ddab640 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxScreenAdMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxScreenAdMapper.java @@ -10,4 +10,7 @@ public interface WxScreenAdMapper extends CommonMapper { List findList(WxScreenAd wxScreenAd); + void offScreeAdByCouponChannelStatus(); + void updateStatusByCouponChannelId(WxScreenAd wxScreenAd); + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java index add4cf76e..a623b260c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java @@ -61,7 +61,7 @@ public interface WxCouponChannelService { * * @param record */ - void saveOrUpdate(WxCouponChannel record); + ResultData saveOrUpdate(WxCouponChannel record); /** * 根据Id删除实体 diff --git a/mallinkService/src/main/java/com/iformall/service/WxScreenAdService.java b/mallinkService/src/main/java/com/iformall/service/WxScreenAdService.java index 8375cdae2..1805e30ca 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxScreenAdService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxScreenAdService.java @@ -54,5 +54,8 @@ public interface WxScreenAdService { List findList(WxScreenAd record); - + + void updateStatusByCouponChannelId(Long couponChannelId, String tenantId, int status); + + void updateStatusByCouponId(Long couponId, String tenantId, int status); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java index 4c4b89b38..1552f8e3b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java @@ -22,6 +22,7 @@ import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.mapper.WxMerchantMapper; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponService; +import com.iformall.service.WxScreenAdService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,6 +41,8 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { WxMerchantMapper wxMerchantMapper; @Autowired WxCouponMerchantMapper wxCouponMerchantMapper; + @Autowired + WxScreenAdService wxScreenAdService; /** * B端业务端 * @param record @@ -58,15 +61,47 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { } @Override - public void saveOrUpdate(WxCouponChannel record) { + public ResultData saveOrUpdate(WxCouponChannel record) { if (record.getId() == null) { //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); wxCouponChannelMapper.insertSelective(record); } else { + + if (record.getCouponId() != null && record.getStatus() != null) { + WxCouponChannel orignal = getById(record.getId()); + if (orignal.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) + && record.getStatus().equals(EnumCouponChannelStatus.STATUS_THROW_IN.getCode())) { + + WxCoupon wxCoupon = wxCouponService.getById(orignal.getCouponId()); + if (wxCoupon == null) + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + if (wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF)) + return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); + + //查找是否该券 在该频道有其他上架 + WxCouponChannel query = new WxCouponChannel(); + query.setTenantId(orignal.getTenantId()); + query.setCouponId(orignal.getCouponId()); + query.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());//已上架 + query.setTargetAd(orignal.getTargetAd()); + List list = wxCouponChannelMapper.findList(query); + if (list != null && list.size() > 0) { + return new ResultData(ErrorCode.COUPON_CHANNEL_IS_EXISTED); + } + } + } + if (record.getStatus() != null) { + WxCouponChannel orignal = getById(record.getId()); + if (orignal.getStatus().equals(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()) + && record.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { + wxScreenAdService.updateStatusByCouponChannelId(record.getId(),record.getTenantId(),EnumScreenAdStatus.INVALID.getCode()); + } + } wxCouponChannelMapper.updateByPrimaryKeySelective(record); } + return new ResultData(); } @Override @@ -171,7 +206,7 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { WxCouponChannel wxCouponChannel = new WxCouponChannel(); wxCouponChannel.setEndTime(endTime); - wxCouponChannel.setStatus(0); + wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); wxCouponChannel.setBeginTime(beginTime); wxCouponChannel.setCouponId(couponid); wxCouponChannel.setType(wxCoupon.getType()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index b9d3eb09f..ea15575de 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -10,16 +10,14 @@ import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponMerchant; +import com.iformall.domain.po.WxScreenAd; import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.*; import com.iformall.mapper.WxCouponMapper; import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.mapper.WxMerchantMapper; -import com.iformall.service.WxCouponChannelService; -import com.iformall.service.WxCouponSendService; -import com.iformall.service.WxCouponService; -import com.iformall.service.WxOrderService; +import com.iformall.service.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +50,8 @@ public class WxCouponServiceImpl implements WxCouponService { @Autowired WxOrderService wxOrderService; + @Autowired + WxScreenAdService wxScreenAdService; @Override public PageInfo listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize, Integer type) { @@ -242,8 +242,8 @@ public class WxCouponServiceImpl implements WxCouponService { .updateStatusByCouponId(record.getId(), record.getTenantId(), EnumCouponSendStatus.INVALID.getCode()); //下架所有已砍价券 wxOrderService.updateStatusByPressCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode()); - - + //下架所有相关广告 + wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode()); } record.setUpdateDate(new Date()); wxCouponMapper.updateByPrimaryKeySelective(record); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java index 9329b9a42..f05dc178b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java @@ -8,8 +8,10 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.IdWorker; import com.iformall.domain.po.WxAppinfo; +import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxScreenAd; import com.iformall.enums.EnumScreenAdType; +import com.iformall.mapper.WxCouponChannelMapper; import com.iformall.mapper.WxScreenAdMapper; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxScreenAdService; @@ -38,6 +40,9 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { @Autowired WxAppinfoService wxAppinfoService; + @Autowired + WxCouponChannelMapper wxCouponChannelMapper; + @Override public PageInfo listAsPage(WxScreenAd record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxScreenAdMapper.findList(record)); @@ -76,6 +81,35 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { } + @Override + public void updateStatusByCouponChannelId(Long couponChannelId, String tenantId, int status) { + WxScreenAd wxScreenAd = new WxScreenAd(); + wxScreenAd.setTenantId(tenantId); + wxScreenAd.setStatus(status); + wxScreenAd.setTargetId(couponChannelId); + wxScreenAd.setUpdateDate(new Date()); + wxScreenAdMapper.updateStatusByCouponChannelId(wxScreenAd); + } + + @Override + public void updateStatusByCouponId(Long couponId, String tenantId, int status) { + + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + wxCouponChannel.setTenantId(tenantId); + wxCouponChannel.setCouponId(couponId); + + List list = wxCouponChannelMapper.findList(wxCouponChannel); + + list.stream().forEach(cc->{ + WxScreenAd wxScreenAd = new WxScreenAd(); + wxScreenAd.setTenantId(tenantId); + wxScreenAd.setStatus(status); + wxScreenAd.setTargetId(cc.getId()); + wxScreenAd.setUpdateDate(new Date()); + wxScreenAdMapper.updateStatusByCouponChannelId(wxScreenAd); + }); + } + private void setQrcode(WxScreenAd record){ if (record.getTargetId() != null && diff --git a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml index 46379e439..a0893618a 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml @@ -102,7 +102,8 @@ - update wx_coupon_channel set status=#{status} + update wx_coupon_channel + set status=#{status}, update_date=#{updateDate} where coupon_id=#{couponId} and tenant_id = #{tenantId} diff --git a/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml b/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml index 78a85ed1a..c2cd4a275 100644 --- a/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml @@ -64,12 +64,28 @@ order by ${sortColumns} - select from wx_screen_ad + + update wx_screen_ad sa + set sa.status = #{status}, sa.update_date = #{updateDate} + where sa.target_id = #{targetId} + + and tenant_id = #{tenantId} + + + + + update wx_screen_ad sa, wx_coupon_channel cc + SET sa.status = 1, sa.update_date = now() + where sa.status = 0 + and sa.target_id = cc.id + and cc.status = 1 +