package com.doumee.service.business.impl;
|
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.DateUtil;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.business.YwGatewayMapper;
|
import com.doumee.dao.business.model.YwGateway;
|
import com.doumee.service.business.YwGatewayService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 网关管理Service实现
|
* @author renkang
|
* @date 2026/04/02
|
*/
|
@Service
|
public class YwGatewayServiceImpl implements YwGatewayService {
|
|
@Autowired
|
private YwGatewayMapper ywGatewayMapper;
|
|
@Override
|
public Integer create(YwGateway ywGateway) {
|
if (Objects.isNull(ywGateway)
|
|| StringUtils.isBlank(ywGateway.getName())
|
|| StringUtils.isBlank(ywGateway.getGatewayCode())) {
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
LoginUserInfo loginUserInfo = ywGateway.getLoginUserInfo();
|
// 校验网关设备号唯一
|
if (ywGatewayMapper.selectCount(new QueryWrapper<YwGateway>().lambda()
|
.eq(YwGateway::getIsdeleted, Constants.ZERO)
|
.eq(YwGateway::getGatewayCode, ywGateway.getGatewayCode())) > Constants.ZERO) {
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "网关设备号重复!");
|
}
|
ywGateway.setCreateDate(new Date());
|
ywGateway.setCreator(loginUserInfo.getId());
|
ywGateway.setEditDate(new Date());
|
ywGateway.setEditor(loginUserInfo.getId());
|
ywGateway.setIsdeleted(Constants.ZERO);
|
ywGatewayMapper.insert(ywGateway);
|
return ywGateway.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id, LoginUserInfo user) {
|
ywGatewayMapper.update(new UpdateWrapper<YwGateway>()
|
.lambda()
|
.set(YwGateway::getIsdeleted, Constants.ONE)
|
.set(YwGateway::getEditDate, DateUtil.getCurrDateTime())
|
.set(YwGateway::getEditor, user.getId())
|
.eq(YwGateway::getId, id)
|
);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
for (Integer id : ids) {
|
this.deleteById(id, user);
|
}
|
}
|
|
@Override
|
public void updateById(YwGateway ywGateway) {
|
if (Objects.isNull(ywGateway)
|
|| Objects.isNull(ywGateway.getId())
|
|| StringUtils.isBlank(ywGateway.getName())
|
|| StringUtils.isBlank(ywGateway.getGatewayCode())) {
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
LoginUserInfo loginUserInfo = ywGateway.getLoginUserInfo();
|
// 校验网关设备号唯一(排除自身)
|
if (ywGatewayMapper.selectCount(new QueryWrapper<YwGateway>().lambda()
|
.eq(YwGateway::getIsdeleted, Constants.ZERO)
|
.eq(YwGateway::getGatewayCode, ywGateway.getGatewayCode())
|
.ne(YwGateway::getId, ywGateway.getId())) > Constants.ZERO) {
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "网关设备号重复!");
|
}
|
ywGateway.setEditDate(new Date());
|
ywGateway.setEditor(loginUserInfo.getId());
|
ywGatewayMapper.updateById(ywGateway);
|
}
|
|
@Override
|
public void updateStatusById(YwGateway ywGateway) {
|
YwGateway model = new YwGateway();
|
model.setId(ywGateway.getId());
|
model.setStatus(ywGateway.getStatus());
|
ywGatewayMapper.updateById(model);
|
}
|
|
@Override
|
public YwGateway findById(Integer id) {
|
return ywGatewayMapper.selectJoinOne(YwGateway.class,
|
new MPJLambdaWrapper<YwGateway>()
|
.selectAll(YwGateway.class)
|
.selectAs(com.doumee.dao.business.model.YwProject::getName, YwGateway::getProjectName)
|
.leftJoin(com.doumee.dao.business.model.YwProject.class, com.doumee.dao.business.model.YwProject::getId, YwGateway::getProjectId)
|
.eq(YwGateway::getId, id)
|
.last(" limit 1 ")
|
);
|
}
|
|
@Override
|
public PageData<YwGateway> findPage(PageWrap<YwGateway> pageWrap) {
|
IPage<YwGateway> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
MPJLambdaWrapper<YwGateway> queryWrapper = new MPJLambdaWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
YwGateway model = pageWrap.getModel();
|
queryWrapper.selectAll(YwGateway.class)
|
.selectAs(com.doumee.dao.business.model.YwProject::getName, YwGateway::getProjectName)
|
.leftJoin(com.doumee.dao.business.model.YwProject.class, com.doumee.dao.business.model.YwProject::getId, YwGateway::getProjectId)
|
.and(Objects.nonNull(model) && StringUtils.isNotBlank(model.getName()),
|
i -> i.like(YwGateway::getName, model.getName()).or().like(YwGateway::getGatewayCode, model.getName()))
|
.eq(Objects.nonNull(model) && Objects.nonNull(model.getStatus()), YwGateway::getStatus, model.getStatus())
|
.eq(Objects.nonNull(model) && Objects.nonNull(model.getProjectId()), YwGateway::getProjectId, model.getProjectId())
|
.eq(YwGateway::getIsdeleted, Constants.ZERO)
|
.orderByDesc(YwGateway::getCreateDate);
|
IPage<YwGateway> iPage = ywGatewayMapper.selectJoinPage(page, YwGateway.class, queryWrapper);
|
return PageData.from(iPage);
|
}
|
}
|