Преглед изворни кода

初步完成农资商城模块

jiuling пре 9 месеци
родитељ
комит
8b5928859d

+ 52 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/JsonListTypeHandler.java

@@ -0,0 +1,52 @@
+package com.ruoyi.common.core.utils;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+
+import java.sql.*;
+import java.util.List;
+
+public class JsonListTypeHandler extends BaseTypeHandler<List<String>> {
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
+        try {
+            ps.setString(i, objectMapper.writeValueAsString(parameter));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        String json = rs.getString(columnName);
+        return parseJson(json);
+    }
+
+    @Override
+    public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+        String json = rs.getString(columnIndex);
+        return parseJson(json);
+    }
+
+    @Override
+    public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+        String json = cs.getString(columnIndex);
+        return parseJson(json);
+    }
+
+    private List<String> parseJson(String json) {
+        if (json == null || json.trim().isEmpty()) {
+            return null;
+        }
+        try {
+            return objectMapper.readValue(json, new TypeReference<List<String>>() {});
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

+ 105 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/controller/MallController.java

@@ -0,0 +1,105 @@
+package com.ruoyi.base.controller;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.base.domain.Mall;
+import com.ruoyi.base.service.IMallService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.log.annotation.Log;
+import com.ruoyi.common.log.enums.BusinessType;
+import com.ruoyi.common.security.annotation.RequiresPermissions;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.common.core.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.web.page.TableDataInfo;
+
+/**
+ * 农资商城Controller
+ * 
+ * @author ruoyi
+ * @date 2025-08-15
+ */
+@RestController
+@RequestMapping("/mall")
+public class MallController extends BaseController
+{
+    @Autowired
+    private IMallService mallService;
+
+    /**
+     * 查询农资商城列表
+     */
+//    @RequiresPermissions("system:mall:list")
+    @GetMapping("/list")
+    public TableDataInfo list(Mall mall)
+    {
+        startPage();
+        List<Mall> list = mallService.selectMallList(mall);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出农资商城列表
+     */
+    @RequiresPermissions("system:mall:export")
+    @Log(title = "农资商城", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, Mall mall)
+    {
+        List<Mall> list = mallService.selectMallList(mall);
+        ExcelUtil<Mall> util = new ExcelUtil<Mall>(Mall.class);
+        util.exportExcel(response, list, "农资商城数据");
+    }
+
+    /**
+     * 获取农资商城详细信息
+     */
+//    @RequiresPermissions("system:mall:query")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") String id)
+    {
+        return success(mallService.selectMallById(id));
+    }
+
+    /**
+     * 新增农资商城
+     */
+    @RequiresPermissions("system:mall:add")
+    @Log(title = "农资商城", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody Mall mall)
+    {
+        return toAjax(mallService.insertMall(mall));
+    }
+
+    /**
+     * 修改农资商城
+     */
+    @RequiresPermissions("system:mall:edit")
+    @Log(title = "农资商城", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody Mall mall)
+    {
+        return toAjax(mallService.updateMall(mall));
+    }
+
+    /**
+     * 删除农资商城
+     */
+    @RequiresPermissions("system:mall:remove")
+    @Log(title = "农资商城", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable String[] ids)
+    {
+        return toAjax(mallService.deleteMallByIds(ids));
+    }
+}

+ 74 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/Mall.java

@@ -0,0 +1,74 @@
+package com.ruoyi.base.domain;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.core.annotation.Excel;
+import com.ruoyi.common.core.web.domain.BaseEntity;
+
+/**
+ * 农资商城对象 mall
+ * 
+ * @author ruoyi
+ * @date 2025-08-15
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Mall extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 商品ID */
+    private String id;
+
+    /** 商品分类;0:推荐,1:种子,2:肥料,3:农药,4:农膜,5:农技配件 */
+    @Excel(name = "商品分类;0:推荐,1:种子,2:肥料,3:农药,4:农膜,5:农技配件")
+    private Long productCategory;
+
+    /** 商品标题 */
+    @Excel(name = "商品标题")
+    private String title;
+
+    /** 商品描述 */
+    @Excel(name = "商品描述")
+    private String description;
+
+    /** 当前价格 */
+    @Excel(name = "当前价格")
+    private String price;
+
+    /** 原价 */
+    @Excel(name = "原价")
+    private BigDecimal originalPrice;
+
+    /** 商品规格 */
+    @Excel(name = "商品规格")
+    private String specifications;
+
+    /** 产品特点(JSON数组) */
+    @Excel(name = "产品特点(JSON数组)")
+    private List<String> features;
+
+    /** 使用说明 */
+    @Excel(name = "使用说明")
+    private String usageGuide;
+
+    /** 轮播图URL数组 */
+    @Excel(name = "轮播图URL数组")
+    private String swiperImages;
+
+    /** 详情图URL数组 */
+    @Excel(name = "详情图URL数组")
+    private String detailImages;
+
+    /** 状态 (1上架, 0下架) */
+    @Excel(name = "状态 (1上架, 0下架)")
+    private Integer status;
+
+}

+ 62 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/MallMapper.java

@@ -0,0 +1,62 @@
+package com.ruoyi.base.mapper;
+
+import com.ruoyi.base.domain.Mall;
+
+import java.util.List;
+
+/**
+ * 农资商城Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2025-08-15
+ */
+public interface MallMapper 
+{
+    /**
+     * 查询农资商城
+     * 
+     * @param id 农资商城主键
+     * @return 农资商城
+     */
+    public Mall selectMallById(String id);
+
+    /**
+     * 查询农资商城列表
+     * 
+     * @param mall 农资商城
+     * @return 农资商城集合
+     */
+    public List<Mall> selectMallList(Mall mall);
+
+    /**
+     * 新增农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    public int insertMall(Mall mall);
+
+    /**
+     * 修改农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    public int updateMall(Mall mall);
+
+    /**
+     * 删除农资商城
+     * 
+     * @param id 农资商城主键
+     * @return 结果
+     */
+    public int deleteMallById(String id);
+
+    /**
+     * 批量删除农资商城
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteMallByIds(String[] ids);
+}

+ 62 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/IMallService.java

@@ -0,0 +1,62 @@
+package com.ruoyi.base.service;
+
+import com.ruoyi.base.domain.Mall;
+
+import java.util.List;
+
+/**
+ * 农资商城Service接口
+ * 
+ * @author ruoyi
+ * @date 2025-08-15
+ */
+public interface IMallService 
+{
+    /**
+     * 查询农资商城
+     * 
+     * @param id 农资商城主键
+     * @return 农资商城
+     */
+    public Mall selectMallById(String id);
+
+    /**
+     * 查询农资商城列表
+     * 
+     * @param mall 农资商城
+     * @return 农资商城集合
+     */
+    public List<Mall> selectMallList(Mall mall);
+
+    /**
+     * 新增农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    public int insertMall(Mall mall);
+
+    /**
+     * 修改农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    public int updateMall(Mall mall);
+
+    /**
+     * 批量删除农资商城
+     * 
+     * @param ids 需要删除的农资商城主键集合
+     * @return 结果
+     */
+    public int deleteMallByIds(String[] ids);
+
+    /**
+     * 删除农资商城信息
+     * 
+     * @param id 农资商城主键
+     * @return 结果
+     */
+    public int deleteMallById(String id);
+}

+ 97 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/impl/MallServiceImpl.java

@@ -0,0 +1,97 @@
+package com.ruoyi.base.service.impl;
+
+import java.util.List;
+
+import com.ruoyi.base.domain.Mall;
+import com.ruoyi.base.mapper.MallMapper;
+import com.ruoyi.base.service.IMallService;
+import com.ruoyi.common.core.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 农资商城Service业务层处理
+ * 
+ * @author ruoyi
+ * @date 2025-08-15
+ */
+@Service
+public class MallServiceImpl implements IMallService
+{
+    @Autowired
+    private MallMapper mallMapper;
+
+    /**
+     * 查询农资商城
+     * 
+     * @param id 农资商城主键
+     * @return 农资商城
+     */
+    @Override
+    public Mall selectMallById(String id)
+    {
+        return mallMapper.selectMallById(id);
+    }
+
+    /**
+     * 查询农资商城列表
+     * 
+     * @param mall 农资商城
+     * @return 农资商城
+     */
+    @Override
+    public List<Mall> selectMallList(Mall mall)
+    {
+        return mallMapper.selectMallList(mall);
+    }
+
+    /**
+     * 新增农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    @Override
+    public int insertMall(Mall mall)
+    {
+        mall.setCreateTime(DateUtils.getNowDate());
+        return mallMapper.insertMall(mall);
+    }
+
+    /**
+     * 修改农资商城
+     * 
+     * @param mall 农资商城
+     * @return 结果
+     */
+    @Override
+    public int updateMall(Mall mall)
+    {
+        mall.setUpdateTime(DateUtils.getNowDate());
+        return mallMapper.updateMall(mall);
+    }
+
+    /**
+     * 批量删除农资商城
+     * 
+     * @param ids 需要删除的农资商城主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMallByIds(String[] ids)
+    {
+        return mallMapper.deleteMallByIds(ids);
+    }
+
+    /**
+     * 删除农资商城信息
+     * 
+     * @param id 农资商城主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMallById(String id)
+    {
+        return mallMapper.deleteMallById(id);
+    }
+}

+ 1 - 0
ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/AgriculturalTasksMapper.xml

@@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="completionDesc != null  and completionDesc != ''"> and completion_desc = #{completionDesc}</if>
             <if test="createBy != null "> and create_by = #{createBy}</if>
         </where>
+        ORDER BY create_time DESC
     </select>
     
     <select id="selectAgriculturalTasksById" parameterType="Long" resultMap="AgriculturalTasksResult">

+ 123 - 0
ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/MallMapper.xml

@@ -0,0 +1,123 @@
+<?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.ruoyi.base.mapper.MallMapper">
+    
+    <resultMap type="Mall" id="MallResult">
+        <result property="id"    column="id"    />
+        <result property="productCategory"    column="product_category"    />
+        <result property="title"    column="title"    />
+        <result property="description"    column="description"    />
+        <result property="price"    column="price"    />
+        <result property="originalPrice"    column="original_price"    />
+        <result property="specifications"    column="specifications"    />
+        <result column="features" property="features"
+                typeHandler="com.ruoyi.common.core.utils.JsonListTypeHandler"/>
+        <result property="usageGuide"    column="usage_guide"    />
+        <result property="swiperImages"    column="swiper_images"    />
+        <result property="detailImages"    column="detail_images"    />
+        <result property="status"    column="status"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
+    <sql id="selectMallVo">
+        select id, product_category, title, description, price, original_price, specifications, features, usage_guide, swiper_images, detail_images, status, create_by, create_time, update_by, update_time from mall
+    </sql>
+
+    <select id="selectMallList" parameterType="Mall" resultMap="MallResult">
+        <include refid="selectMallVo"/>
+        <where>  
+            <if test="productCategory != null "> and product_category = #{productCategory}</if>
+            <if test="title != null  and title != ''"> and title = #{title}</if>
+            <if test="description != null  and description != ''"> and description = #{description}</if>
+            <if test="price != null "> and price = #{price}</if>
+            <if test="originalPrice != null "> and original_price = #{originalPrice}</if>
+            <if test="specifications != null  and specifications != ''"> and specifications = #{specifications}</if>
+            <if test="features != null  and features != ''"> and features = #{features}</if>
+            <if test="usageGuide != null  and usageGuide != ''"> and usage_guide = #{usageGuide}</if>
+            <if test="swiperImages != null  and swiperImages != ''"> and swiper_images = #{swiperImages}</if>
+            <if test="detailImages != null  and detailImages != ''"> and detail_images = #{detailImages}</if>
+            <if test="status != null "> and status = #{status}</if>
+        </where>
+    </select>
+    
+    <select id="selectMallById" parameterType="String" resultMap="MallResult">
+        <include refid="selectMallVo"/>
+        where id = #{id}
+    </select>
+
+    <insert id="insertMall" parameterType="Mall" useGeneratedKeys="true" keyProperty="id">
+        insert into mall
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="productCategory != null">product_category,</if>
+            <if test="title != null and title != ''">title,</if>
+            <if test="description != null and description != ''">description,</if>
+            <if test="price != null">price,</if>
+            <if test="originalPrice != null">original_price,</if>
+            <if test="specifications != null and specifications != ''">specifications,</if>
+            <if test="features != null and features != ''">features,</if>
+            <if test="usageGuide != null and usageGuide != ''">usage_guide,</if>
+            <if test="swiperImages != null and swiperImages != ''">swiper_images,</if>
+            <if test="detailImages != null">detail_images,</if>
+            <if test="status != null">status,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="productCategory != null">#{productCategory},</if>
+            <if test="title != null and title != ''">#{title},</if>
+            <if test="description != null and description != ''">#{description},</if>
+            <if test="price != null">#{price},</if>
+            <if test="originalPrice != null">#{originalPrice},</if>
+            <if test="specifications != null and specifications != ''">#{specifications},</if>
+            <if test="features != null and features != ''">#{features},</if>
+            <if test="usageGuide != null and usageGuide != ''">#{usageGuide},</if>
+            <if test="swiperImages != null and swiperImages != ''">#{swiperImages},</if>
+            <if test="detailImages != null">#{detailImages},</if>
+            <if test="status != null">#{status},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateMall" parameterType="Mall">
+        update mall
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="productCategory != null">product_category = #{productCategory},</if>
+            <if test="title != null and title != ''">title = #{title},</if>
+            <if test="description != null and description != ''">description = #{description},</if>
+            <if test="price != null">price = #{price},</if>
+            <if test="originalPrice != null">original_price = #{originalPrice},</if>
+            <if test="specifications != null and specifications != ''">specifications = #{specifications},</if>
+            <if test="features != null and features != ''">features = #{features},</if>
+            <if test="usageGuide != null and usageGuide != ''">usage_guide = #{usageGuide},</if>
+            <if test="swiperImages != null and swiperImages != ''">swiper_images = #{swiperImages},</if>
+            <if test="detailImages != null">detail_images = #{detailImages},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteMallById" parameterType="String">
+        delete from mall where id = #{id}
+    </delete>
+
+    <delete id="deleteMallByIds" parameterType="String">
+        delete from mall where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>