Browse Source

增加权限 判断标题 头像是否重复

zhangyang 2 years ago
parent
commit
9f2009e663

+ 38 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PoTetherController.java

@@ -4,9 +4,13 @@ import java.util.Date;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.system.domain.PoCollection;
+import com.ruoyi.system.domain.PoUser;
 import com.ruoyi.system.domain.vo.TetherVo;
+import com.ruoyi.system.service.IPoUserService;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.data.repository.query.Param;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -32,6 +36,9 @@ public class PoTetherController extends BaseController
     @Autowired
     private IPoTetherService poTetherService;
 
+    @Autowired
+    private IPoUserService poUserService;
+
     /**
      * 标题和时间搜索消息列表
      */
@@ -114,8 +121,19 @@ public class PoTetherController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:tether:add')")
     @Log(title = "套系", businessType = BusinessType.INSERT)
     @PostMapping("/add")
-    public AjaxResult add(@RequestBody TetherVo tetherVo)
+    public AjaxResult add(@RequestBody TetherVo tetherVo, @RequestBody @Param("poUser") PoUser poUser)
     {
+        //判断当前用户是否有操作的权限
+        poUserService.checkUserAllowed(poUser);
+
+        if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
+            return AjaxResult.error("新增失败"+tetherVo.getTetherName()+"已经存在");
+        }
+        if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
+            return AjaxResult.error("新增失败"+tetherVo.getImage()+"已经存在");
+        }
+        tetherVo.setCreateBy(getUsername());
+        tetherVo.setCreateTime(new Date());
         return toAjax(poTetherService.insertPoTetherWithCollection(tetherVo));
     }
 
@@ -136,11 +154,26 @@ public class PoTetherController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:tether:edit')")
     @Log(title = "套系", businessType = BusinessType.UPDATE)
     @PutMapping("edit")
-    public AjaxResult edit(@RequestBody TetherVo tetherVo)
+    public AjaxResult edit(@RequestBody TetherVo tetherVo,@RequestBody PoUser poUser)
     {
+        //校验是否有操作的权限
+        poUserService.checkUserAllowed(poUser);
+        //校验是否可以访问到数据
+        poUserService.checkUserDataScope(poUser.getUserId());
+
+        if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
+            return AjaxResult.error("修改失败"+tetherVo.getTetherName()+"已经存在");
+        }
+        if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
+            return AjaxResult.error("修改失败"+tetherVo.getImage()+"已经存在");
+        }
+
         //清理所有套系的缓存数
         //因为对于修改操作,用户是可以修改菜品的分类的,如果用户修改了菜品的分类,
         // 那么原来分类下将少一个菜品,新的分类下将多一个菜品,这样的话,两个分类下的菜品列表数据都发生了变化。
+
+        tetherVo.setUpdateBy(getUsername());
+        tetherVo.setUpdateTime(new Date());
         return toAjax(poTetherService.updatePoTetherWithCollection(tetherVo));
     }
 
@@ -152,6 +185,9 @@ public class PoTetherController extends BaseController
     @DeleteMapping("/remove/{tetherIds}")
     public AjaxResult remove(@PathVariable Long[] tetherIds)
     {
+        if (!getUsername().equals("admin")){
+            return AjaxResult.error("删除消息失败当前用户不是管理员");
+        }
         return toAjax(poTetherService.deletePoTetherByTetherIdsWithCollection(tetherIds));
     }
 }

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/PoTether.java

@@ -28,6 +28,11 @@ public class PoTether extends BaseEntity
      */
     private Integer sellStatus;
 
+    /**
+     * 套系图片
+     */
+    private String image;
+
     /** 展示时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "展示时间", width = 30, dateFormat = "yyyy-MM-dd")
@@ -61,6 +66,14 @@ public class PoTether extends BaseEntity
         return tetherId;
     }
 
+    public void setImage(String image) {
+        this.image = image;
+    }
+
+    public String getImage() {
+        return image;
+    }
+
     public void setSellStatus(Integer sellStatus) {
         this.sellStatus = sellStatus;
     }
@@ -121,6 +134,7 @@ public class PoTether extends BaseEntity
                 .append("remark", getRemark())
                 .append("sellStatus",getSellStatus())
                 .append("delFlag",getDelFlag())
+                .append("image",getImage())
                 .toString();
     }
 }

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PoTetherMapper.java

@@ -102,4 +102,18 @@ public interface PoTetherMapper
      * @return
      */
     List<PoCollection> selectPoCollectionListById(Long tetherId);
+
+    /**
+     * 检验标题是否重复
+     * @param tetherId
+     * @return
+     */
+    PoTether checkPostTetherTitleUnique(Long tetherId);
+
+    /**
+     * 检验图片是否重复
+     * @param image
+     * @return
+     */
+    PoTether checkPostTetherImageUnique(String image);
 }

+ 15 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPoTetherService.java

@@ -90,5 +90,20 @@ public interface IPoTetherService
      * @return
      */
     boolean deletePoTetherByTetherIdsWithCollection(Long[] tetherIds);
+
+    /**
+     * 校验套系名称是否存在
+     * @param tetherVo
+     * @return
+     */
+    String checkPostTetherNameUnique(TetherVo tetherVo);
+
+    /**
+     * 检验图片是否重复
+     * @param tetherVo
+     * @return
+     */
+    String checkPostTetherImageUnique(TetherVo tetherVo);
+
 }
 

