Browse Source

酒店员工修改

wangzhengliang 3 years ago
parent
commit
d2af969d56

+ 108 - 0
src/main/java/com/chuanghai/ihotel/controller/HotelStaffController.java

@@ -0,0 +1,108 @@
+package com.chuanghai.ihotel.controller;
+
+import java.util.Arrays;
+
+import com.chuanghai.ihotel.anno.AdminLoginCheck;
+import com.chuanghai.ihotel.anno.ParamCheck;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.chuanghai.ihotel.entity.HotelStaffEntity;
+import com.chuanghai.ihotel.service.HotelStaffService;
+import com.chuanghai.ihotel.common.utils.PageUtils;
+import com.chuanghai.ihotel.common.utils.CommonResult;
+import com.chuanghai.ihotel.common.utils.PageParam;
+
+
+/**
+ * 酒店员工 
+ *
+ * @author codingliang
+ * @email codingliang@gmail.com
+ * @date 2022-08-17 15:38:01
+ */
+@RestController
+@RequestMapping("ihotel/hotelStaff")
+public class HotelStaffController {
+    @Autowired
+    private HotelStaffService hotelStaffService;
+
+    /**
+     * 员工列表
+     */
+    @AdminLoginCheck
+    @GetMapping("/list")
+    public CommonResult<PageUtils<HotelStaffEntity>> list(@RequestHeader("admin_token") String adminToken,
+                                                          PageParam pageParam){
+        PageUtils page = hotelStaffService.queryPage(pageParam);
+
+        return CommonResult.ok().setResult(page);
+    }
+
+    /**
+     * 员工信息
+     */
+    @AdminLoginCheck
+    @GetMapping("/info/{id}")
+    public CommonResult<HotelStaffEntity> info(@RequestHeader("admin_token") String adminToken,
+                                               @PathVariable("id") Long id){
+		HotelStaffEntity hotelStaff = hotelStaffService.getById(id);
+
+        return CommonResult.ok().setResult(hotelStaff);
+    }
+
+    /**
+     * 新增员工
+     */
+    @ParamCheck(index = 2)
+    @AdminLoginCheck
+    @PostMapping("/save")
+    public CommonResult<String> save(@RequestHeader("admin_token") String adminToken,
+                                     @RequestBody HotelStaffEntity hotelStaff){
+		hotelStaffService.save(hotelStaff);
+
+        return CommonResult.ok();
+    }
+
+    /**
+     * 修改员工
+     */
+    @ParamCheck(index = 2)
+    @AdminLoginCheck
+    @PutMapping("/update")
+    public CommonResult<String> update(@RequestHeader("admin_token") String adminToken,
+                                       @RequestBody HotelStaffEntity hotelStaff){
+		boolean flag = hotelStaffService.updateById(hotelStaff);
+
+		if (flag) {
+            return CommonResult.ok();
+        } else {
+		    return CommonResult.fail();
+        }
+    }
+
+    /**
+     * 删除员工
+     */
+    @AdminLoginCheck
+    @DeleteMapping("/delete")
+    public CommonResult<String> delete(@RequestHeader("admin_token") String adminToken,
+                                       @RequestBody Long[] ids){
+        boolean flag = hotelStaffService.removeByIds(Arrays.asList(ids));
+
+        if (flag) {
+            return CommonResult.ok();
+        } else {
+            return CommonResult.fail();
+        }
+    }
+
+}

+ 17 - 0
src/main/java/com/chuanghai/ihotel/dao/HotelStaffDao.java

@@ -0,0 +1,17 @@
+package com.chuanghai.ihotel.dao;
+
+import com.chuanghai.ihotel.entity.HotelStaffEntity;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 酒店员工 
+ * 
+ * @author codingliang
+ * @email codingliang@gmail.com
+ * @date 2022-08-17 15:38:01
+ */
+@Mapper
+public interface HotelStaffDao extends BaseMapper<HotelStaffEntity> {
+	
+}

+ 55 - 0
src/main/java/com/chuanghai/ihotel/entity/HotelStaffEntity.java

@@ -0,0 +1,55 @@
+package com.chuanghai.ihotel.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Pattern;
+import java.io.Serializable;
+
+/**
+ * 酒店员工 
+ * 
+ * @author codingliang
+ * @email codingliang@gmail.com
+ * @date 2022-08-17 15:38:01
+ */
+@Data
+@TableName("hotel_staff")
+public class HotelStaffEntity implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * id
+	 */
+	@TableId
+	private Long id;
+	/**
+	 * 员工卡号 微校card_number
+	 */
+	@NotBlank(message = "员工卡号不能为空")
+	private String cardNumber;
+	/**
+	 * 手机号码 登录账号
+	 */
+	@NotBlank(message = "手机号码不能为空")
+	private String phone;
+	/**
+	 * 员工姓名
+	 */
+	@NotBlank(message = "员工姓名不能为空")
+	private String username;
+	/**
+	 * 职位
+	 */
+	@NotBlank(message = "员工职位不能为空")
+	private String position;
+	/**
+	 * 状态 0冻结、1正常
+	 */
+	@NotBlank(message = "状态不能为空")
+	@Pattern(regexp = "[1-2]", message = "状态只能为1或2")
+	private String statu;
+
+}

+ 19 - 0
src/main/java/com/chuanghai/ihotel/service/HotelStaffService.java

@@ -0,0 +1,19 @@
+package com.chuanghai.ihotel.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.chuanghai.ihotel.common.utils.PageUtils;
+import com.chuanghai.ihotel.common.utils.PageParam;
+import com.chuanghai.ihotel.entity.HotelStaffEntity;
+
+/**
+ * 酒店员工 
+ *
+ * @author codingliang
+ * @email codingliang@gmail.com
+ * @date 2022-08-17 15:38:01
+ */
+public interface HotelStaffService extends IService<HotelStaffEntity> {
+
+    PageUtils queryPage(PageParam pageParam);
+}
+

+ 29 - 0
src/main/java/com/chuanghai/ihotel/service/impl/HotelStaffServiceImpl.java

@@ -0,0 +1,29 @@
+package com.chuanghai.ihotel.service.impl;
+
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chuanghai.ihotel.common.utils.PageUtils;
+import com.chuanghai.ihotel.common.utils.MyQuery;
+import com.chuanghai.ihotel.common.utils.PageParam;
+
+import com.chuanghai.ihotel.dao.HotelStaffDao;
+import com.chuanghai.ihotel.entity.HotelStaffEntity;
+import com.chuanghai.ihotel.service.HotelStaffService;
+
+
+@Service("hotelStaffService")
+public class HotelStaffServiceImpl extends ServiceImpl<HotelStaffDao, HotelStaffEntity> implements HotelStaffService {
+
+    @Override
+    public PageUtils queryPage(PageParam pageParam) {
+        IPage<HotelStaffEntity> page = this.page(
+                new MyQuery<HotelStaffEntity>().getPage(pageParam),
+                new QueryWrapper<>()
+        );
+
+        return new PageUtils(page);
+    }
+
+}

+ 17 - 0
src/main/resources/mapper/ihotel/HotelStaffDao.xml

@@ -0,0 +1,17 @@
+<?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.chuanghai.ihotel.dao.HotelStaffDao">
+
+	<!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.chuanghai.ihotel.entity.HotelStaffEntity" id="hotelStaffMap">
+        <result property="id" column="id"/>
+        <result property="cardNumber" column="card_number"/>
+        <result property="phone" column="phone"/>
+        <result property="username" column="username"/>
+        <result property="position" column="position"/>
+        <result property="statu" column="statu"/>
+    </resultMap>
+
+
+</mapper>