| @@ -0,0 +1,52 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.service.*; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| @RestController | |||||
| @RequestMapping("topic") | |||||
| @Api(description = "专题相关接口") | |||||
| public class WxTopicController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxTopicService wxTopicService; | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(WxTopic wxTopic, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::list"); | |||||
| String tenantId = getTenantId(); | |||||
| wxTopic.setTenantId(tenantId); | |||||
| PageInfo<WxTopic> page = wxTopicService.listAsPage(wxTopic, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @PostMapping("saveOrUpdate") | |||||
| public ResultData saveOrUpdate(@RequestBody WxTopic wxTopic) { | |||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::saveOrUpdate"); | |||||
| wxTopicService.saveOrUpdate(wxTopic); | |||||
| return new ResultData(); | |||||
| } | |||||
| @GetMapping("show") | |||||
| public ResultData show() { | |||||
| logger.debug("[" + getIpAddr() + "] WxTopicController::show"); | |||||
| WxTopic wxTopic = new WxTopic(); | |||||
| String tenantId = getTenantId(); | |||||
| wxTopic.setTenantId(tenantId); | |||||
| return new ResultData(wxTopicService.show(wxTopic)); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,61 @@ | |||||
| package com.iformall.domain.po; | |||||
| import javax.persistence.Id; | |||||
| import javax.persistence.Table; | |||||
| import java.io.Serializable; | |||||
| @Table(name = "wx_coupon_topic") | |||||
| public class WxCouponTopic implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||||
| private String tenantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="专题ID",name="topicId") | |||||
| private Long topicId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="业务类型1通用卷2满减卷3代金卷4礼品卷5停车卷6砍价商品7拼团商品",name="busType") | |||||
| private String busType; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="busId") | |||||
| private String busId; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| } | |||||
| public Long getTopicId() { | |||||
| return topicId; | |||||
| } | |||||
| public void setTopicId(Long topicId) { | |||||
| this.topicId = topicId; | |||||
| } | |||||
| public String getBusType() { | |||||
| return busType; | |||||
| } | |||||
| public void setBusType(String busType) { | |||||
| this.busType = busType; | |||||
| } | |||||
| public String getBusId() { | |||||
| return busId; | |||||
| } | |||||
| public void setBusId(String busId) { | |||||
| this.busId = busId; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,196 @@ | |||||
| package com.iformall.domain.po; | |||||
| import javax.persistence.Id; | |||||
| import javax.persistence.Table; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| @Table(name = "wx_topic") | |||||
| public class WxTopic implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| /*租户ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||||
| private String tenantId; | |||||
| /*名称**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="名称",name="name") | |||||
| private String name; | |||||
| /*标题**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="标题",name="title") | |||||
| private String title; | |||||
| /*内容**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="内容",name="content") | |||||
| private String content; | |||||
| /*封面**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="封面",name="cover") | |||||
| private String cover; | |||||
| /*广告图**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="广告图",name="advert") | |||||
| private String advert; | |||||
| /*开始时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="开始时间",name="beginTime") | |||||
| private Date beginTime; | |||||
| /*结束时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="结束时间",name="endTime") | |||||
| private Date endTime; | |||||
| /*状态1投放2作废**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="状态",name="status") | |||||
| private Integer status; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | |||||
| private Date createtime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updatetime") | |||||
| private Date updatetime; | |||||
| /*优惠券ids**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="优惠券ids",name="couponIds") | |||||
| private String couponIds; | |||||
| @Transient | |||||
| private String couponName; | |||||
| @Transient | |||||
| private String couponPic; | |||||
| @Transient | |||||
| private String couponId; | |||||
| public String getCouponName() { | |||||
| return couponName; | |||||
| } | |||||
| public void setCouponName(String couponName) { | |||||
| this.couponName = couponName; | |||||
| } | |||||
| public String getCouponPic() { | |||||
| return couponPic; | |||||
| } | |||||
| public void setCouponPic(String couponPic) { | |||||
| this.couponPic = couponPic; | |||||
| } | |||||
| public String getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(String couponId) { | |||||
| this.couponId = couponId; | |||||
| } | |||||
| public List<WxCoupon> getCouponList() { | |||||
| return couponList; | |||||
| } | |||||
| public void setCouponList(List<WxCoupon> couponList) { | |||||
| this.couponList = couponList; | |||||
| } | |||||
| private List<WxCoupon> couponList; | |||||
| public String getCouponIds() { | |||||
| return couponIds; | |||||
| } | |||||
| public void setCouponIds(String couponIds) { | |||||
| this.couponIds = couponIds; | |||||
| } | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| } | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public String getTitle() { | |||||
| return title; | |||||
| } | |||||
| public void setTitle(String title) { | |||||
| this.title = title; | |||||
| } | |||||
| public String getContent() { | |||||
| return content; | |||||
| } | |||||
| public void setContent(String content) { | |||||
| this.content = content; | |||||
| } | |||||
| public String getCover() { | |||||
| return cover; | |||||
| } | |||||
| public void setCover(String cover) { | |||||
| this.cover = cover; | |||||
| } | |||||
| public String getAdvert() { | |||||
| return advert; | |||||
| } | |||||
| public void setAdvert(String advert) { | |||||
| this.advert = advert; | |||||
| } | |||||
| public Date getBeginTime() { | |||||
| return beginTime; | |||||
| } | |||||
| public void setBeginTime(Date beginTime) { | |||||
| this.beginTime = beginTime; | |||||
| } | |||||
| public Date getEndTime() { | |||||
| return endTime; | |||||
| } | |||||
| public void setEndTime(Date endTime) { | |||||
| this.endTime = endTime; | |||||
| } | |||||
| public Integer getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(Integer status) { | |||||
| this.status = status; | |||||
| } | |||||
| public Date getCreatetime() { | |||||
| return createtime; | |||||
| } | |||||
| public void setCreatetime(Date createtime) { | |||||
| this.createtime = createtime; | |||||
| } | |||||
| public Date getUpdatetime() { | |||||
| return updatetime; | |||||
| } | |||||
| public void setUpdatetime(Date updatetime) { | |||||
| this.updatetime = updatetime; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,10 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxCouponTopic; | |||||
| public interface WxCouponTopicMapper extends CommonMapper<WxCouponTopic, String> { | |||||
| void del(WxCouponTopic couponTopic); | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxTopic; | |||||
| import java.util.List; | |||||
| public interface WxTopicMapper extends CommonMapper<WxTopic, String> { | |||||
| List<WxTopic> findList(WxTopic wxTopic); | |||||
| WxTopic show(WxTopic record); | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxTopic; | |||||
| public interface WxTopicService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<WxTopic> listAsPage(WxTopic record, Integer pageIndex, Integer pageSize); | |||||
| ResultData saveOrUpdate(WxTopic record); | |||||
| WxTopic show(WxTopic record); | |||||
| } | |||||
| @@ -0,0 +1,84 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.domain.po.WxCouponTopic; | |||||
| import com.iformall.domain.po.WxTopic; | |||||
| import com.iformall.mapper.WxCouponTopicMapper; | |||||
| import com.iformall.mapper.WxTopicMapper; | |||||
| import com.iformall.service.WxTopicService; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import com.iformall.common.ResultData; | |||||
| import java.util.Date; | |||||
| /** | |||||
| * @author luozukai ^_^ | |||||
| * @date 2019/3/28 17:02 | |||||
| */ | |||||
| public class WxTopicServiceImpl implements WxTopicService { | |||||
| @Autowired | |||||
| private WxTopicMapper wxTopicMapper; | |||||
| @Autowired | |||||
| private WxCouponTopicMapper wxCouponTopicMapper; | |||||
| @Override | |||||
| public PageInfo<WxTopic> listAsPage(WxTopic record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxTopicMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public WxTopic show(WxTopic record) { | |||||
| return wxTopicMapper.show(record); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(WxTopic record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| wxTopicMapper.insertSelective(record); | |||||
| if(StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| addCouponTopic(record); | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"添加成功"); | |||||
| } else { | |||||
| if(record.getStatus().equals(1)) { | |||||
| WxTopic queryTopic = new WxTopic(); | |||||
| queryTopic.setStatus(1); | |||||
| queryTopic.setTenantId(record.getTenantId()); | |||||
| if (wxTopicMapper.findList(queryTopic).size() > 0) { | |||||
| return new ResultData(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION.getCode(), "已有正在投放的专题"); | |||||
| } | |||||
| } | |||||
| record.setUpdatetime(new Date()); | |||||
| wxTopicMapper.updateByPrimaryKeySelective(record); | |||||
| if(StringUtils.isNotBlank(record.getCouponIds())) { | |||||
| WxCouponTopic delCouponTopic = new WxCouponTopic(); | |||||
| delCouponTopic.setTopicId(record.getId()); | |||||
| wxCouponTopicMapper.del(delCouponTopic); | |||||
| addCouponTopic(record); | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"更新成功"); | |||||
| } | |||||
| } | |||||
| public void addCouponTopic(WxTopic record){ | |||||
| for (String couponId:JSONArray.parseArray(record.getCouponIds(), String.class)) { | |||||
| String[] couponArray = couponId.split("-"); | |||||
| WxCouponTopic couponTopic = new WxCouponTopic(); | |||||
| couponTopic.setBusType(couponArray[0]); | |||||
| couponTopic.setBusId(couponArray[1]); | |||||
| couponTopic.setTenantId(record.getTenantId()); | |||||
| couponTopic.setTopicId(record.getId()); | |||||
| wxCouponTopicMapper.insertSelective(couponTopic); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,55 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxCouponTopicMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponTopic"> | |||||
| <id column="id" property="id" /> | |||||
| <result column="tenant_id" property="tenantId" /> | |||||
| <result column="name" property="name" /> | |||||
| <result column="title" property="title" /> | |||||
| <result column="content" property="content" /> | |||||
| <result column="cover" property="cover" /> | |||||
| <result column="advert" property="advert" /> | |||||
| <result column="begin_time" property="beginTime" /> | |||||
| <result column="end_time" property="endTime" /> | |||||
| <result column="status" property="status" /> | |||||
| <result column="createtime" property="createtime" /> | |||||
| <result column="updatetime" property="updatetime" /> | |||||
| </resultMap> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| </if> | |||||
| <if test=" null != name and '' != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | |||||
| <if test=" null != beginTime "> | |||||
| and `begin_time` >= #{beginTime} | |||||
| </if> | |||||
| <if test=" null != endTime "> | |||||
| and `end_time` <= #{endTime} | |||||
| </if> | |||||
| order by createtime desc | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | |||||
| select * from wx_topic | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <delete id="del" parameterType="com.iformall.domain.po.WxCouponTopic"> | |||||
| delete from wx_coupon_topic where topic_id = #{topicId} | |||||
| </delete> | |||||
| </mapper> | |||||
| @@ -0,0 +1,61 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxTopicMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxTopic"> | |||||
| <id column="id" property="id" /> | |||||
| <result column="tenant_id" property="tenantId" /> | |||||
| <result column="name" property="name" /> | |||||
| <result column="title" property="title" /> | |||||
| <result column="content" property="content" /> | |||||
| <result column="cover" property="cover" /> | |||||
| <result column="advert" property="advert" /> | |||||
| <result column="begin_time" property="beginTime" /> | |||||
| <result column="end_time" property="endTime" /> | |||||
| <result column="status" property="status" /> | |||||
| <result column="createtime" property="createtime" /> | |||||
| <result column="updatetime" property="updatetime" /> | |||||
| <result column="couponName" property="couponName" /> | |||||
| <result column="couponPic" property="couponPic" /> | |||||
| <result column="couponId" property="couponId" /> | |||||
| </resultMap> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| </if> | |||||
| <if test=" null != name and '' != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | |||||
| <if test=" null != beginTime "> | |||||
| and `begin_time` >= #{beginTime} | |||||
| </if> | |||||
| <if test=" null != endTime "> | |||||
| and `end_time` <= #{endTime} | |||||
| </if> | |||||
| order by createtime desc | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | |||||
| select * from wx_topic | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <select id="show" parameterType="com.iformall.domain.po.WxTopic" resultMap="BaseResultMap"> | |||||
| select t.*,wc.title as couponName,wc.`cover_img` as couponPic,wc.id as couponId | |||||
| from wx_topic t left join wx_coupon_topic ct on t.id = ct.`topic_id` | |||||
| left join wx_coupon wc on ct.bus_id = wc.id | |||||
| where t.status = 1 order by t.createtime desc limit 1 | |||||
| </select> | |||||
| </mapper> | |||||