diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFloatingLayerController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFloatingLayerController.java new file mode 100644 index 000000000..e790d00a2 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFloatingLayerController.java @@ -0,0 +1,88 @@ +package com.iformall.controller.market; + +import com.github.pagehelper.PageInfo; +import com.iformall.annotation.SystemControllerLog; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.controller.base.BaseController; +import com.iformall.domain.po.BaseEntity; +import com.iformall.domain.po.WxFloatingLayer; +import com.iformall.enums.EnumFloatingLayerStatus; +import com.iformall.exception.MallinkException; +import com.iformall.service.WxFloatingLayerService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @author gongbiao + */ +@RestController +@RequestMapping("wxFloatingLayer") +@Api(description = "首页浮层展示") +public class WxFloatingLayerController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxFloatingLayerService wxFloatingLayerService; + + @ApiOperation("分页列表接口") + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + @SystemControllerLog(description = "列表") + public ResultData list(@ModelAttribute WxFloatingLayer wxFloatingLayer, Integer pageNum, Integer pageSize) { + logger.debug("[" + getIpAddr() + "] WxFloatingLayerController::list"); + wxFloatingLayer.setTenantId(getTenantId()); + wxFloatingLayer.setSortColumns(BaseEntity.SortField.CreateTime_DESC, BaseEntity.SortField.Id_DESC); + final PageInfo page = wxFloatingLayerService.listAsPage(wxFloatingLayer, pageNum, pageSize); + return new ResultData(page); + } + + @ApiOperation("新增接口") + @PostMapping("add") + @SystemControllerLog(description = "新增") + public ResultData add(@RequestBody WxFloatingLayer wxFloatingLayer) { + logger.debug("[" + getIpAddr() + "] WxFloatingLayerController::add"); + wxFloatingLayer.setStatus(EnumFloatingLayerStatus.STATUS_THROW_IN.getCode()); + wxFloatingLayer.setTenantId(getTenantId()); + try { + wxFloatingLayerService.saveOrUpdate(wxFloatingLayer); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + return new ResultData(); + } + + @ApiOperation("根据id更新接口") + @PostMapping("update") + @SystemControllerLog(description = "id更新") + public ResultData update(@RequestBody WxFloatingLayer wxFloatingLayer) { + logger.debug("[" + getIpAddr() + "] WxFloatingLayerController::update"); + try { + wxFloatingLayer.setStatus(EnumFloatingLayerStatus.STATUS_TAKE_OFFF.getCode()); + return wxFloatingLayerService.saveOrUpdate(wxFloatingLayer); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + } + + @ApiOperation("根据id查询接口") + @GetMapping("/findById") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "活动-查询") + public ResultData findById(Long id) { + logger.debug("[" + getIpAddr() + "] WxFloatingLayerController::findById"); + WxFloatingLayer wxFloatingLayer = wxFloatingLayerService.getById(id); + return new ResultData(Result.SUCCESS, "查询成功", wxFloatingLayer); + } + +} diff --git a/mallinkAdmin/src/main/resources/db/migration/V201909181530__G_FLOTING_LAYER.sql b/mallinkAdmin/src/main/resources/db/migration/V201909181530__G_FLOTING_LAYER.sql new file mode 100644 index 000000000..787fa41e3 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201909181530__G_FLOTING_LAYER.sql @@ -0,0 +1,22 @@ +create table wx_floting_layer( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `tenant_id` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', + `cover_img` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '封面图', + `produce_id` bigint(20) DEFAULT NULL COMMENT '产品ID', + `page_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '小程序跳转路径', + `status` smallint(2) DEFAULT NULL COMMENT '0上线 1下线', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP, + `update_time` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `id_UNIQUE` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='首页浮层'; + + +create table wx_cuser_floting_layer( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `tenant_id` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', + `user_id` bigint(20) DEFAULT NULL COMMENT 'C端用户ID', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `id_UNIQUE` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户首页浮层记录'; diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java new file mode 100755 index 000000000..9df67b6c2 --- /dev/null +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java @@ -0,0 +1,40 @@ +package com.iformall.controller; + +import com.iformall.annotation.AuthIgnore; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxFloatingLayer; +import com.iformall.service.WxCuserFloatingLayerService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author gongbiao + */ +@RestController +@RequestMapping("/api/floatingLayer") +@Api(description = "首页浮层") +public class WxCuserFloatingLayerController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCuserFloatingLayerService wxCuserFloatingLayerService; + + @AuthIgnore + @ApiOperation("获取浮层") + @GetMapping("/getFloatingLayer") + @ApiImplicitParam(name = "openId", value = "openId", dataType = "String", paramType = "query", required = true) + public ResultData getAppIcon(String openId) { + WxFloatingLayer wxFloatingLayer = wxCuserFloatingLayerService.getFloatingLayer(openId); + return new ResultData(Result.SUCCESS, "查询成功", wxFloatingLayer); + } + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCuserFloatingLayer.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCuserFloatingLayer.java new file mode 100644 index 000000000..3fe26a8ed --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCuserFloatingLayer.java @@ -0,0 +1,26 @@ +package com.iformall.domain.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +@TableName(value = "wx_cuser_floating_layer") +@Data +@EqualsAndHashCode(callSuper = true) +public class WxCuserFloatingLayer extends BaseEntity { + private static final long serialVersionUID = 1L; + + protected Long id; + + @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") + private String tenantId; + + @io.swagger.annotations.ApiModelProperty(value = "C端用户ID", name = "userId") + private Long userId; + + @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createTime") + private Date createTime; + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxFloatingLayer.java b/mallinkService/src/main/java/com/iformall/domain/po/WxFloatingLayer.java new file mode 100644 index 000000000..16884eb36 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxFloatingLayer.java @@ -0,0 +1,38 @@ +package com.iformall.domain.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +@TableName(value = "wx_floating_layer") +@Data +@EqualsAndHashCode(callSuper = true) +public class WxFloatingLayer extends BaseEntity { + private static final long serialVersionUID = 1L; + + protected Long id; + + @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") + private String tenantId; + + @io.swagger.annotations.ApiModelProperty(value = "封面图", name = "coverImg") + private String coverImg; + + @io.swagger.annotations.ApiModelProperty(value = "产品ID", name = "produceId") + private Long produceId; + + @io.swagger.annotations.ApiModelProperty(value = "小程序跳转路径", name = "pagePath") + private String pagePath; + + @io.swagger.annotations.ApiModelProperty(value = "0上线 1下线", 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; + +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumFloatingLayerStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumFloatingLayerStatus.java new file mode 100644 index 000000000..1e44a7965 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumFloatingLayerStatus.java @@ -0,0 +1,36 @@ +package com.iformall.enums; + + +/** + * @author gongbiao + */ +public enum EnumFloatingLayerStatus { + + STATUS_THROW_IN(0, "已上线"), + STATUS_TAKE_OFFF(1, "已下线"),; + + public static EnumFloatingLayerStatus getEnum(Integer code) { + for (EnumFloatingLayerStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumFloatingLayerStatus(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/iformall/mapper/WxCuserFloatingLayerMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCuserFloatingLayerMapper.java new file mode 100644 index 000000000..69fd62302 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCuserFloatingLayerMapper.java @@ -0,0 +1,15 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxCuserFloatingLayer; + +import java.util.List; + +/** + * @author gongbiao + */ +public interface WxCuserFloatingLayerMapper extends CommonMapper { + + List findList(WxCuserFloatingLayer wxCuserFloatingLayer); + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxFloatingLayerMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxFloatingLayerMapper.java new file mode 100644 index 000000000..c914083ef --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxFloatingLayerMapper.java @@ -0,0 +1,15 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxFloatingLayer; + +import java.util.List; + +/** + * @author gongbiao + */ +public interface WxFloatingLayerMapper extends CommonMapper { + + List findList(WxFloatingLayer wxFloatingLayer); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java b/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java new file mode 100644 index 000000000..6e175d55f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java @@ -0,0 +1,12 @@ +package com.iformall.service; + +import com.iformall.domain.po.WxFloatingLayer; + +/** + * @author gongbiao + */ +public interface WxCuserFloatingLayerService { + + WxFloatingLayer getFloatingLayer(String openId); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxFloatingLayerService.java b/mallinkService/src/main/java/com/iformall/service/WxFloatingLayerService.java new file mode 100644 index 000000000..f814f03c2 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxFloatingLayerService.java @@ -0,0 +1,38 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxFloatingLayer; + +/** + * @author gongbiao + */ +public interface WxFloatingLayerService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @param pageIndex + * @param pageSize + * @return + */ + PageInfo listAsPage(WxFloatingLayer record, Integer pageIndex, Integer pageSize); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + WxFloatingLayer getById(Long id); + + /** + * 保存或更新实体 + * + * @param record + */ + ResultData saveOrUpdate(WxFloatingLayer record); + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java new file mode 100644 index 000000000..4b2e792cb --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java @@ -0,0 +1,73 @@ +package com.iformall.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.iformall.common.IdWorker; +import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxCuserFloatingLayer; +import com.iformall.domain.po.WxFloatingLayer; +import com.iformall.enums.EnumFloatingLayerStatus; +import com.iformall.mapper.WxCUserMapper; +import com.iformall.mapper.WxCuserFloatingLayerMapper; +import com.iformall.mapper.WxFloatingLayerMapper; +import com.iformall.service.WxCuserFloatingLayerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + * @author gongbiao + */ +@Service +public class WxCuserFloatingLayerServiceImpl implements WxCuserFloatingLayerService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCuserFloatingLayerMapper WxCuserFloatingLayerMapper; + + @Autowired + WxFloatingLayerMapper WxFloatingLayerMapper; + + @Autowired + WxCUserMapper WxCUserMapper; + + + @Override + public WxFloatingLayer getFloatingLayer(String openId) { + //1 查看是否存在用户,用户不存在 直接返回浮层信息 + WxCUser user = new WxCUser(); + user.setOpenId(openId); + WxCUser byOpenId = WxCUserMapper.findByOpenId(user); + if (byOpenId == null) { + return getWxFloatingLayer(); + } + //2 用户存在 查看是否已有弹出记录 没有 保存记录后返回浮层信息 + WxCuserFloatingLayer wxCuserFloatingLayerQuery = new WxCuserFloatingLayer(); + wxCuserFloatingLayerQuery.setUserId(byOpenId.getId()); + WxCuserFloatingLayer wxCuserFloatingLayer = WxCuserFloatingLayerMapper.selectOne(new QueryWrapper<>(wxCuserFloatingLayerQuery)); + if (wxCuserFloatingLayer == null) { + saveCuserFloatingLayer(byOpenId); + return getWxFloatingLayer(); + } + return null; + } + + public void saveCuserFloatingLayer(WxCUser wxCUser) { + WxCuserFloatingLayer wxCuserFloatingLayer; + wxCuserFloatingLayer = new WxCuserFloatingLayer(); + final IdWorker idWorker = IdWorker.get(); + wxCuserFloatingLayer.setId(idWorker.nextId()); + wxCuserFloatingLayer.setUserId(wxCUser.getId()); + wxCuserFloatingLayer.setTenantId(wxCUser.getTenantId()); + wxCuserFloatingLayer.setCreateTime(new Date()); + WxCuserFloatingLayerMapper.insert(wxCuserFloatingLayer); + } + + public WxFloatingLayer getWxFloatingLayer() { + WxFloatingLayer wxFloatingLayer = new WxFloatingLayer(); + wxFloatingLayer.setStatus(EnumFloatingLayerStatus.STATUS_THROW_IN.getCode()); + return WxFloatingLayerMapper.selectOne(new QueryWrapper<>(wxFloatingLayer)); + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFloatingLayerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFloatingLayerServiceImpl.java new file mode 100644 index 000000000..0161c88fd --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFloatingLayerServiceImpl.java @@ -0,0 +1,65 @@ +package com.iformall.service.impl; + +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.common.ResultData; +import com.iformall.domain.po.WxFloatingLayer; +import com.iformall.mapper.WxFloatingLayerMapper; +import com.iformall.service.WxFloatingLayerService; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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; + +/** + * @author gongbiao + */ +@Service +public class WxFloatingLayerServiceImpl implements WxFloatingLayerService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxFloatingLayerMapper WxFloatingLayerMapper; + + @Override + public PageInfo listAsPage(WxFloatingLayer record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> WxFloatingLayerMapper.findList(record)); + } + + @Override + public WxFloatingLayer getById(Long id) { + return WxFloatingLayerMapper.selectById(id); + } + + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + @Override + public ResultData saveOrUpdate(WxFloatingLayer wxFloatingLayer) { + if (StringUtils.isEmpty(wxFloatingLayer.getCoverImg())) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "封面图不能为空"); + } + if (StringUtils.isEmpty(wxFloatingLayer.getPagePath())) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "小程序跳转路径不能为空"); + } + Date date = new Date(); + if (wxFloatingLayer.getId() == null) { + final IdWorker idWorker = IdWorker.get(); + wxFloatingLayer.setId(idWorker.nextId()); + wxFloatingLayer.setCreateTime(date); + wxFloatingLayer.setUpdateTime(date); + WxFloatingLayerMapper.insert(wxFloatingLayer); + } else { + wxFloatingLayer.setUpdateTime(date); + WxFloatingLayerMapper.updateById(wxFloatingLayer); + } + return new ResultData(Result.SUCCESS, "操作成功"); + } + +} diff --git a/mallinkService/src/main/resources/mapper/WxCuserFloatingLayer.xml b/mallinkService/src/main/resources/mapper/WxCuserFloatingLayer.xml new file mode 100644 index 000000000..a2c2feec4 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxCuserFloatingLayer.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + `id`, `tenant_id` , `user_id` , `create_time` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + + and `user_id` = #{user_id} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxFloatingLayer.xml b/mallinkService/src/main/resources/mapper/WxFloatingLayer.xml new file mode 100644 index 000000000..376b88eac --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxFloatingLayer.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + `id`, `tenant_id` , `cover_img` , `produce_id`, `page_path` , `status`, `create_time`, `update_time` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + + and `status` = #{status} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + +