From 49564f3123b3dc3363414f137050b560f218b8ce Mon Sep 17 00:00:00 2001 From: GitHub <2041376447@qq.com> Date: Thu, 26 Dec 2024 22:13:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86absent=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/AbsentController.java | 115 +++++++++++++++ .../controller/DormitoryController.java | 30 ++-- .../java/com/ruoyi/system/domain/Absent.java | 136 ++++++++++++++++++ .../com/ruoyi/system/domain/Dormitory.java | 17 ++- .../java/com/ruoyi/system/domain/Student.java | 14 +- .../com/ruoyi/system/mapper/AbsentMapper.java | 87 +++++++++++ .../ruoyi/system/mapper/DormitoryMapper.java | 31 +++- .../ruoyi/system/service/IAbsentService.java | 63 ++++++++ .../system/service/IDormitoryService.java | 4 +- .../service/impl/AbsentServiceImpl.java | 131 +++++++++++++++++ .../service/impl/DormitoryServiceImpl.java | 46 +++++- .../resources/mapper/system/AbsentMapper.xml | 120 ++++++++++++++++ .../mapper/system/DormitoryMapper.xml | 43 +++++- 13 files changed, 797 insertions(+), 40 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controller/AbsentController.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/Absent.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/AbsentMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/IAbsentService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AbsentServiceImpl.java create mode 100644 ruoyi-system/src/main/resources/mapper/system/AbsentMapper.xml diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AbsentController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AbsentController.java new file mode 100644 index 0000000..11455d8 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AbsentController.java @@ -0,0 +1,115 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.common.annotation.Anonymous; +import com.ruoyi.system.domain.DormitoryAdmin; +import com.ruoyi.system.vo.PageResult; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +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.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.Absent; +import com.ruoyi.system.service.IAbsentService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 缺寝信息表Controller + * + * @author ruoyi + * @date 2024-12-26 + */ +@RestController +@RequestMapping("/system/absent") +public class AbsentController extends BaseController +{ + @Autowired + private IAbsentService absentService; + + /** + * 查询缺寝信息表列表 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:list')") + @Anonymous + @GetMapping("/list") + public TableDataInfo list(Absent absent) + { + startPage(); + List list = absentService.selectAbsentList(absent); + return getDataTable(list); + } + + /** + * 导出缺寝信息表列表 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:export')") + @Anonymous + @Log(title = "缺寝信息表", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, Absent absent) + { + List list = absentService.selectAbsentList(absent); + ExcelUtil util = new ExcelUtil(Absent.class); + util.exportExcel(response, list, "缺寝信息表数据"); + } + + /** + * 获取缺寝信息表详细信息 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:query')") + @Anonymous + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(absentService.selectAbsentById(id)); + } + + /** + * 新增缺寝信息表 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:add')") + @Anonymous + @Log(title = "缺寝信息表", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody Absent absent) + { + return toAjax(absentService.insertAbsent(absent)); + } + + /** + * 修改缺寝信息表 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:edit')") + @Anonymous + @Log(title = "缺寝信息表", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody Absent absent) + { + return toAjax(absentService.updateAbsent(absent)); + } + + /** + * 删除缺寝信息表 + */ +// @PreAuthorize("@ss.hasPermi('system:absent:remove')") + @Anonymous + @Log(title = "缺寝信息表", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(absentService.deleteAbsentByIds(ids)); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java index c11cce1..93bdf69 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java @@ -3,9 +3,7 @@ package com.ruoyi.system.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.annotation.Anonymous; -import com.ruoyi.system.vo.ResultVo; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -29,7 +27,7 @@ import com.ruoyi.common.core.page.TableDataInfo; * 宿舍表Controller * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ @RestController @RequestMapping("/system/dormitory") @@ -38,18 +36,11 @@ public class DormitoryController extends BaseController @Autowired private IDormitoryService dormitoryService; - @Anonymous - @GetMapping("/available") - public ResultVo availableList(){ - List list = dormitoryService.getAvailableDormitories(); - ResultVo resultVo = new ResultVo(); - resultVo.setData(list); - return resultVo; - } /** * 查询宿舍表列表 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:list')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:list')") + @Anonymous @GetMapping("/list") public TableDataInfo list(Dormitory dormitory) { @@ -61,7 +52,8 @@ public class DormitoryController extends BaseController /** * 导出宿舍表列表 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:export')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:export')") + @Anonymous @Log(title = "宿舍表", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Dormitory dormitory) @@ -74,7 +66,8 @@ public class DormitoryController extends BaseController /** * 获取宿舍表详细信息 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:query')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:query')") + @Anonymous @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { @@ -84,7 +77,8 @@ public class DormitoryController extends BaseController /** * 新增宿舍表 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:add')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:add')") + @Anonymous @Log(title = "宿舍表", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody Dormitory dormitory) @@ -95,7 +89,8 @@ public class DormitoryController extends BaseController /** * 修改宿舍表 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:edit')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:edit')") + @Anonymous @Log(title = "宿舍表", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody Dormitory dormitory) @@ -106,7 +101,8 @@ public class DormitoryController extends BaseController /** * 删除宿舍表 */ - @PreAuthorize("@ss.hasPermi('system:dormitory:remove')") +// @PreAuthorize("@ss.hasPermi('system:dormitory:remove')") + @Anonymous @Log(title = "宿舍表", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Absent.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Absent.java new file mode 100644 index 0000000..3b7c537 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Absent.java @@ -0,0 +1,136 @@ +package com.ruoyi.system.domain; + +import java.util.List; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 缺寝信息表对象 absent + * + * @author ruoyi + * @date 2024-12-26 + */ +public class Absent extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** id */ + private Long id; + + /** building_id */ + @Excel(name = "building_id") + private Long buildingId; + + /** dormitory_id */ + @Excel(name = "dormitory_id") + private Long dormitoryId; + + /** student_id */ + @Excel(name = "student_id") + private Long studentId; + + /** dormitory_admin_id */ + @Excel(name = "dormitory_admin_id") + private Long dormitoryAdminId; + + /** create_date */ + @Excel(name = "create_date") + private String createDate; + + /** reason */ + @Excel(name = "reason") + private String reason; + + /** 学生表信息 */ + private List studentList; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setBuildingId(Long buildingId) + { + this.buildingId = buildingId; + } + + public Long getBuildingId() + { + return buildingId; + } + public void setDormitoryId(Long dormitoryId) + { + this.dormitoryId = dormitoryId; + } + + public Long getDormitoryId() + { + return dormitoryId; + } + public void setStudentId(Long studentId) + { + this.studentId = studentId; + } + + public Long getStudentId() + { + return studentId; + } + public void setDormitoryAdminId(Long dormitoryAdminId) + { + this.dormitoryAdminId = dormitoryAdminId; + } + + public Long getDormitoryAdminId() + { + return dormitoryAdminId; + } + public void setCreateDate(String createDate) + { + this.createDate = createDate; + } + + public String getCreateDate() + { + return createDate; + } + public void setReason(String reason) + { + this.reason = reason; + } + + public String getReason() + { + return reason; + } + + public List getStudentList() + { + return studentList; + } + + public void setStudentList(List studentList) + { + this.studentList = studentList; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("buildingId", getBuildingId()) + .append("dormitoryId", getDormitoryId()) + .append("studentId", getStudentId()) + .append("dormitoryAdminId", getDormitoryAdminId()) + .append("createDate", getCreateDate()) + .append("reason", getReason()) + .append("studentList", getStudentList()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Dormitory.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Dormitory.java index 3bc1978..eb4e591 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Dormitory.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Dormitory.java @@ -1,5 +1,6 @@ package com.ruoyi.system.domain; +import java.util.List; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; @@ -9,7 +10,7 @@ import com.ruoyi.common.core.domain.BaseEntity; * 宿舍表对象 dormitory * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ public class Dormitory extends BaseEntity { @@ -38,6 +39,9 @@ public class Dormitory extends BaseEntity @Excel(name = "telephone") private String telephone; + /** 学生表信息 */ + private List studentList; + public void setId(Long id) { this.id = id; @@ -93,6 +97,16 @@ public class Dormitory extends BaseEntity return telephone; } + public List getStudentList() + { + return studentList; + } + + public void setStudentList(List studentList) + { + this.studentList = studentList; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -102,6 +116,7 @@ public class Dormitory extends BaseEntity .append("type", getType()) .append("availabe", getAvailabe()) .append("telephone", getTelephone()) + .append("studentList", getStudentList()) .toString(); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java index ac3f4e6..41b5068 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java @@ -9,7 +9,7 @@ import com.ruoyi.common.core.domain.BaseEntity; * 学生表对象 student * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ public class Student extends BaseEntity { @@ -32,7 +32,7 @@ public class Student extends BaseEntity /** dormitory_id */ @Excel(name = "dormitory_id") - private Long dormitory_id; + private Long dormitoryId; /** state */ @Excel(name = "state") @@ -40,7 +40,7 @@ public class Student extends BaseEntity /** create_date */ @Excel(name = "create_date") - private String create_date; + private String createDate; public void setId(Long id) { @@ -80,12 +80,12 @@ public class Student extends BaseEntity } public void setDormitoryId(Long dormitoryId) { - this.dormitory_id = dormitoryId; + this.dormitoryId = dormitoryId; } public Long getDormitoryId() { - return dormitory_id; + return dormitoryId; } public void setState(String state) { @@ -98,12 +98,12 @@ public class Student extends BaseEntity } public void setCreateDate(String createDate) { - this.create_date = createDate; + this.createDate = createDate; } public String getCreateDate() { - return create_date; + return createDate; } @Override diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AbsentMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AbsentMapper.java new file mode 100644 index 0000000..a82e7e6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AbsentMapper.java @@ -0,0 +1,87 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.Absent; +import com.ruoyi.system.domain.Student; + +/** + * 缺寝信息表Mapper接口 + * + * @author ruoyi + * @date 2024-12-26 + */ +public interface AbsentMapper +{ + /** + * 查询缺寝信息表 + * + * @param id 缺寝信息表主键 + * @return 缺寝信息表 + */ + public Absent selectAbsentById(Long id); + + /** + * 查询缺寝信息表列表 + * + * @param absent 缺寝信息表 + * @return 缺寝信息表集合 + */ + public List selectAbsentList(Absent absent); + + /** + * 新增缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + public int insertAbsent(Absent absent); + + /** + * 修改缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + public int updateAbsent(Absent absent); + + /** + * 删除缺寝信息表 + * + * @param id 缺寝信息表主键 + * @return 结果 + */ + public int deleteAbsentById(Long id); + + /** + * 批量删除缺寝信息表 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteAbsentByIds(Long[] ids); + + /** + * 批量删除学生表 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteStudentByNames(Long[] ids); + + /** + * 批量新增学生表 + * + * @param studentList 学生表列表 + * @return 结果 + */ + public int batchStudent(List studentList); + + + /** + * 通过缺寝信息表主键删除学生表信息 + * + * @param id 缺寝信息表ID + * @return 结果 + */ + public int deleteStudentByName(Long id); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java index 1f26231..acb5fa7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java @@ -2,18 +2,16 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.Dormitory; -import org.apache.ibatis.annotations.Select; +import com.ruoyi.system.domain.Student; /** * 宿舍表Mapper接口 * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ public interface DormitoryMapper { - @Select("SELECT * FROM dormitory WHERE availabe > 0") - List selectAvailableDormitories(); /** * 查询宿舍表 * @@ -61,4 +59,29 @@ public interface DormitoryMapper * @return 结果 */ public int deleteDormitoryByIds(Long[] ids); + + /** + * 批量删除学生表 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteStudentByDormitoryIds(Long[] ids); + + /** + * 批量新增学生表 + * + * @param studentList 学生表列表 + * @return 结果 + */ + public int batchStudent(List studentList); + + + /** + * 通过宿舍表主键删除学生表信息 + * + * @param id 宿舍表ID + * @return 结果 + */ + public int deleteStudentByDormitoryId(Long id); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IAbsentService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IAbsentService.java new file mode 100644 index 0000000..bd3a184 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IAbsentService.java @@ -0,0 +1,63 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.Absent; +import com.ruoyi.system.domain.DormitoryAdmin; +import com.ruoyi.system.vo.PageResult; + +/** + * 缺寝信息表Service接口 + * + * @author ruoyi + * @date 2024-12-26 + */ +public interface IAbsentService +{ + /** + * 查询缺寝信息表 + * + * @param id 缺寝信息表主键 + * @return 缺寝信息表 + */ + public Absent selectAbsentById(Long id); + + /** + * 查询缺寝信息表列表 + * + * @param absent 缺寝信息表 + * @return 缺寝信息表集合 + */ + public List selectAbsentList(Absent absent); + + /** + * 新增缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + public int insertAbsent(Absent absent); + + /** + * 修改缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + public int updateAbsent(Absent absent); + + /** + * 批量删除缺寝信息表 + * + * @param ids 需要删除的缺寝信息表主键集合 + * @return 结果 + */ + public int deleteAbsentByIds(Long[] ids); + + /** + * 删除缺寝信息表信息 + * + * @param id 缺寝信息表主键 + * @return 结果 + */ + public int deleteAbsentById(Long id); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java index c7492ba..fa4c712 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java @@ -7,12 +7,10 @@ import com.ruoyi.system.domain.Dormitory; * 宿舍表Service接口 * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ public interface IDormitoryService { - - public List getAvailableDormitories(); /** * 查询宿舍表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AbsentServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AbsentServiceImpl.java new file mode 100644 index 0000000..1f1aa46 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AbsentServiceImpl.java @@ -0,0 +1,131 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.util.ArrayList; +import com.ruoyi.common.utils.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import com.ruoyi.system.domain.Student; +import com.ruoyi.system.mapper.AbsentMapper; +import com.ruoyi.system.domain.Absent; +import com.ruoyi.system.service.IAbsentService; + +/** + * 缺寝信息表Service业务层处理 + * + * @author ruoyi + * @date 2024-12-26 + */ +@Service +public class AbsentServiceImpl implements IAbsentService +{ + @Autowired + private AbsentMapper absentMapper; + + /** + * 查询缺寝信息表 + * + * @param id 缺寝信息表主键 + * @return 缺寝信息表 + */ + @Override + public Absent selectAbsentById(Long id) + { + return absentMapper.selectAbsentById(id); + } + + /** + * 查询缺寝信息表列表 + * + * @param absent 缺寝信息表 + * @return 缺寝信息表 + */ + @Override + public List selectAbsentList(Absent absent) + { + return absentMapper.selectAbsentList(absent); + } + + /** + * 新增缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + @Transactional + @Override + public int insertAbsent(Absent absent) + { + int rows = absentMapper.insertAbsent(absent); + insertStudent(absent); + return rows; + } + + /** + * 修改缺寝信息表 + * + * @param absent 缺寝信息表 + * @return 结果 + */ + @Transactional + @Override + public int updateAbsent(Absent absent) + { + absentMapper.deleteStudentByName(absent.getId()); + insertStudent(absent); + return absentMapper.updateAbsent(absent); + } + + /** + * 批量删除缺寝信息表 + * + * @param ids 需要删除的缺寝信息表主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteAbsentByIds(Long[] ids) + { + absentMapper.deleteStudentByNames(ids); + return absentMapper.deleteAbsentByIds(ids); + } + + /** + * 删除缺寝信息表信息 + * + * @param id 缺寝信息表主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteAbsentById(Long id) + { + absentMapper.deleteStudentByName(id); + return absentMapper.deleteAbsentById(id); + } + + /** + * 新增学生表信息 + * + * @param absent 缺寝信息表对象 + */ + public void insertStudent(Absent absent) + { + List studentList = absent.getStudentList(); + Long id = absent.getId(); + if (StringUtils.isNotNull(studentList)) + { + List list = new ArrayList(); + for (Student student : studentList) + { + student.setName(String.valueOf(id)); + list.add(student); + } + if (list.size() > 0) + { + absentMapper.batchStudent(list); + } + } + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java index e05bd44..39a5ac1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java @@ -3,6 +3,10 @@ package com.ruoyi.system.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import com.ruoyi.common.utils.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import com.ruoyi.system.domain.Student; import com.ruoyi.system.mapper.DormitoryMapper; import com.ruoyi.system.domain.Dormitory; import com.ruoyi.system.service.IDormitoryService; @@ -11,7 +15,7 @@ import com.ruoyi.system.service.IDormitoryService; * 宿舍表Service业务层处理 * * @author ruoyi - * @date 2024-12-23 + * @date 2024-12-26 */ @Service public class DormitoryServiceImpl implements IDormitoryService @@ -19,10 +23,6 @@ public class DormitoryServiceImpl implements IDormitoryService @Autowired private DormitoryMapper dormitoryMapper; - public List getAvailableDormitories() { - // 使用自定义 Mapper 来查询可用的宿舍 - return dormitoryMapper.selectAvailableDormitories(); - } /** * 查询宿舍表 * @@ -53,10 +53,13 @@ public class DormitoryServiceImpl implements IDormitoryService * @param dormitory 宿舍表 * @return 结果 */ + @Transactional @Override public int insertDormitory(Dormitory dormitory) { - return dormitoryMapper.insertDormitory(dormitory); + int rows = dormitoryMapper.insertDormitory(dormitory); + insertStudent(dormitory); + return rows; } /** @@ -65,9 +68,12 @@ public class DormitoryServiceImpl implements IDormitoryService * @param dormitory 宿舍表 * @return 结果 */ + @Transactional @Override public int updateDormitory(Dormitory dormitory) { + dormitoryMapper.deleteStudentByDormitoryId(dormitory.getId()); + insertStudent(dormitory); return dormitoryMapper.updateDormitory(dormitory); } @@ -77,9 +83,11 @@ public class DormitoryServiceImpl implements IDormitoryService * @param ids 需要删除的宿舍表主键 * @return 结果 */ + @Transactional @Override public int deleteDormitoryByIds(Long[] ids) { + dormitoryMapper.deleteStudentByDormitoryIds(ids); return dormitoryMapper.deleteDormitoryByIds(ids); } @@ -89,9 +97,35 @@ public class DormitoryServiceImpl implements IDormitoryService * @param id 宿舍表主键 * @return 结果 */ + @Transactional @Override public int deleteDormitoryById(Long id) { + dormitoryMapper.deleteStudentByDormitoryId(id); return dormitoryMapper.deleteDormitoryById(id); } + + /** + * 新增学生表信息 + * + * @param dormitory 宿舍表对象 + */ + public void insertStudent(Dormitory dormitory) + { + List studentList = dormitory.getStudentList(); + Long id = dormitory.getId(); + if (StringUtils.isNotNull(studentList)) + { + List list = new ArrayList(); + for (Student student : studentList) + { + student.setDormitoryId(id); + list.add(student); + } + if (list.size() > 0) + { + dormitoryMapper.batchStudent(list); + } + } + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/AbsentMapper.xml b/ruoyi-system/src/main/resources/mapper/system/AbsentMapper.xml new file mode 100644 index 0000000..88c728e --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/AbsentMapper.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, building_id, dormitory_id, student_id, dormitory_admin_id, create_date, reason from absent + + + + + + + + + + insert into absent + + building_id, + dormitory_id, + student_id, + dormitory_admin_id, + create_date, + reason, + + + #{buildingId}, + #{dormitoryId}, + #{studentId}, + #{dormitoryAdminId}, + #{createDate}, + #{reason}, + + + + + update absent + + building_id = #{buildingId}, + dormitory_id = #{dormitoryId}, + student_id = #{studentId}, + dormitory_admin_id = #{dormitoryAdminId}, + create_date = #{createDate}, + reason = #{reason}, + + where id = #{id} + + + + delete from absent where id = #{id} + + + + delete from absent where id in + + #{id} + + + + + delete from student where name in + + #{name} + + + + + delete from student where name = #{name} + + + + insert into student( id, number, name, gender, dormitory_id, state, create_date) values + + ( #{item.id}, #{item.number}, #{item.name}, #{item.gender}, #{item.dormitoryId}, #{item.state}, #{item.createDate}) + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/DormitoryMapper.xml b/ruoyi-system/src/main/resources/mapper/system/DormitoryMapper.xml index fc5173a..d49810f 100644 --- a/ruoyi-system/src/main/resources/mapper/system/DormitoryMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/DormitoryMapper.xml @@ -13,6 +13,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + select id, building_id, name, type, availabe, telephone from dormitory @@ -28,11 +42,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select id, building_id, name, type, availabe, telephone + from dormitory where id = #{id} + + insert into dormitory @@ -73,4 +94,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + + delete from student where dormitory_id in + + #{dormitoryId} + + + + + delete from student where dormitory_id = #{dormitoryId} + + + + insert into student( id, number, name, gender, dormitory_id, state, create_date) values + + ( #{item.id}, #{item.number}, #{item.name}, #{item.gender}, #{item.dormitoryId}, #{item.state}, #{item.createDate}) + + \ No newline at end of file