+ 35 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PoTetherServiceImpl.java

@@ -5,9 +5,12 @@ import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.domain.PoCollection;
+import com.ruoyi.system.domain.PoNews;
 import com.ruoyi.system.domain.vo.TetherVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -193,5 +196,37 @@ public class PoTetherServiceImpl implements IPoTetherService
         //删除po_collection表中的数据
         return true;
     }
+    /**
+     * 校验套系名称是否存在
+     * @param tetherVo
+     * @return
+     */
+    @Override
+    public String checkPostTetherNameUnique(TetherVo tetherVo) {
+        Long tetherId = StringUtils.isNull(tetherVo.getTetherId()) ? -1L : tetherVo.getTetherId();
+        PoTether info = poTetherMapper.checkPostTetherTitleUnique(tetherVo.getTetherId());
+        if (StringUtils.isNotNull(info) && info.getTetherId() != tetherId) {
+            return UserConstants.NOT_UNIQUE;
+        }
+            return UserConstants.UNIQUE;
+    }
+
+    /**
+     * 检验图片是否重复
+     * @param tetherVo
+     * @return
+     */
+    @Override
+    public String checkPostTetherImageUnique(TetherVo tetherVo) {
+
+        Long tetherId = StringUtils.isNull(tetherVo.getTetherId()) ? -1L : tetherVo.getTetherId();
+
+        PoTether info = poTetherMapper.checkPostTetherImageUnique(tetherVo.getImage());
+        if (StringUtils.isNotNull(info) && info.getTetherId() != tetherId) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+
+    }
 }
 

+ 20 - 2
ruoyi-system/src/main/resources/mapper/system/PoTetherMapper.xml

@@ -17,6 +17,7 @@
         <result property="remark"    column="remark"    />
         <result property="sellStatus" column="sell_status"/>
         <result property="delFlag" column="del_flag"/>
+        <result property="image"    column="image"    />
     </resultMap>
 
     <resultMap type="PoCollection" id="PoCollectionResult">
@@ -41,7 +42,7 @@
     </resultMap>
 
     <sql id="selectPoTetherVo">
-        select tether_id, tether_name, show_time, create_by, create_time, update_by, update_time, total, status, remark ,sell_status,del_flag from po_tether
+        select tether_id, tether_name, show_time, create_by, create_time, update_by, update_time, total, status, remark ,sell_status,del_flag,image from po_tether
     </sql>
 
 <!--在售-->
@@ -52,6 +53,7 @@
             <if test="showTime != null "> and show_time = #{showTime}</if>
             <if test="total != null "> and total = #{total}</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="image != null and image != '' ">and image = #{image}</if>
             and del_flag = '0'
             and sell_status = 0
         </where>
@@ -81,6 +83,7 @@
             <if test="showTime != null "> and show_time = #{showTime}</if>
             <if test="total != null "> and total = #{total}</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="image != null and image != '' ">and image = #{image}</if>
             and del_flag = '0'
             and sell_status = 1
         </where>
@@ -94,6 +97,7 @@
             <if test="showTime != null "> and show_time = #{showTime}</if>
             <if test="total != null "> and total = #{total}</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="image != null and image != '' ">and image = #{image}</if>
             and del_flag = '0'
             and sell_status = 2
         </where>
@@ -107,6 +111,7 @@
             <if test="showTime != null "> and show_time = #{showTime}</if>
             <if test="total != null "> and total = #{total}</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="image != null and image != '' ">and image = #{image}</if>
             and del_flag = '0'
         </where>
 
@@ -120,7 +125,17 @@
 
     </select>
 
-<!--新增-->
+<!--    检验标题是否重复-->
+    <select id="checkPostTetherTitleUnique" resultType="PoTether" resultMap="PoTetherResult">
+        select tether_id, tether_name from po_tether where tether_name = #{tetherName} and del_flag = '0' limit 1
+    </select>
+
+<!--    检验图片是否重复-->
+    <select id="checkPostTetherImageUnique" resultType="PoTether" resultMap="PoTetherResult">
+        select tether_id,image from po_tether where image = #{image} and del_flag = '0' limit 1
+    </select>
+
+    <!--新增-->
     <insert id="insertPoTether" parameterType="PoTether" useGeneratedKeys="true" keyProperty="tetherId">
         insert into po_tether
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -134,6 +149,7 @@
             <if test="status != null">status,</if>
             <if test="remark != null">remark,</if>
             <if test="sellStatus != null">sell_status,</if>
+            <if test="image != null and image != ''">image,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="tetherName != null">#{tetherName},</if>
@@ -146,6 +162,7 @@
             <if test="status != null">#{status},</if>
             <if test="remark != null">#{remark},</if>
             <if test="sellStatus != null">#{sellStatus},</if>
+            <if test="image != null and image != ''">#{image},</if>
         </trim>
     </insert>
 
@@ -162,6 +179,7 @@
             <if test="status != null">status = #{status},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="sellStatus != null">sell_status = #{sellStatus},</if>
+            <if test="image != null and image != ''">image = #{image},</if>
         </trim>
         where tether_id = #{tetherId}
     </update>