jiangping
2025-02-17 66ca3c7a1abce80143a3bd5c1e197aa020c396b6
server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java
@@ -2,10 +2,14 @@
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.Constants;
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.StringTools;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BaseParamMapper;
import com.doumee.dao.business.BikesMapper;
import com.doumee.dao.business.join.BikesJoinMapper;
import com.doumee.dao.business.model.*;
@@ -23,13 +27,12 @@
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -43,6 +46,8 @@
    @Autowired
    private BikesMapper bikesMapper;
    @Autowired
    private BaseParamMapper baseParamMapper;
    @Autowired
    private BikesJoinMapper bikesJoinMapper;
@@ -51,6 +56,33 @@
    @Override
    public String create(Bikes bikes) {
        if(StringUtils.isBlank(bikes.getParamId() )
                ||StringUtils.isBlank(bikes.getCode())
                ||StringUtils.isBlank(bikes.getDeviceSn())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(baseParamMapper.selectCount(new QueryWrapper<BaseParam>().lambda().eq(BaseParam::getIsdeleted,Constants.ZERO)
                .eq(BaseParam::getType,Constants.FOUR)) ==0){
            throw   new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请选择正确的电车类型!");
        }
        QueryWrapper<Bikes> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Bikes::getCode,bikes.getCode())
                .eq(Bikes::getIsdeleted,Constants.ZERO)
                .eq(Bikes::getType,Constants.ONE);
        Integer count = bikesMapper.selectCount(wrapper);
        if (count > 0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"车牌号号已存在");
        }
        LoginUserInfo user =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        bikes.setId(UUID.randomUUID().toString());
        bikes.setCreateDate(new Date());
        bikes.setCreator(user.getId());
        bikes.setEditDate(bikes.getCreateDate());
        bikes.setEditor(user.getId());
        bikes.setStatus(Constants.ZERO);
        bikes.setIsdeleted(Constants.ZERO);
        bikes.setType(Constants.ONE);//只能新增电车数据
        bikesMapper.insert(bikes);
        return bikes.getId();
    }
@@ -76,6 +108,27 @@
    @Override
    public void updateById(Bikes bikes) {
        QueryWrapper<Bikes> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Bikes::getCode,bikes.getCode())
                .eq(Bikes::getIsdeleted,Constants.ZERO)
                .ne(Bikes::getId,bikes.getId())
                .eq(Bikes::getType,Constants.ONE);
        Integer count = bikesMapper.selectCount(wrapper);
        if (count > 0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"车牌号号已存在");
        }
        if(StringUtils.isNotBlank(bikes.getParamId()) &&
                baseParamMapper.selectCount(new QueryWrapper<BaseParam>().lambda().eq(BaseParam::getIsdeleted,Constants.ZERO)
                .eq(BaseParam::getType,Constants.FOUR)) ==0){
            throw   new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请选择正确的电车类型!");
        }
        LoginUserInfo user =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        bikes.setEditDate(new Date());
        bikes.setEditor(user.getId());
        bikes.setStatus(Constants.ZERO);
        bikes.setIsdeleted(Constants.ZERO);
        bikes.setType(null);//只能新增电车数据
        bikesMapper.updateById(bikes);
    }