|  |  | 
 |  |  | package com.doumee.service.business.impl; | 
 |  |  |  | 
 |  |  | 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.Utils; | 
 |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.checkerframework.checker.units.qual.C; | 
 |  |  | 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实现 | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public String create(BaseParam baseParam) { | 
 |  |  |         baseParamMapper.insert(baseParam); | 
 |  |  |         return baseParam.getId(); | 
 |  |  |  | 
 |  |  |         LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |  | 
 |  |  |         if (Objects.isNull(baseParam.getType()) || StringUtils.isEmpty(baseParam.getName())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"参数错误"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         QueryWrapper<BaseParam> wrapper = new QueryWrapper<>(); | 
 |  |  |         wrapper.lambda() | 
 |  |  |                 .eq(BaseParam::getType,baseParam.getType()) | 
 |  |  |                 .eq(BaseParam::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(BaseParam::getName,baseParam.getName()); | 
 |  |  |  | 
 |  |  |         Integer count = baseParamMapper.selectCount(wrapper); | 
 |  |  |         if (count > 0){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"车辆问题已存在"); | 
 |  |  |         } | 
 |  |  |         BaseParam insert = new BaseParam(); | 
 |  |  |         insert.setCreateDate(new Date()); | 
 |  |  |         insert.setCreator(principal.getId()); | 
 |  |  |         insert.setEditDate(new Date()); | 
 |  |  |         insert.setEditor(principal.getId()); | 
 |  |  |         insert.setIsdeleted(Constants.ZERO); | 
 |  |  |         insert.setName(baseParam.getName()); | 
 |  |  |         insert.setSortnum(baseParam.getSortnum()); | 
 |  |  |         insert.setType(baseParam.getType()); | 
 |  |  |         insert.setStatus(Constants.ZERO); | 
 |  |  |         insert.setInfo(baseParam.getInfo()); | 
 |  |  |         insert.setRequired(baseParam.getRequired()); | 
 |  |  |         baseParamMapper.insert(insert); | 
 |  |  |         return insert.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(String id) { | 
 |  |  |         baseParamMapper.deleteById(id); | 
 |  |  |         BaseParam baseParam = new BaseParam(); | 
 |  |  |         baseParam.setId(id); | 
 |  |  |         baseParam.setEditDate(new Date()); | 
 |  |  |         baseParam.setIsdeleted(Constants.ONE); | 
 |  |  |         baseParamMapper.updateById(baseParam); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void delete(BaseParam baseParam) { | 
 |  |  |         UpdateWrapper<BaseParam> deleteWrapper = new UpdateWrapper<>(baseParam); | 
 |  |  |         baseParamMapper.delete(deleteWrapper); | 
 |  |  | //      UpdateWrapper<BaseParam> deleteWrapper = new UpdateWrapper<>(baseParam); | 
 |  |  |         baseParam.setIsdeleted(Constants.ONE); | 
 |  |  |         baseParamMapper.updateById(baseParam); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteByIdInBatch(List<String> ids) { | 
 |  |  |  | 
 |  |  |         if (CollectionUtils.isEmpty(ids)) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         baseParamMapper.deleteBatchIds(ids); | 
 |  |  |        for(String id :ids){ | 
 |  |  |            deleteById(id); | 
 |  |  |        } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void updateById(BaseParam baseParam) { | 
 |  |  |         baseParamMapper.updateById(baseParam); | 
 |  |  |         LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         QueryWrapper<BaseParam> wrapper = new QueryWrapper<>(); | 
 |  |  |         wrapper.lambda() | 
 |  |  |                 .eq(BaseParam::getType,baseParam.getType()) | 
 |  |  |                 .eq(BaseParam::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(BaseParam::getName,baseParam.getName()); | 
 |  |  |  | 
 |  |  |         BaseParam baseParam1 = baseParamMapper.selectOne(wrapper.last(" limit 1")); | 
 |  |  |         if (Objects.nonNull(baseParam1) && !baseParam1.getId().equals(baseParam.getId())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"车辆问题已存在"); | 
 |  |  |         } | 
 |  |  |         UpdateWrapper<BaseParam> updateWrapper = new UpdateWrapper<>(); | 
 |  |  |         updateWrapper | 
 |  |  |                 .lambda() | 
 |  |  |                 .eq(BaseParam::getId,baseParam.getId()) | 
 |  |  |                 .set(BaseParam::getRequired,baseParam.getRequired()) | 
 |  |  |                 .set(BaseParam::getName,baseParam.getName()) | 
 |  |  |                 .set(BaseParam::getSortnum,baseParam.getSortnum()) | 
 |  |  |                 .set(BaseParam::getEditDate,new Date()) | 
 |  |  |                 .set(BaseParam::getEditor,principal.getId()); | 
 |  |  |         baseParamMapper.update(null,updateWrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public BaseParam findOne(BaseParam baseParam) { | 
 |  |  |         QueryWrapper<BaseParam> wrapper = new QueryWrapper<>(baseParam); | 
 |  |  |         return baseParamMapper.selectOne(wrapper); | 
 |  |  |         return baseParamMapper.selectOne(wrapper.last(" limit 1")); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<BaseParam> findList(BaseParam baseParam) { | 
 |  |  |         QueryWrapper<BaseParam> wrapper = new QueryWrapper<>(baseParam); | 
 |  |  |         baseParam.setIsdeleted(Constants.ZERO); | 
 |  |  |         wrapper.orderByAsc("sortnum"); | 
 |  |  |         return baseParamMapper.selectList(wrapper); | 
 |  |  |     } | 
 |  |  |    | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public PageData<BaseParam> findPage(PageWrap<BaseParam> pageWrap) { | 
 |  |  |         IPage<BaseParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |         QueryWrapper<BaseParam> queryWrapper = new QueryWrapper<>(); | 
 |  |  |         Utils.MP.blankToNull(pageWrap.getModel()); | 
 |  |  |         pageWrap.getModel().setIsdeleted(Constants.ZERO); | 
 |  |  |         if (pageWrap.getModel().getId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getId, pageWrap.getModel().getId()); | 
 |  |  |         } | 
 |  |  | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getName() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getName, pageWrap.getModel().getName()); | 
 |  |  |             queryWrapper.lambda().like(BaseParam::getName, pageWrap.getModel().getName()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getSortnum() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getSortnum, pageWrap.getModel().getSortnum()); | 
 |  |  | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getStatus, pageWrap.getModel().getStatus()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getInfo() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getInfo, pageWrap.getModel().getInfo()); | 
 |  |  |             queryWrapper.lambda().like(BaseParam::getInfo, pageWrap.getModel().getInfo()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getRequired() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseParam::getRequired, pageWrap.getModel().getRequired()); | 
 |  |  |         } | 
 |  |  |         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
 |  |  |             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
 |  |  |                 queryWrapper.orderByDesc(sortData.getProperty()); | 
 |  |  |             } else { | 
 |  |  |                 queryWrapper.orderByAsc(sortData.getProperty()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         queryWrapper.lambda().orderByAsc(BaseParam::getSortnum); | 
 |  |  |         return PageData.from(baseParamMapper.selectPage(page, queryWrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public long count(BaseParam baseParam) { | 
 |  |  |         QueryWrapper<BaseParam> wrapper = new QueryWrapper<>(baseParam); | 
 |  |  |         baseParam.setIsdeleted(Constants.ZERO); | 
 |  |  |         return baseParamMapper.selectCount(wrapper); | 
 |  |  |     } | 
 |  |  | } |