浏览代码

[fix]
拼团banner生成代码

chenchen 2 月之前
父节点
当前提交
ae4d48103d

+ 293 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/controller/TourProjectGroupPurchaseBannerController.java

@@ -0,0 +1,293 @@
+package com.tourism.webadmin.back.controller;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.core.util.ReflectUtil;
+import com.tourism.common.core.upload.BaseUpDownloader;
+import com.tourism.common.core.upload.UpDownloaderFactory;
+import com.tourism.common.core.upload.UploadResponseInfo;
+import com.tourism.common.core.upload.UploadStoreInfo;
+import com.tourism.common.log.annotation.OperationLog;
+import com.tourism.common.log.model.constant.SysOperationLogType;
+import com.github.pagehelper.page.PageMethod;
+import com.tourism.webadmin.back.vo.*;
+import com.tourism.webadmin.back.dto.*;
+import com.tourism.webadmin.back.model.*;
+import com.tourism.webadmin.back.service.*;
+import com.tourism.common.core.object.*;
+import com.tourism.common.core.util.*;
+import com.tourism.common.core.constant.*;
+import com.tourism.common.core.annotation.MyRequestBody;
+import com.tourism.common.redis.cache.SessionCacheHelper;
+import com.tourism.common.additional.config.ApplicationConfig;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * 拼团首页banner操作控制器类。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Tag(name = "拼团首页banner管理接口")
+@Slf4j
+@RestController
+@RequestMapping("/admin/app/tourProjectGroupPurchaseBanner")
+public class TourProjectGroupPurchaseBannerController {
+
+    @Autowired
+    private ApplicationConfig appConfig;
+    @Autowired
+    private SessionCacheHelper cacheHelper;
+    @Autowired
+    private UpDownloaderFactory upDownloaderFactory;
+    @Autowired
+    private TourProjectGroupPurchaseBannerService tourProjectGroupPurchaseBannerService;
+
+    /**
+     * 新增拼团首页banner数据。
+     *
+     * @param tourProjectGroupPurchaseBannerDto 新增对象。
+     * @return 应答结果对象,包含新增对象主键Id。
+     */
+    @ApiOperationSupport(ignoreParameters = {"tourProjectGroupPurchaseBannerDto.id"})
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.add")
+    @OperationLog(type = SysOperationLogType.ADD)
+    @PostMapping("/add")
+    public ResponseResult<Long> add(@MyRequestBody TourProjectGroupPurchaseBannerDto tourProjectGroupPurchaseBannerDto) {
+        String errorMessage = MyCommonUtil.getModelValidationError(tourProjectGroupPurchaseBannerDto, false);
+        if (errorMessage != null) {
+            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
+        }
+        TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner = MyModelUtil.copyTo(tourProjectGroupPurchaseBannerDto, TourProjectGroupPurchaseBanner.class);
+        tourProjectGroupPurchaseBanner = tourProjectGroupPurchaseBannerService.saveNew(tourProjectGroupPurchaseBanner);
+        return ResponseResult.success(tourProjectGroupPurchaseBanner.getId());
+    }
+
+    /**
+     * 更新拼团首页banner数据。
+     *
+     * @param tourProjectGroupPurchaseBannerDto 更新对象。
+     * @return 应答结果对象。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.update")
+    @OperationLog(type = SysOperationLogType.UPDATE)
+    @PostMapping("/update")
+    public ResponseResult<Void> update(@MyRequestBody TourProjectGroupPurchaseBannerDto tourProjectGroupPurchaseBannerDto) {
+        String errorMessage = MyCommonUtil.getModelValidationError(tourProjectGroupPurchaseBannerDto, true);
+        if (errorMessage != null) {
+            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
+        }
+        TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner = MyModelUtil.copyTo(tourProjectGroupPurchaseBannerDto, TourProjectGroupPurchaseBanner.class);
+        TourProjectGroupPurchaseBanner originalTourProjectGroupPurchaseBanner = tourProjectGroupPurchaseBannerService.getById(tourProjectGroupPurchaseBanner.getId());
+        if (originalTourProjectGroupPurchaseBanner == null) {
+            // NOTE: 修改下面方括号中的话述
+            errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
+        }
+        if (!tourProjectGroupPurchaseBannerService.update(tourProjectGroupPurchaseBanner, originalTourProjectGroupPurchaseBanner)) {
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
+        }
+        return ResponseResult.success();
+    }
+
+    /**
+     * 删除拼团首页banner数据。
+     *
+     * @param id 删除对象主键Id。
+     * @return 应答结果对象。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.delete")
+    @OperationLog(type = SysOperationLogType.DELETE)
+    @PostMapping("/delete")
+    public ResponseResult<Void> delete(@MyRequestBody Long id) {
+        if (MyCommonUtil.existBlankArgument(id)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+        return this.doDelete(id);
+    }
+
+    /**
+     * 批量删除拼团首页banner数据。
+     *
+     * @param idList 待删除对象的主键Id列表。
+     * @return 应答结果对象。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.delete")
+    @OperationLog(type = SysOperationLogType.DELETE_BATCH)
+    @PostMapping("/deleteBatch")
+    public ResponseResult<Void> deleteBatch(@MyRequestBody List<Long> idList) {
+        if (MyCommonUtil.existBlankArgument(idList)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+        for (Long id : idList) {
+            ResponseResult<Void> responseResult = this.doDelete(id);
+            if (!responseResult.isSuccess()) {
+                return responseResult;
+            }
+        }
+        return ResponseResult.success();
+    }
+
+    /**
+     * 列出符合过滤条件的拼团首页banner列表。
+     *
+     * @param tourProjectGroupPurchaseBannerDtoFilter 过滤对象。
+     * @param orderParam 排序参数。
+     * @param pageParam 分页参数。
+     * @return 应答结果对象,包含查询结果集。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.view")
+    @PostMapping("/list")
+    public ResponseResult<MyPageData<TourProjectGroupPurchaseBannerVo>> list(
+            @MyRequestBody TourProjectGroupPurchaseBannerDto tourProjectGroupPurchaseBannerDtoFilter,
+            @MyRequestBody MyOrderParam orderParam,
+            @MyRequestBody MyPageParam pageParam) {
+        if (pageParam != null) {
+            PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getCount());
+        }
+        TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBannerFilter = MyModelUtil.copyTo(tourProjectGroupPurchaseBannerDtoFilter, TourProjectGroupPurchaseBanner.class);
+        String orderBy = MyOrderParam.buildOrderBy(orderParam, TourProjectGroupPurchaseBanner.class);
+        List<TourProjectGroupPurchaseBanner> tourProjectGroupPurchaseBannerList =
+                tourProjectGroupPurchaseBannerService.getTourProjectGroupPurchaseBannerListWithRelation(tourProjectGroupPurchaseBannerFilter, orderBy);
+        return ResponseResult.success(MyPageUtil.makeResponseData(tourProjectGroupPurchaseBannerList, TourProjectGroupPurchaseBannerVo.class));
+    }
+
+    /**
+     * 查看指定拼团首页banner对象详情。
+     *
+     * @param id 指定对象主键Id。
+     * @return 应答结果对象,包含对象详情。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.view")
+    @GetMapping("/view")
+    public ResponseResult<TourProjectGroupPurchaseBannerVo> view(@RequestParam Long id) {
+        TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner = tourProjectGroupPurchaseBannerService.getByIdWithRelation(id, MyRelationParam.full());
+        if (tourProjectGroupPurchaseBanner == null) {
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
+        }
+        TourProjectGroupPurchaseBannerVo tourProjectGroupPurchaseBannerVo = MyModelUtil.copyTo(tourProjectGroupPurchaseBanner, TourProjectGroupPurchaseBannerVo.class);
+        return ResponseResult.success(tourProjectGroupPurchaseBannerVo);
+    }
+
+    /**
+     * 附件文件下载。
+     * 这里将图片和其他类型的附件文件放到不同的父目录下,主要为了便于今后图片文件的迁移。
+     *
+     * @param id 附件所在记录的主键Id。
+     * @param fieldName 附件所属的字段名。
+     * @param filename  文件名。如果没有提供该参数,就从当前记录的指定字段中读取。
+     * @param asImage   下载文件是否为图片。
+     * @param response  Http 应答对象。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.view")
+    @OperationLog(type = SysOperationLogType.DOWNLOAD, saveResponse = false)
+    @GetMapping("/download")
+    public void download(
+            @RequestParam(required = false) Long id,
+            @RequestParam String fieldName,
+            @RequestParam String filename,
+            @RequestParam Boolean asImage,
+            HttpServletResponse response) {
+        if (MyCommonUtil.existBlankArgument(fieldName, filename, asImage)) {
+            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+            return;
+        }
+        // 使用try来捕获异常,是为了保证一旦出现异常可以返回500的错误状态,便于调试。
+        // 否则有可能给前端返回的是200的错误码。
+        try {
+            // 如果请求参数中没有包含主键Id,就判断该文件是否为当前session上传的。
+            if (id == null) {
+                if (!cacheHelper.existSessionUploadFile(filename)) {
+                    ResponseResult.output(HttpServletResponse.SC_FORBIDDEN);
+                    return;
+                }
+            } else {
+                TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner = tourProjectGroupPurchaseBannerService.getById(id);
+                if (tourProjectGroupPurchaseBanner == null) {
+                    ResponseResult.output(HttpServletResponse.SC_NOT_FOUND);
+                    return;
+                }
+                String fieldJsonData = (String) ReflectUtil.getFieldValue(tourProjectGroupPurchaseBanner, fieldName);
+                if (fieldJsonData == null && !cacheHelper.existSessionUploadFile(filename)) {
+                    ResponseResult.output(HttpServletResponse.SC_BAD_REQUEST);
+                    return;
+                }
+                if (!BaseUpDownloader.containFile(fieldJsonData, filename)
+                        && !cacheHelper.existSessionUploadFile(filename)) {
+                    ResponseResult.output(HttpServletResponse.SC_FORBIDDEN);
+                    return;
+                }
+            }
+            UploadStoreInfo storeInfo = MyModelUtil.getUploadStoreInfo(TourProjectGroupPurchaseBanner.class, fieldName);
+            if (!storeInfo.isSupportUpload()) {
+                ResponseResult.output(HttpServletResponse.SC_NOT_IMPLEMENTED,
+                        ResponseResult.error(ErrorCodeEnum.INVALID_UPLOAD_FIELD));
+                return;
+            }
+            BaseUpDownloader upDownloader = upDownloaderFactory.get(storeInfo.getStoreType());
+            upDownloader.doDownload(appConfig.getUploadFileBaseDir(),
+                    TourProjectGroupPurchaseBanner.class.getSimpleName(), fieldName, filename, asImage, response);
+        } catch (Exception e) {
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 文件上传操作。
+     *
+     * @param fieldName  上传文件名。
+     * @param asImage    是否作为图片上传。如果是图片,今后下载的时候无需权限验证。否则就是附件上传,下载时需要权限验证。
+     * @param uploadFile 上传文件对象。
+     */
+    @SaCheckPermission("tourProjectGroupPurchaseBanner.view")
+    @OperationLog(type = SysOperationLogType.UPLOAD, saveResponse = false)
+    @PostMapping("/upload")
+    public void upload(
+            @RequestParam String fieldName,
+            @RequestParam Boolean asImage,
+            @RequestParam("uploadFile") MultipartFile uploadFile) throws IOException {
+        UploadStoreInfo storeInfo = MyModelUtil.getUploadStoreInfo(TourProjectGroupPurchaseBanner.class, fieldName);
+        // 这里就会判断参数中指定的字段,是否支持上传操作。
+        if (!storeInfo.isSupportUpload()) {
+            ResponseResult.output(HttpServletResponse.SC_FORBIDDEN,
+                    ResponseResult.error(ErrorCodeEnum.INVALID_UPLOAD_FIELD));
+            return;
+        }
+        // 根据字段注解中的存储类型,通过工厂方法获取匹配的上传下载实现类,从而解耦。
+        BaseUpDownloader upDownloader = upDownloaderFactory.get(storeInfo.getStoreType());
+        UploadResponseInfo responseInfo = upDownloader.doUpload(null,
+                appConfig.getUploadFileBaseDir(), TourProjectGroupPurchaseBanner.class.getSimpleName(), fieldName, asImage, uploadFile);
+        if (Boolean.TRUE.equals(responseInfo.getUploadFailed())) {
+            ResponseResult.output(HttpServletResponse.SC_FORBIDDEN,
+                    ResponseResult.error(ErrorCodeEnum.UPLOAD_FAILED, responseInfo.getErrorMessage()));
+            return;
+        }
+        cacheHelper.putSessionUploadFile(responseInfo.getFilename());
+        ResponseResult.output(ResponseResult.success(responseInfo));
+    }
+
+    private ResponseResult<Void> doDelete(Long id) {
+        String errorMessage;
+        // 验证关联Id的数据合法性
+        TourProjectGroupPurchaseBanner originalTourProjectGroupPurchaseBanner = tourProjectGroupPurchaseBannerService.getById(id);
+        if (originalTourProjectGroupPurchaseBanner == null) {
+            // NOTE: 修改下面方括号中的话述
+            errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
+        }
+        if (!tourProjectGroupPurchaseBannerService.remove(id)) {
+            errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
+        }
+        return ResponseResult.success();
+    }
+}

