| @@ -2,14 +2,17 @@ package com.iformall.controller.market; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumWxTopicStatus; | import com.iformall.enums.EnumWxTopicStatus; | ||||
| import com.iformall.enums.EnumWxTopicType; | |||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -32,6 +35,7 @@ public class WxTopicController extends BaseController { | |||||
| public ResultData list(WxTopic wxTopic, Integer pageNum, Integer pageSize) { | public ResultData list(WxTopic wxTopic, Integer pageNum, Integer pageSize) { | ||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::list"); | logger.debug("[" + getIpAddr() + "] WxTopicController::list"); | ||||
| wxTopic.updateTenantInfo(getTenantInfo()); | wxTopic.updateTenantInfo(getTenantInfo()); | ||||
| wxTopic.setTopicType(EnumWxTopicType.SPECIAL_TOPIC.getCode()); | |||||
| PageInfo<WxTopic> page = wxTopicService.listAsPage(wxTopic, pageNum, pageSize); | PageInfo<WxTopic> page = wxTopicService.listAsPage(wxTopic, pageNum, pageSize); | ||||
| //可投放、已上线,时间区间查的是活动开始时间 | //可投放、已上线,时间区间查的是活动开始时间 | ||||
| @@ -59,13 +63,45 @@ public class WxTopicController extends BaseController { | |||||
| return new ResultData(queryTopic); | return new ResultData(queryTopic); | ||||
| } | } | ||||
| @PostMapping("saveOrUpdate") | @PostMapping("saveOrUpdate") | ||||
| @SystemControllerLog(description = "专题-保存更新") | @SystemControllerLog(description = "专题-保存更新") | ||||
| public ResultData saveOrUpdate(@RequestBody WxTopic wxTopic) { | public ResultData saveOrUpdate(@RequestBody WxTopic wxTopic) { | ||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::saveOrUpdate"); | logger.debug("[" + getIpAddr() + "] WxTopicController::saveOrUpdate"); | ||||
| wxTopic.updateTenantInfo(getTenantInfo()); | wxTopic.updateTenantInfo(getTenantInfo()); | ||||
| if(wxTopic.getTopicType() == null){ | |||||
| wxTopic.setTopicType(EnumWxTopicType.SPECIAL_TOPIC.getCode()); | |||||
| } | |||||
| return wxTopicService.saveOrUpdate(wxTopic); | return wxTopicService.saveOrUpdate(wxTopic); | ||||
| } | } | ||||
| @GetMapping("findByType") | |||||
| @SystemControllerLog(description = "专题-获取详情") | |||||
| public ResultData findByType(Integer topicType) { | |||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::findByType"); | |||||
| if(topicType == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| WxTopic wxTopic = new WxTopic(); | |||||
| wxTopic.updateTenantInfo(getTenantInfo()); | |||||
| wxTopic.setTopicType(topicType); | |||||
| WxTopic queryTopic = wxTopicService.findByType(wxTopic); | |||||
| return new ResultData(queryTopic); | |||||
| } | |||||
| @PostMapping("updateByType") | |||||
| @SystemControllerLog(description = "专题-保存更新") | |||||
| public ResultData updateByType(@RequestBody WxTopic wxTopic) { | |||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::updateByType"); | |||||
| wxTopic.updateTenantInfo(getTenantInfo()); | |||||
| if(wxTopic.getTopicType() == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| wxTopic.setName(EnumWxTopicType.getEnum(wxTopic.getTopicType()).getMessage()); | |||||
| if(StringUtils.isBlank(wxTopic.getName())){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| return wxTopicService.saveOrUpdate(wxTopic); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,2 @@ | |||||
| ALTER TABLE `mallink`.`wx_topic` | |||||
| ADD COLUMN `topic_type` smallint(3) NOT NULL DEFAULT 1 COMMENT 'EnumWxTopicType' AFTER `parent_tenant_id`; | |||||
| @@ -3,6 +3,7 @@ package com.iformall.domain.po; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | import com.baomidou.mybatisplus.annotation.TableField; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.enums.EnumWxTopicType; | |||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import lombok.Data; | import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||
| @@ -19,6 +20,8 @@ public class WxTopic extends TenantEntity { | |||||
| protected Long id; | protected Long id; | ||||
| @io.swagger.annotations.ApiModelProperty(value="专题类型",name="topicType") | |||||
| private Integer topicType; | |||||
| @io.swagger.annotations.ApiModelProperty(value="名称",name="name") | @io.swagger.annotations.ApiModelProperty(value="名称",name="name") | ||||
| private String name; | private String name; | ||||
| @io.swagger.annotations.ApiModelProperty(value="标题",name="title") | @io.swagger.annotations.ApiModelProperty(value="标题",name="title") | ||||
| @@ -81,12 +84,16 @@ public class WxTopic extends TenantEntity { | |||||
| public String getWeappPath() { | public String getWeappPath() { | ||||
| if(id == null) | if(id == null) | ||||
| return Constant.mainPageUrl; | return Constant.mainPageUrl; | ||||
| return Constant.mainPageUrl + "?type=td&id="+id; | |||||
| if(EnumWxTopicType.SPECIAL_TOPIC.getCode().equals(topicType)) | |||||
| return Constant.mainPageUrl + "?type=td&id="+id; | |||||
| return Constant.mainPageUrl; | |||||
| } | } | ||||
| public String getWeappScene() { | public String getWeappScene() { | ||||
| if(id == null) | if(id == null) | ||||
| return ""; | return ""; | ||||
| return "t:td:" + id; | |||||
| if(EnumWxTopicType.SPECIAL_TOPIC.getCode().equals(topicType)) | |||||
| return "t:td:" + id; | |||||
| return ""; | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,40 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by | |||||
| */ | |||||
| public enum EnumWxTopicType { | |||||
| SPECIAL_TOPIC(1, "默认专题"), | |||||
| FLASH_SALE(2, "限时抢购"), | |||||
| PRESS(3, "砍价专区"), | |||||
| GROUP(4, "拼团专区"), | |||||
| CARD_MULTIMCH(5, "消费卡"), | |||||
| CREDIT(6, "积分商城"), | |||||
| ; | |||||
| public static EnumWxTopicType getEnum(Integer code) { | |||||
| for (EnumWxTopicType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumWxTopicType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -26,5 +26,5 @@ public interface WxTopicService { | |||||
| WxTopic findById(WxTopic record); | WxTopic findById(WxTopic record); | ||||
| WxTopic findByType(WxTopic wxTopic); | |||||
| } | } | ||||
| @@ -12,6 +12,7 @@ import com.iformall.domain.po.WxTopic; | |||||
| import com.iformall.enums.EnumCouponChannelType; | import com.iformall.enums.EnumCouponChannelType; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.enums.EnumWxTopicStatus; | import com.iformall.enums.EnumWxTopicStatus; | ||||
| import com.iformall.enums.EnumWxTopicType; | |||||
| import com.iformall.mapper.WxCouponChannelMapper; | import com.iformall.mapper.WxCouponChannelMapper; | ||||
| import com.iformall.mapper.WxCouponMapper; | import com.iformall.mapper.WxCouponMapper; | ||||
| import com.iformall.mapper.WxTopicMapper; | import com.iformall.mapper.WxTopicMapper; | ||||
| @@ -109,19 +110,22 @@ public class WxTopicServiceImpl implements WxTopicService { | |||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| wxTopicMapper.insert(record); | wxTopicMapper.insert(record); | ||||
| if(StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| if(EnumWxTopicType.SPECIAL_TOPIC.getCode().equals(record.getTopicType()) | |||||
| && StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| addCouponTopic(record); | addCouponTopic(record); | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS,"添加成功"); | return new ResultData(Result.SUCCESS,"添加成功"); | ||||
| } else { | } else { | ||||
| record.setUpdatetime(new Date()); | record.setUpdatetime(new Date()); | ||||
| wxTopicMapper.updateById(record); | wxTopicMapper.updateById(record); | ||||
| if(StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| //优化:区分添加的和删除的 | |||||
| wxCouponChannelMapper.delByTopic(record); | |||||
| addCouponTopic(record); | |||||
| if(EnumWxTopicType.SPECIAL_TOPIC.getCode().equals(record.getTopicType())){ | |||||
| if(StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| //优化:区分添加的和删除的 | |||||
| wxCouponChannelMapper.delByTopic(record); | |||||
| addCouponTopic(record); | |||||
| } | |||||
| wxTopicMapper.couponDownLine(record); | |||||
| } | } | ||||
| wxTopicMapper.couponDownLine(record); | |||||
| return new ResultData(Result.SUCCESS,"更新成功"); | return new ResultData(Result.SUCCESS,"更新成功"); | ||||
| } | } | ||||
| } | } | ||||
| @@ -166,20 +170,31 @@ public class WxTopicServiceImpl implements WxTopicService { | |||||
| @Override | @Override | ||||
| public WxTopic findById(WxTopic record) { | public WxTopic findById(WxTopic record) { | ||||
| WxTopic wxTopic = wxTopicMapper.selectById(record.getId()); | WxTopic wxTopic = wxTopicMapper.selectById(record.getId()); | ||||
| List<WxCoupon> wxCouponList = wxCouponMapper.findCouponByTopic(record); | |||||
| wxTopic.setCouponList(wxCouponList); | |||||
| String couponIds = ""; | |||||
| if(CollectionUtils.isNotEmpty(wxCouponList)) { | |||||
| for (int i = 0; i < wxCouponList.size(); i++) { | |||||
| WxCoupon wxCoupon = wxCouponList.get(i); | |||||
| if (i == wxCouponList.size() - 1) { | |||||
| couponIds += wxCoupon.getType() +"-"+ wxCoupon.getId().toString(); | |||||
| } else { | |||||
| couponIds += wxCoupon.getType() +"-"+ wxCoupon.getId().toString() + ","; | |||||
| if(EnumWxTopicType.SPECIAL_TOPIC.getCode().equals(record.getTopicType())){ | |||||
| List<WxCoupon> wxCouponList = wxCouponMapper.findCouponByTopic(record); | |||||
| wxTopic.setCouponList(wxCouponList); | |||||
| String couponIds = ""; | |||||
| if(CollectionUtils.isNotEmpty(wxCouponList)) { | |||||
| for (int i = 0; i < wxCouponList.size(); i++) { | |||||
| WxCoupon wxCoupon = wxCouponList.get(i); | |||||
| if (i == wxCouponList.size() - 1) { | |||||
| couponIds += wxCoupon.getType() +"-"+ wxCoupon.getId().toString(); | |||||
| } else { | |||||
| couponIds += wxCoupon.getType() +"-"+ wxCoupon.getId().toString() + ","; | |||||
| } | |||||
| } | } | ||||
| wxTopic.setCouponIds(couponIds); | |||||
| } | } | ||||
| wxTopic.setCouponIds(couponIds); | |||||
| } | } | ||||
| return wxTopic; | return wxTopic; | ||||
| } | } | ||||
| @Override | |||||
| public WxTopic findByType(WxTopic wxTopic) { | |||||
| List<WxTopic> list = wxTopicMapper.findList(wxTopic); | |||||
| if(list != null && list.size() > 0){ | |||||
| return list.get(0); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| } | } | ||||
| @@ -5,6 +5,7 @@ | |||||
| <id column="id" property="id"/> | <id column="id" property="id"/> | ||||
| <result column="tenant_id" property="tenantId"/> | <result column="tenant_id" property="tenantId"/> | ||||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | ||||
| <result column="topic_type" jdbcType="INTEGER" property="topicType"/> | |||||
| <result column="name" property="name"/> | <result column="name" property="name"/> | ||||
| <result column="title" property="title"/> | <result column="title" property="title"/> | ||||
| <result column="content" property="content"/> | <result column="content" property="content"/> | ||||
| @@ -22,7 +23,7 @@ | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`name`,`title`,`content`,`cover`,`cover_picture`,`detail_picture`,`advert`,`begin_time`,`end_time`,`createtime`,`updatetime`,`bg_color` | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`topic_type`,`name`,`title`,`content`,`cover`,`cover_picture`,`detail_picture`,`advert`,`begin_time`,`end_time`,`createtime`,`updatetime`,`bg_color` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -37,6 +38,10 @@ | |||||
| and `parent_tenant_id` = #{parentTenantId} | and `parent_tenant_id` = #{parentTenantId} | ||||
| </if> | </if> | ||||
| <if test=" null != topicType"> | |||||
| and `topic_type` = #{topicType} | |||||
| </if> | |||||
| <if test='statusStr =="0,2" or status==1'> | <if test='statusStr =="0,2" or status==1'> | ||||
| <if test=" null != beginTime "> | <if test=" null != beginTime "> | ||||
| and `begin_time` >= #{beginTime} | and `begin_time` >= #{beginTime} | ||||
| @@ -83,7 +88,7 @@ | |||||
| <select id="show" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | <select id="show" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | ||||
| select t.* from wx_topic t | select t.* from wx_topic t | ||||
| where t.status = 1 | |||||
| where t.status = 1 and t.`topic_type` = 1 | |||||
| and now() >= t.begin_time and now() <= t.end_time | and now() >= t.begin_time and now() <= t.end_time | ||||
| and t.tenant_id = #{tenantId} | and t.tenant_id = #{tenantId} | ||||
| order by t.begin_time desc limit 1 | order by t.begin_time desc limit 1 | ||||
| @@ -91,7 +96,7 @@ | |||||
| <select id="showList" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | <select id="showList" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | ||||
| select t.* from wx_topic t | select t.* from wx_topic t | ||||
| where t.status = 1 | |||||
| where t.status = 1 and t.`topic_type` = 1 | |||||
| and now() >= t.begin_time and now() <= t.end_time | and now() >= t.begin_time and now() <= t.end_time | ||||
| and t.tenant_id = #{tenantId} | and t.tenant_id = #{tenantId} | ||||
| order by t.begin_time desc | order by t.begin_time desc | ||||
| @@ -100,14 +105,14 @@ | |||||
| <update id="updateStatus" parameterType="com.iformall.domain.po.WxTopic"> | <update id="updateStatus" parameterType="com.iformall.domain.po.WxTopic"> | ||||
| update wx_topic set status = 3 where id in( | update wx_topic set status = 3 where id in( | ||||
| select t.id from ( | select t.id from ( | ||||
| select id from wx_topic where status !=3 and now() >= end_time and tenant_id = #{tenantId} | |||||
| select id from wx_topic where `topic_type` = 1 and status !=3 and now() >= end_time and tenant_id = #{tenantId} | |||||
| ) t | ) t | ||||
| ) | ) | ||||
| </update> | </update> | ||||
| <update id="couponDownLine" parameterType="com.iformall.domain.po.WxTopic"> | <update id="couponDownLine" parameterType="com.iformall.domain.po.WxTopic"> | ||||
| update wx_coupon_channel set status = 1 where status = 0 and target_ad = 8 and sub_target_id in( | update wx_coupon_channel set status = 1 where status = 0 and target_ad = 8 and sub_target_id in( | ||||
| select id from wx_topic where status in(2,3) and tenant_id = #{tenantId} | |||||
| select id from wx_topic where `topic_type` = 1 and status in(2,3) and tenant_id = #{tenantId} | |||||
| ) | ) | ||||
| </update> | </update> | ||||