Commit 3224f83e by 吕明尚

新增房间标签绑定功能

parent 80f24fb4
......@@ -89,4 +89,9 @@ public class LabelController extends BaseController {
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(labelService.deleteLabelByIds(ids));
}
@GetMapping("/queryList")
public AjaxResult queryList() {
return success(labelService.querylist());
}
}
package share.web.controller.system;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import share.common.annotation.Log;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.core.page.TableDataInfo;
import share.common.enums.BusinessType;
import share.common.utils.poi.ExcelUtil;
import share.system.domain.RoomLabel;
import share.system.domain.vo.RoomLabelVo;
import share.system.service.RoomLabelService;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 房间标签Controller
*
* @author ruoyi
* @date 2024-04-22
*/
@RestController
@RequestMapping("/system/roomLabel")
public class RoomLabelController extends BaseController {
@Autowired
private RoomLabelService roomLabelService;
/**
* 查询房间标签列表
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:list')")
@GetMapping("/list")
public TableDataInfo list(RoomLabel roomLabel) {
startPage();
List<RoomLabelVo> list = roomLabelService.selectRoomLabelList(roomLabel);
return getDataTable(list);
}
/**
* 导出房间标签列表
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:export')")
@Log(title = "房间标签", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, RoomLabel roomLabel) {
List<RoomLabelVo> list = roomLabelService.selectRoomLabelList(roomLabel);
ExcelUtil<RoomLabelVo> util = new ExcelUtil<RoomLabelVo>(RoomLabelVo.class);
util.exportExcel(response, list, "房间标签数据");
}
/**
* 获取房间标签详细信息
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(roomLabelService.selectRoomLabelById(id));
}
/**
* 新增房间标签
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:add')")
@Log(title = "房间标签", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody RoomLabel roomLabel) {
return toAjax(roomLabelService.insertRoomLabel(roomLabel));
}
/**
* 修改房间标签
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:edit')")
@Log(title = "房间标签", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody RoomLabel roomLabel) {
return toAjax(roomLabelService.updateRoomLabel(roomLabel));
}
/**
* 删除房间标签
*/
@PreAuthorize("@ss.hasPermi('system:roomLabel:remove')")
@Log(title = "房间标签", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(roomLabelService.deleteRoomLabelByIds(ids));
}
}
......@@ -8,8 +8,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public enum YesNoEnum {
yes(1, true, "是", "激活", "正常", "Y", "", "", "", "", ""),
no(0, false, "否", "冻结", "异常", "N", "", "", "", "", "");
yes(1, true, "是", "激活", "正常", "Y", "续费", "", "", "", ""),
no(0, false, "否", "冻结", "异常", "N", "预定", "", "", "", "");
private Integer index;
......@@ -110,6 +110,15 @@ public enum YesNoEnum {
return "";
}
public static String getLabelName(Integer index) {
for (YesNoEnum yesNo : YesNoEnum.values()) {
if (yesNo.index.equals(index)) {
return yesNo.display_5;
}
}
return "";
}
public static String getSuccessNameByIndex(Integer index){
for (YesNoEnum yesNo : YesNoEnum.values()) {
if (yesNo.index.equals(index)){
......
package share.system.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
......@@ -12,6 +13,7 @@ import share.common.core.domain.BaseEntity;
* @author ruoyi
* @date 2024-04-19
*/
@TableName("s_label")
@Data
public class Label extends BaseEntity {
private static final long serialVersionUID = 1L;
......
package share.system.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import java.math.BigDecimal;
/**
* 房间标签对象 s_room_label
*
* @author ruoyi
* @date 2024-04-22
*/
@Data
@TableName("s_room_label")
public class RoomLabel extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
private Long id;
/**
* 门店id
*/
@Excel(name = "门店id")
private Long storeId;
/**
* 房间id
*/
@Excel(name = "房间id")
private Long roomId;
/**
* 标签id
*/
@Excel(name = "标签id")
private Long labelId;
/**
* 套餐id
*/
@Excel(name = "套餐id")
private Long packId;
/**
* 促销时长
*/
@Excel(name = "促销时长")
private String promotionDuration;
/**
* 促销金额
*/
@Excel(name = "促销金额")
private BigDecimal promotionAmount;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("storeId", getStoreId())
.append("roomId", getRoomId())
.append("labelId", getLabelId())
.append("packId", getPackId())
.append("promotionDuration", getPromotionDuration())
.append("promotionAmount", getPromotionAmount())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}
package share.system.domain.vo;
import lombok.Data;
import share.system.domain.RoomLabel;
@Data
public class RoomLabelVo extends RoomLabel {
private String storeName;
private String roomName;
private String labelName;
private String packName;
private Long labelType;
}
package share.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import share.system.domain.RoomLabel;
import java.util.List;
/**
* 房间标签Mapper接口
*
* @author ruoyi
* @date 2024-04-22
*/
public interface RoomLabelMapper extends BaseMapper<RoomLabel> {
/**
* 查询房间标签
*
* @param id 房间标签主键
* @return 房间标签
*/
public RoomLabel selectRoomLabelById(Long id);
/**
* 查询房间标签列表
*
* @param roomLabel 房间标签
* @return 房间标签集合
*/
public List<RoomLabel> selectRoomLabelList(RoomLabel roomLabel);
/**
* 新增房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
public int insertRoomLabel(RoomLabel roomLabel);
/**
* 修改房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
public int updateRoomLabel(RoomLabel roomLabel);
/**
* 删除房间标签
*
* @param id 房间标签主键
* @return 结果
*/
public int deleteRoomLabelById(Long id);
/**
* 批量删除房间标签
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteRoomLabelByIds(Long[] ids);
}
......@@ -59,4 +59,6 @@ public interface LabelService extends IService<Label> {
* @return 结果
*/
public int deleteLabelById(Long id);
List<Label> querylist();
}
package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.RoomLabel;
import share.system.domain.vo.RoomLabelVo;
import java.util.List;
/**
* 房间标签Service接口
*
* @author ruoyi
* @date 2024-04-22
*/
public interface RoomLabelService extends IService<RoomLabel> {
/**
* 查询房间标签
*
* @param id 房间标签主键
* @return 房间标签
*/
public RoomLabel selectRoomLabelById(Long id);
/**
* 查询房间标签列表
*
* @param roomLabel 房间标签
* @return 房间标签集合
*/
public List<RoomLabelVo> selectRoomLabelList(RoomLabel roomLabel);
/**
* 新增房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
public int insertRoomLabel(RoomLabel roomLabel);
/**
* 修改房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
public int updateRoomLabel(RoomLabel roomLabel);
/**
* 批量删除房间标签
*
* @param ids 需要删除的房间标签主键集合
* @return 结果
*/
public int deleteRoomLabelByIds(Long[] ids);
/**
* 删除房间标签信息
*
* @param id 房间标签主键
* @return 结果
*/
public int deleteRoomLabelById(Long id);
}
......@@ -3,6 +3,7 @@ package share.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils;
import share.system.domain.Label;
import share.system.mapper.LabelMapper;
......@@ -88,4 +89,14 @@ public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements
public int deleteLabelById(Long id) {
return labelMapper.deleteLabelById(id);
}
@Override
public List<Label> querylist() {
List<Label> labels = labelMapper.selectList(null);
labels.stream().forEach(item -> {
item.setName(item.getName() + "-" + YesNoEnum.getLabelName(Math.toIntExact(item.getType())));
});
return labels;
}
}
package share.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import share.common.utils.DateUtils;
import share.common.utils.bean.BeanUtils;
import share.system.domain.*;
import share.system.domain.vo.RoomLabelVo;
import share.system.mapper.RoomLabelMapper;
import share.system.service.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 房间标签Service业务层处理
*
* @author ruoyi
* @date 2024-04-22
*/
@Service
public class RoomLabelServiceImpl extends ServiceImpl<RoomLabelMapper, RoomLabel> implements RoomLabelService {
@Autowired
private RoomLabelMapper roomLabelMapper;
@Autowired
private ISStoreService storeService;
@Autowired
private ISRoomService roomService;
@Autowired
private IPackService packService;
@Autowired
private LabelService labelService;
/**
* 查询房间标签
*
* @param id 房间标签主键
* @return 房间标签
*/
@Override
public RoomLabel selectRoomLabelById(Long id) {
return roomLabelMapper.selectRoomLabelById(id);
}
/**
* 查询房间标签列表
*
* @param roomLabel 房间标签
* @return 房间标签
*/
@Override
public List<RoomLabelVo> selectRoomLabelList(RoomLabel roomLabel) {
List<RoomLabel> roomLabels = roomLabelMapper.selectRoomLabelList(roomLabel);
if (CollectionUtils.isEmpty(roomLabels)) {
return new ArrayList<>();
}
return doListToVoList(roomLabels);
}
/**
* 新增房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
@Override
public int insertRoomLabel(RoomLabel roomLabel) {
RoomLabel selectedOne = roomLabelMapper.selectOne(
new LambdaQueryWrapper<RoomLabel>().
eq(RoomLabel::getRoomId, roomLabel.getRoomId()).
eq(RoomLabel::getLabelId, roomLabel.getLabelId()));
if (!ObjectUtils.isEmpty(selectedOne)) {
throw new RuntimeException("该房间已存在该标签");
}
roomLabel.setCreateTime(DateUtils.getNowDate());
if (!ObjectUtils.isEmpty(roomLabel.getRoomId())) {
SRoom one = roomService.getOne(new LambdaQueryWrapper<SRoom>().eq(SRoom::getId, roomLabel.getRoomId()));
if (ObjectUtils.isEmpty(one)) {
throw new RuntimeException("门店不存在");
} else {
roomLabel.setStoreId(one.getStoreId());
}
}
return roomLabelMapper.insertRoomLabel(roomLabel);
}
/**
* 修改房间标签
*
* @param roomLabel 房间标签
* @return 结果
*/
@Override
public int updateRoomLabel(RoomLabel roomLabel) {
roomLabel.setUpdateTime(DateUtils.getNowDate());
return roomLabelMapper.updateRoomLabel(roomLabel);
}
/**
* 批量删除房间标签
*
* @param ids 需要删除的房间标签主键
* @return 结果
*/
@Override
public int deleteRoomLabelByIds(Long[] ids) {
return roomLabelMapper.deleteRoomLabelByIds(ids);
}
/**
* 删除房间标签信息
*
* @param id 房间标签主键
* @return 结果
*/
@Override
public int deleteRoomLabelById(Long id) {
return roomLabelMapper.deleteRoomLabelById(id);
}
public List<RoomLabelVo> doListToVoList(List<RoomLabel> list) {
Map<Long, SStore> sStoreMap = storeService.list().stream()
.collect(Collectors.toMap(SStore::getId, store -> store));
Map<Long, SRoom> roomMap = roomService.list().stream()
.collect(Collectors.toMap(SRoom::getId, room -> room));
Map<Long, SPack> packMap = packService.list().stream()
.collect(Collectors.toMap(SPack::getId, pack -> pack));
Map<Long, Label> labelMap = labelService.list().stream()
.collect(Collectors.toMap(Label::getId, label -> label));
List<RoomLabelVo> voList = new ArrayList<>();
list.forEach(item -> {
RoomLabelVo vo = new RoomLabelVo();
BeanUtils.copyProperties(item, vo);
vo.setStoreName(sStoreMap.containsKey(item.getStoreId()) ? sStoreMap.get(item.getStoreId()).getName() : "");
vo.setRoomName(roomMap.containsKey(item.getRoomId()) ? roomMap.get(item.getRoomId()).getName() : "");
vo.setPackName(packMap.containsKey(item.getPackId()) ? packMap.get(item.getPackId()).getName() : "");
vo.setLabelName(labelMap.containsKey(item.getLabelId()) ? labelMap.get(item.getLabelId()).getName() : "");
vo.setLabelType(labelMap.containsKey(item.getLabelId()) ? labelMap.get(item.getLabelId()).getType() : null);
voList.add(vo);
});
return voList;
}
}
<?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="share.system.mapper.RoomLabelMapper">
<resultMap type="RoomLabel" id="RoomLabelResult">
<result property="id" column="id"/>
<result property="storeId" column="store_id"/>
<result property="roomId" column="room_id"/>
<result property="labelId" column="label_id"/>
<result property="packId" column="pack_id"/>
<result property="promotionDuration" column="promotion_duration"/>
<result property="promotionAmount" column="promotion_amount"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectRoomLabelVo">
select id,
store_id,
room_id,
label_id,
pack_id,
promotion_duration,
promotion_amount,
create_by,
create_time,
update_by,
update_time,
remark
from s_room_label
</sql>
<select id="selectRoomLabelList" parameterType="RoomLabel" resultMap="RoomLabelResult">
<include refid="selectRoomLabelVo"/>
<where>
<if test="storeId != null ">and store_id = #{storeId}</if>
<if test="roomId != null ">and room_id = #{roomId}</if>
<if test="labelId != null ">and label_id = #{labelId}</if>
<if test="packId != null ">and pack_id = #{packId}</if>
<if test="promotionDuration != null and promotionDuration != ''">and promotion_duration =
#{promotionDuration}
</if>
<if test="promotionAmount != null ">and promotion_amount = #{promotionAmount}</if>
</where>
</select>
<select id="selectRoomLabelById" parameterType="Long" resultMap="RoomLabelResult">
<include refid="selectRoomLabelVo"/>
where id = #{id}
</select>
<insert id="insertRoomLabel" parameterType="RoomLabel" useGeneratedKeys="true" keyProperty="id">
insert into s_room_label
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="storeId != null">store_id,</if>
<if test="roomId != null">room_id,</if>
<if test="labelId != null">label_id,</if>
<if test="packId != null">pack_id,</if>
<if test="promotionDuration != null">promotion_duration,</if>
<if test="promotionAmount != null">promotion_amount,</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>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="storeId != null">#{storeId},</if>
<if test="roomId != null">#{roomId},</if>
<if test="labelId != null">#{labelId},</if>
<if test="packId != null">#{packId},</if>
<if test="promotionDuration != null">#{promotionDuration},</if>
<if test="promotionAmount != null">#{promotionAmount},</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>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateRoomLabel" parameterType="RoomLabel">
update s_room_label
<trim prefix="SET" suffixOverrides=",">
<if test="storeId != null">store_id = #{storeId},</if>
<if test="roomId != null">room_id = #{roomId},</if>
<if test="labelId != ''">label_id = #{labelId},</if>
<if test="packId != ''">pack_id = #{packId},</if>
<if test="promotionDuration != ''">promotion_duration = #{promotionDuration},</if>
<if test="promotionAmount != ''">promotion_amount = #{promotionAmount},</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>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteRoomLabelById" parameterType="Long">
delete
from s_room_label
where id = #{id}
</delete>
<delete id="deleteRoomLabelByIds" parameterType="String">
delete from s_room_label where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment