package com.yuanchu.limslaboratory.service.impl; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.yuanchu.limslaboratory.pojo.Classify; import com.yuanchu.limslaboratory.mapper.ClassifyMapper; import com.yuanchu.limslaboratory.service.ClassifyService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import javax.annotation.Resource; import java.util.List; import java.util.Map; /** *

* 服务实现类 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2023-07-20 */ @Service public class ClassifyServiceImpl extends ServiceImpl implements ClassifyService { @Resource private ClassifyMapper classifyMapper; @Override public Integer addClassifyInformation(Classify classify) { List classify1 = classifyMapper.selectOneByName(classify); if (classify1.size()>0){ return 2; } else { classify.setCreateTime(DateUtil.date()); return classifyMapper.insert(classify); } } @Override public List> getListClassifyInformation(String classifyName) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!ObjectUtils.isEmpty(classifyName)){ wrapper.like(Classify::getFatherName, classifyName); } wrapper.groupBy(Classify::getFatherName); wrapper.select(Classify::getId, Classify::getFatherName); List> maps = classifyMapper.selectMaps(wrapper); for (Map map : maps){ LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); wrapper1.eq(Classify::getFatherName, map.get("father_name")); wrapper1.isNotNull(Classify::getSonName); wrapper1.select(Classify::getId, Classify::getSonName); List> maps1 = classifyMapper.selectMaps(wrapper1); if (!ObjectUtils.isEmpty(maps1)){ map.put("children", maps1); map.remove("id"); } else { map.put("children", null); } } return maps; } @Override public Boolean deleteClassifyInformation(String classifyId) { LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); wrapper.eq(Classify::getId, classifyId); wrapper.set(Classify::getState, 0); int isDeleteSuccess = classifyMapper.update(new Classify(), wrapper); return isDeleteSuccess > 0; } @Override public Boolean updateClassifyInformation(Classify classify) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(Classify::getId, classify.getId()); int isUpdateClassifySuccess = classifyMapper.update(classify, updateWrapper); return isUpdateClassifySuccess > 0; } }