浏览代码

食堂新增字段

zwq 2 年之前
父节点
当前提交
3d537bc90f

+ 17 - 12
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/CanteenController.java

@@ -1,5 +1,6 @@
 package com.example.nngkxxdp.controller;
 
+import cn.hutool.core.lang.Validator;
 import com.example.nngkxxdp.entity.CanteenDO;
 import com.example.nngkxxdp.service.CanteenService;
 import com.example.nngkxxdp.util.Blank;
@@ -46,25 +47,29 @@ public class CanteenController {
      * description: 新增
      * @author zwq
      * @date 2022/9/2 15:51
-     * @param canteenName 食堂名称
-     * @param founder 创建人
-     * @param supplyTimeId 时间节点
+     * @param canteen 食堂
      * @param files 文件
      * @return java.util.Map<java.lang.String,java.lang.Object>
      */
     @PostMapping("/add")
-    public Map<String,Object> add(String canteenName, Integer founder, String supplyTimeId, MultipartFile[] files) throws IOException {
-        if (Blank.isEmpty(canteenName, founder)) {
+    public Map<String,Object> add(CanteenDO canteen, MultipartFile[] files) throws IOException {
+        if (Blank.isEmpty(canteen.getCanteenName(), canteen.getFounder(), canteen.getComplaintPhone(),
+                canteen.getPrincipal())) {
             return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
         }
-        if (canteenName.length() > 64) {
-            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS, "名称最长为64字符");
+        if (canteen.getCanteenName().length() > 64) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS, "食堂名称最长为64字符");
         }
-        CanteenDO canteenDO = new CanteenDO();
-        canteenDO.setCanteenName(canteenName);
-        canteenDO.setFounder(founder);
-        canteenDO.setSupplyTimeId(supplyTimeId);
-        return canteenService.add(canteenDO, files);
+        if (canteen.getPrincipal().length() > 32) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS, "负责人名称最长为32字符");
+        }
+        if (!Validator.isMobile(canteen.getComplaintPhone())) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "投诉电话格式不正确,请填入移动电话号码");
+        }
+        if (canteen.getTakeoutPhone() != null && !Validator.isMobile(canteen.getTakeoutPhone())) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "外卖电话格式不正确,请填入移动电话号码");
+        }
+        return canteenService.add(canteen, files);
     }
 
     /**

+ 15 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/CanteenDO.java

@@ -40,6 +40,21 @@ public class CanteenDO implements Serializable {
     * 创建人id
     */
     private Integer founder;
+
+    /**
+     * 负责人
+     */
+    private String principal;
+
+    /**
+     * 投诉电话
+     */
+    private String complaintPhone;
+
+    /**
+     * 外卖电话
+     */
+    private String takeoutPhone;
     
     /**
     * 创建时间

+ 23 - 6
nngkxxdp/src/main/resources/mapper/CanteenDao.xml

@@ -2,21 +2,25 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.example.nngkxxdp.dao.CanteenDao">
 
-    <resultMap type="com.example.nngkxxdp.entity.CanteenDO" id="SCanteenMap">
+    <resultMap type="com.example.nngkxxdp.entity.CanteenDO" id="CanteenMap">
         <result property="id" column="id" jdbcType="VARCHAR"/>
         <result property="canteenName" column="canteen_name" jdbcType="VARCHAR"/>
         <result property="canteenPhotoPath" column="canteen_photo_path" jdbcType="VARCHAR"/>
         <result property="supplyTimeId" column="supply_time_id" jdbcType="VARCHAR"/>
         <result property="founder" column="founder" jdbcType="INTEGER"/>
+        <result property="principal" column="principal" jdbcType="VARCHAR"/>
+        <result property="complaintPhone" column="complaint_phone" jdbcType="VARCHAR"/>
+        <result property="takeoutPhone" column="takeout_phone" jdbcType="VARCHAR"/>
         <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
         <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
         <result property="isdel" column="isdel" jdbcType="INTEGER"/>
     </resultMap>
 
     <!--查询单个-->
-    <select id="queryById" resultMap="SCanteenMap">
+    <select id="queryById" resultMap="CanteenMap">
         SELECT
-          id, canteen_name, canteen_photo_path, supply_time_id, founder, create_time, update_time, isdel
+          id, canteen_name, canteen_photo_path, supply_time_id, founder, principal, complaint_phone, takeout_phone,
+          create_time, update_time, isdel
         FROM s_canteen
         WHERE id = #{id}
     </select>
@@ -36,7 +40,9 @@
     <!--分页列表-->
     <select id="pageList" resultType="java.util.Map">
         SELECT
-          s_canteen.id, canteen_name, canteen_photo_path, supply_time_id, u.user_name founder, s_canteen.create_time, s_canteen.update_time, s_canteen.isdel
+          s_canteen.id, canteen_name, canteen_photo_path, supply_time_id, u.user_name founder, s_canteen.principal,
+          complaint_phone complaintPhone, takeout_phone takeoutPhone, s_canteen.create_time, s_canteen.update_time,
+          s_canteen.isdel
         FROM s_canteen
         LEFT JOIN p_user u
         ON u.id = s_canteen.founder
@@ -52,8 +58,10 @@
 
     <!--新增所有列-->
     <insert id="addSCanteen">
-        INSERT INTO s_canteen(id, canteen_name, canteen_photo_path, supply_time_id, founder, create_time, update_time, isdel)
-        VALUES (#{id}, #{canteenName}, #{canteenPhotoPath}, #{supplyTimeId}, #{founder}, #{createTime}, #{updateTime}, #{isdel})
+        INSERT INTO s_canteen(id, canteen_name, canteen_photo_path, supply_time_id, founder, principal,
+        complaint_phone, takeout_phone, create_time, update_time, isdel)
+        VALUES (#{id}, #{canteenName}, #{canteenPhotoPath}, #{supplyTimeId}, #{founder}, #{principal}, #{createTime},
+        #{complaintPhone}, #{takeoutPhone}, #{updateTime}, #{isdel})
     </insert>
 
     <!--通过主键修改数据-->
@@ -68,6 +76,15 @@
             <if test="founder != null">
                 founder = #{founder},
             </if>
+            <if test="principal != null">
+                principal = #{principal},
+            </if>
+            <if test="complaintPhone != null">
+                complaint_phone = #{complaintPhone},
+            </if>
+            <if test="takeoutPhone != null">
+                takeout_phone = #{takeoutPhone},
+            </if>
             <if test="createTime != null">
                 create_time = #{createTime},
             </if>