+ 33 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/dao/TourProjectGroupPurchaseBannerMapper.java

@@ -0,0 +1,33 @@
+package com.tourism.webadmin.back.dao;
+
+import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchaseBanner;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.*;
+
+/**
+ * 拼团首页banner数据操作访问接口。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+public interface TourProjectGroupPurchaseBannerMapper extends BaseDaoMapper<TourProjectGroupPurchaseBanner> {
+
+    /**
+     * 批量插入对象列表。
+     *
+     * @param tourProjectGroupPurchaseBannerList 新增对象列表。
+     */
+    void insertList(List<TourProjectGroupPurchaseBanner> tourProjectGroupPurchaseBannerList);
+
+    /**
+     * 获取过滤后的对象列表。
+     *
+     * @param tourProjectGroupPurchaseBannerFilter 主表过滤对象。
+     * @param orderBy 排序字符串,order by从句的参数。
+     * @return 对象列表。
+     */
+    List<TourProjectGroupPurchaseBanner> getTourProjectGroupPurchaseBannerList(
+            @Param("tourProjectGroupPurchaseBannerFilter") TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBannerFilter, @Param("orderBy") String orderBy);
+}

+ 82 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/dao/mapper/TourProjectGroupPurchaseBannerMapper.xml

@@ -0,0 +1,82 @@
+<?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.tourism.webadmin.back.dao.TourProjectGroupPurchaseBannerMapper">
+    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourProjectGroupPurchaseBanner">
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="banner_name" jdbcType="VARCHAR" property="bannerName"/>
+        <result column="enable" jdbcType="TINYINT" property="enable"/>
+        <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/>
+        <result column="banner_url" jdbcType="VARCHAR" property="bannerUrl"/>
+        <result column="show_order" jdbcType="TINYINT" property="showOrder"/>
+        <result column="type" jdbcType="TINYINT" property="type"/>
+        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
+        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+    </resultMap>
+
+    <insert id="insertList">
+        INSERT INTO tour_project_group_purchase_banner
+            (id,
+            banner_name,
+            enable,
+            img_url,
+            banner_url,
+            show_order,
+            type,
+            data_state,
+            create_user_id,
+            create_time,
+            update_user_id,
+            update_time)
+        VALUES
+        <foreach collection="list" index="index" item="item" separator="," >
+            (#{item.id},
+            #{item.bannerName},
+            #{item.enable},
+            #{item.imgUrl},
+            #{item.bannerUrl},
+            #{item.showOrder},
+            #{item.type},
+            #{item.dataState},
+            #{item.createUserId},
+            #{item.createTime},
+            #{item.updateUserId},
+            #{item.updateTime})
+        </foreach>
+    </insert>
+
+    <!-- 如果有逻辑删除字段过滤,请写到这里 -->
+    <sql id="filterRef">
+        <!-- 这里必须加上全包名,否则当filterRef被其他Mapper.xml包含引用的时候,就会调用Mapper.xml中的该SQL片段 -->
+        <include refid="com.tourism.webadmin.back.dao.TourProjectGroupPurchaseBannerMapper.inputFilterRef"/>
+        AND tour_project_group_purchase_banner.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
+    </sql>
+
+    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
+    <sql id="inputFilterRef">
+        <if test="tourProjectGroupPurchaseBannerFilter != null">
+            <if test="tourProjectGroupPurchaseBannerFilter.bannerName != null and tourProjectGroupPurchaseBannerFilter.bannerName != ''">
+                <bind name = "safeTourProjectGroupPurchaseBannerBannerName" value = "'%' + tourProjectGroupPurchaseBannerFilter.bannerName + '%'" />
+                AND tour_project_group_purchase_banner.banner_name LIKE #{safeTourProjectGroupPurchaseBannerBannerName}
+            </if>
+            <if test="tourProjectGroupPurchaseBannerFilter.enable != null">
+                AND tour_project_group_purchase_banner.enable = #{tourProjectGroupPurchaseBannerFilter.enable}
+            </if>
+            <if test="tourProjectGroupPurchaseBannerFilter.type != null">
+                AND tour_project_group_purchase_banner.type = #{tourProjectGroupPurchaseBannerFilter.type}
+            </if>
+        </if>
+    </sql>
+
+    <select id="getTourProjectGroupPurchaseBannerList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourProjectGroupPurchaseBanner">
+        SELECT * FROM tour_project_group_purchase_banner
+        <where>
+            <include refid="filterRef"/>
+        </where>
+        <if test="orderBy != null and orderBy != ''">
+            ORDER BY ${orderBy}
+        </if>
+    </select>
+</mapper>

+ 70 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/dto/TourProjectGroupPurchaseBannerDto.java

@@ -0,0 +1,70 @@
+package com.tourism.webadmin.back.dto;
+
+import com.tourism.common.core.validator.UpdateGroup;
+import com.tourism.common.core.validator.ConstDictRef;
+import com.tourism.webadmin.back.model.constant.Enable;
+import com.tourism.webadmin.back.model.constant.BannerType;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import jakarta.validation.constraints.*;
+
+/**
+ * 拼团首页bannerDto对象。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Schema(description = "拼团首页bannerDto对象")
+@Data
+public class TourProjectGroupPurchaseBannerDto {
+
+    /**
+     * 主键。
+     */
+    @Schema(description = "主键。", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "数据验证失败,主键不能为空!", groups = {UpdateGroup.class})
+    private Long id;
+
+    /**
+     * banner名称。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "banner名称。可支持等于操作符的列表数据过滤。")
+    private String bannerName;
+
+    /**
+     * 是否启用,0否,1是。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "是否启用,0否,1是。可支持等于操作符的列表数据过滤。")
+    @ConstDictRef(constDictClass = Enable.class, message = "数据验证失败,是否启用,0否,1是为无效值!")
+    private Integer enable;
+
+    /**
+     * 图片URL。
+     */
+    @Schema(description = "图片URL。")
+    private String imgUrl;
+
+    /**
+     * 跳转链接。
+     */
+    @Schema(description = "跳转链接。")
+    private String bannerUrl;
+
+    /**
+     * banner排序。
+     */
+    @Schema(description = "banner排序。")
+    private Integer showOrder;
+
+    /**
+     * 类型(0.PC;1.H5)。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "类型(0.PC;1.H5)。可支持等于操作符的列表数据过滤。")
+    @ConstDictRef(constDictClass = BannerType.class, message = "数据验证失败,类型(0.PC;1.H5)为无效值!")
+    private Integer type;
+}

+ 86 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourProjectGroupPurchaseBanner.java

@@ -0,0 +1,86 @@
+package com.tourism.webadmin.back.model;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.tourism.webadmin.back.model.constant.Enable;
+import com.tourism.webadmin.back.model.constant.BannerType;
+import com.tourism.common.core.upload.UploadStoreTypeEnum;
+import com.tourism.common.core.annotation.*;
+import com.tourism.common.core.base.model.BaseModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Map;
+
+/**
+ * 拼团首页banner实体对象。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName(value = "tour_project_group_purchase_banner")
+public class TourProjectGroupPurchaseBanner extends BaseModel {
+
+    /**
+     * 主键。
+     */
+    @TableId(value = "id")
+    private Long id;
+
+    /**
+     * banner名称。
+     */
+    @TableField(value = "banner_name")
+    private String bannerName;
+
+    /**
+     * 是否启用,0否,1是。
+     */
+    @TableField(value = "enable")
+    private Integer enable;
+
+    /**
+     * 图片URL。
+     */
+    @UploadFlagColumn(storeType = UploadStoreTypeEnum.HUAWEI_OBS_SYSTEM)
+    @TableField(value = "img_url")
+    private String imgUrl;
+
+    /**
+     * 跳转链接。
+     */
+    @TableField(value = "banner_url")
+    private String bannerUrl;
+
+    /**
+     * banner排序。
+     */
+    @TableField(value = "show_order")
+    private Integer showOrder;
+
+    /**
+     * 类型(0.PC;1.H5)。
+     */
+    @TableField(value = "type")
+    private Integer type;
+
+    /**
+     * 逻辑删除标记字段(1: 正常 -1: 已删除)。
+     */
+    @TableLogic
+    @TableField(value = "data_state")
+    private Integer dataState;
+
+    @RelationConstDict(
+            masterIdField = "enable",
+            constantDictClass = Enable.class)
+    @TableField(exist = false)
+    private Map<String, Object> enableDictMap;
+
+    @RelationConstDict(
+            masterIdField = "type",
+            constantDictClass = BannerType.class)
+    @TableField(exist = false)
+    private Map<String, Object> typeDictMap;
+}

