This commit is contained in:
sxu 2025-04-29 10:21:00 +08:00
parent 94daf19822
commit 466f2454e8
3 changed files with 20 additions and 6 deletions

View File

@ -18,6 +18,8 @@ public interface AllocCanteenMapper {
*/
public AllocCanteen selectAllocCanteenByCanteenId(Long canteenId);
public AllocCanteen selectAllocCanteenByCanteenName(String canteenName);
/**
* 查询食堂信息列表
*

View File

@ -7,10 +7,7 @@ import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.alloc.domain.AllocCanteen;
import com.bonus.canteen.core.alloc.domain.AllocStall;
import com.bonus.canteen.core.alloc.domain.AppletReserveCanteenVO;
import com.bonus.canteen.core.alloc.domain.AppletReserveStallVO;
import com.bonus.canteen.core.alloc.domain.*;
import com.bonus.canteen.core.alloc.mapper.AllocCanteenMapper;
import com.bonus.canteen.core.utils.BnsConstants;
import com.bonus.common.core.exception.ServiceException;
@ -65,9 +62,13 @@ public class AllocCanteenServiceImpl implements IAllocCanteenService {
allocCanteen.setCreateTime(DateUtils.getNowDate());
allocCanteen.setIfReserve(BnsConstants.COMMON_YES); //默认开启预订餐
try {
AllocCanteen checkResult = allocCanteenMapper.selectAllocCanteenByCanteenName(allocCanteen.getCanteenName());
if (Objects.nonNull(checkResult)) {
throw new ServiceException("食堂名称已存在");
}
return allocCanteenMapper.insertAllocCanteen(allocCanteen);
} catch (Exception e) {
throw new ServiceException("错误信息描述");
throw new ServiceException("新增食堂异常," + e.getMessage());
}
}
@ -81,9 +82,15 @@ public class AllocCanteenServiceImpl implements IAllocCanteenService {
public int updateAllocCanteen(AllocCanteen allocCanteen) {
allocCanteen.setUpdateTime(DateUtils.getNowDate());
try {
List<AllocCanteen> allCanteenList = allocCanteenMapper.selectAllocCanteenList(new AllocCanteen());
List<String> otherCanteenNameList = allCanteenList.stream().filter(item -> !item.getCanteenId().equals(allocCanteen.getCanteenId()))
.map(AllocCanteen::getCanteenName).collect(Collectors.toList());
if (otherCanteenNameList.contains(allocCanteen.getCanteenName())) {
throw new ServiceException("食堂名称已存在");
}
return allocCanteenMapper.updateAllocCanteen(allocCanteen);
} catch (Exception e) {
throw new ServiceException("错误信息描述");
throw new ServiceException("更新食堂异常," + e.getMessage());
}
}

View File

@ -70,6 +70,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where ac.canteen_id = #{canteenId}
</select>
<select id="selectAllocCanteenByCanteenName" parameterType="String" resultMap="AllocCanteenResult">
<include refid="selectAllocCanteenVo"/>
where ac.canteen_name = #{canteenName}
</select>
<insert id="insertAllocCanteen" parameterType="com.bonus.canteen.core.alloc.domain.AllocCanteen" useGeneratedKeys="true" keyProperty="canteenId">
insert into alloc_canteen
<trim prefix="(" suffix=")" suffixOverrides=",">