+ 68 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseBannerService.java

@@ -0,0 +1,68 @@
+package com.tourism.webadmin.back.service;
+
+import com.tourism.webadmin.back.model.*;
+import com.tourism.common.core.base.service.IBaseService;
+
+import java.util.*;
+
+/**
+ * 拼团首页banner数据操作服务接口。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+public interface TourProjectGroupPurchaseBannerService extends IBaseService<TourProjectGroupPurchaseBanner, Long> {
+
+    /**
+     * 保存新增对象。
+     *
+     * @param tourProjectGroupPurchaseBanner 新增对象。
+     * @return 返回新增对象。
+     */
+    TourProjectGroupPurchaseBanner saveNew(TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner);
+
+    /**
+     * 利用数据库的insertList语法,批量插入对象列表。
+     *
+     * @param tourProjectGroupPurchaseBannerList 新增对象列表。
+     */
+    void saveNewBatch(List<TourProjectGroupPurchaseBanner> tourProjectGroupPurchaseBannerList);
+
+    /**
+     * 更新数据对象。
+     *
+     * @param tourProjectGroupPurchaseBanner         更新的对象。
+     * @param originalTourProjectGroupPurchaseBanner 原有数据对象。
+     * @return 成功返回true,否则false。
+     */
+    boolean update(TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner, TourProjectGroupPurchaseBanner originalTourProjectGroupPurchaseBanner);
+
+    /**
+     * 删除指定数据。
+     *
+     * @param id 主键Id。
+     * @return 成功返回true,否则false。
+     */
+    boolean remove(Long id);
+
+    /**
+     * 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
+     * 如果需要同时获取关联数据,请移步(getTourProjectGroupPurchaseBannerListWithRelation)方法。
+     *
+     * @param filter  过滤对象。
+     * @param orderBy 排序参数。
+     * @return 查询结果集。
+     */
+    List<TourProjectGroupPurchaseBanner> getTourProjectGroupPurchaseBannerList(TourProjectGroupPurchaseBanner filter, String orderBy);
+
+    /**
+     * 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
+     * 该查询会涉及到一对一从表的关联过滤,或一对多从表的嵌套关联过滤,因此性能不如单表过滤。
+     * 如果仅仅需要获取主表数据,请移步(getTourProjectGroupPurchaseBannerList),以便获取更好的查询性能。
+     *
+     * @param filter 主表过滤对象。
+     * @param orderBy 排序参数。
+     * @return 查询结果集。
+     */
+    List<TourProjectGroupPurchaseBanner> getTourProjectGroupPurchaseBannerListWithRelation(TourProjectGroupPurchaseBanner filter, String orderBy);
+}

+ 103 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseBannerServiceImpl.java

@@ -0,0 +1,103 @@
+package com.tourism.webadmin.back.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.tourism.webadmin.back.service.*;
+import com.tourism.webadmin.back.dao.*;
+import com.tourism.webadmin.back.model.*;
+import com.tourism.webadmin.config.DataSourceType;
+import com.tourism.common.core.annotation.MyDataSource;
+import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.common.core.constant.GlobalDeletedFlag;
+import com.tourism.common.core.object.MyRelationParam;
+import com.tourism.common.core.base.service.BaseService;
+import com.tourism.common.core.util.MyModelUtil;
+import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
+import com.github.pagehelper.Page;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * 拼团首页banner数据操作服务类。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Slf4j
+@Service("tourProjectGroupPurchaseBannerService")
+public class TourProjectGroupPurchaseBannerServiceImpl extends BaseService<TourProjectGroupPurchaseBanner, Long> implements TourProjectGroupPurchaseBannerService {
+
+    @Autowired
+    private IdGeneratorWrapper idGenerator;
+    @Autowired
+    private TourProjectGroupPurchaseBannerMapper tourProjectGroupPurchaseBannerMapper;
+
+    /**
+     * 返回当前Service的主表Mapper对象。
+     *
+     * @return 主表Mapper对象。
+     */
+    @Override
+    protected BaseDaoMapper<TourProjectGroupPurchaseBanner> mapper() {
+        return tourProjectGroupPurchaseBannerMapper;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public TourProjectGroupPurchaseBanner saveNew(TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner) {
+        tourProjectGroupPurchaseBannerMapper.insert(this.buildDefaultValue(tourProjectGroupPurchaseBanner));
+        return tourProjectGroupPurchaseBanner;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void saveNewBatch(List<TourProjectGroupPurchaseBanner> tourProjectGroupPurchaseBannerList) {
+        if (CollUtil.isNotEmpty(tourProjectGroupPurchaseBannerList)) {
+            tourProjectGroupPurchaseBannerList.forEach(this::buildDefaultValue);
+            tourProjectGroupPurchaseBannerMapper.insertList(tourProjectGroupPurchaseBannerList);
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public boolean update(TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner, TourProjectGroupPurchaseBanner originalTourProjectGroupPurchaseBanner) {
+        MyModelUtil.fillCommonsForUpdate(tourProjectGroupPurchaseBanner, originalTourProjectGroupPurchaseBanner);
+        // 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
+        UpdateWrapper<TourProjectGroupPurchaseBanner> uw = this.createUpdateQueryForNullValue(tourProjectGroupPurchaseBanner, tourProjectGroupPurchaseBanner.getId());
+        return tourProjectGroupPurchaseBannerMapper.update(tourProjectGroupPurchaseBanner, uw) == 1;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public boolean remove(Long id) {
+        return tourProjectGroupPurchaseBannerMapper.deleteById(id) == 1;
+    }
+
+    @Override
+    public List<TourProjectGroupPurchaseBanner> getTourProjectGroupPurchaseBannerList(TourProjectGroupPurchaseBanner filter, String orderBy) {
+        return tourProjectGroupPurchaseBannerMapper.getTourProjectGroupPurchaseBannerList(filter, orderBy);
+    }
+
+    @Override
+    public List<TourProjectGroupPurchaseBanner> getTourProjectGroupPurchaseBannerListWithRelation(TourProjectGroupPurchaseBanner filter, String orderBy) {
+        List<TourProjectGroupPurchaseBanner> resultList = tourProjectGroupPurchaseBannerMapper.getTourProjectGroupPurchaseBannerList(filter, orderBy);
+        // 在缺省生成的代码中,如果查询结果resultList不是Page对象,说明没有分页,那么就很可能是数据导出接口调用了当前方法。
+        // 为了避免一次性的大量数据关联,规避因此而造成的系统运行性能冲击,这里手动进行了分批次读取,开发者可按需修改该值。
+        int batchSize = resultList instanceof Page ? 0 : 1000;
+        this.buildRelationForDataList(resultList, MyRelationParam.normal(), batchSize);
+        return resultList;
+    }
+
+    private TourProjectGroupPurchaseBanner buildDefaultValue(TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner) {
+        if (tourProjectGroupPurchaseBanner.getId() == null) {
+            tourProjectGroupPurchaseBanner.setId(idGenerator.nextLongId());
+        }
+        MyModelUtil.fillCommonsForInsert(tourProjectGroupPurchaseBanner);
+        tourProjectGroupPurchaseBanner.setDataState(GlobalDeletedFlag.NORMAL);
+        return tourProjectGroupPurchaseBanner;
+    }
+}

+ 73 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourProjectGroupPurchaseBannerVo.java

@@ -0,0 +1,73 @@
+package com.tourism.webadmin.back.vo;
+
+import com.tourism.common.core.base.vo.BaseVo;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import java.util.Map;
+
+/**
+ * 拼团首页bannerVO视图对象。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Schema(description = "拼团首页bannerVO视图对象")
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class TourProjectGroupPurchaseBannerVo extends BaseVo {
+
+    /**
+     * 主键。
+     */
+    @Schema(description = "主键")
+    private Long id;
+
+    /**
+     * banner名称。
+     */
+    @Schema(description = "banner名称")
+    private String bannerName;
+
+    /**
+     * 是否启用,0否,1是。
+     */
+    @Schema(description = "是否启用,0否,1是")
+    private Integer enable;
+
+    /**
+     * 图片URL。
+     */
+    @Schema(description = "图片URL")
+    private String imgUrl;
+
+    /**
+     * 跳转链接。
+     */
+    @Schema(description = "跳转链接")
+    private String bannerUrl;
+
+    /**
+     * banner排序。
+     */
+    @Schema(description = "banner排序")
+    private Integer showOrder;
+
+    /**
+     * 类型(0.PC;1.H5)。
+     */
+    @Schema(description = "类型(0.PC;1.H5)")
+    private Integer type;
+
+    /**
+     * enable 常量字典关联数据。
+     */
+    @Schema(description = "enable 常量字典关联数据")
+    private Map<String, Object> enableDictMap;
+
+    /**
+     * type 常量字典关联数据。
+     */
+    @Schema(description = "type 常量字典关联数据")
+    private Map<String, Object> typeDictMap;
+}