| | |
| | | package com.yuanchu.limslaboratory.service.impl; |
| | | |
| | | import com.yuanchu.limslaboratory.entity.Classify; |
| | | 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; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService { |
| | | |
| | | @Resource |
| | | private ClassifyMapper classifyMapper; |
| | | |
| | | @Override |
| | | public Integer addClassifyInformation(Classify classify) { |
| | | if (ObjectUtils.isEmpty(classify.getFatherName())){ |
| | | classify.setFatherName(classify.getSonName()); |
| | | classify.setSonName(null); |
| | | LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Classify::getFatherName, classify.getFatherName()); |
| | | wrapper.isNull(Classify::getSonName); |
| | | wrapper.eq(Classify::getState, 1); |
| | | Classify classify1 = classifyMapper.selectOne(wrapper); |
| | | if (ObjectUtils.isEmpty(classify1)){ |
| | | return classifyMapper.insert(classify); |
| | | } |
| | | return 2; |
| | | } |
| | | LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Classify::getFatherName, classify.getFatherName()); |
| | | wrapper.eq(Classify::getSonName, classify.getSonName()); |
| | | wrapper.eq(Classify::getState, 1); |
| | | Classify classify1 = classifyMapper.selectOne(wrapper); |
| | | if (ObjectUtils.isEmpty(classify1)){ |
| | | return classifyMapper.insert(classify); |
| | | } else { |
| | | return 3; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getListClassifyInformation(String classifyName) { |
| | | LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!ObjectUtils.isEmpty(classifyName)){ |
| | | wrapper.like(Classify::getFatherName, classifyName); |
| | | } |
| | | wrapper.groupBy(Classify::getFatherName); |
| | | wrapper.select(Classify::getId, Classify::getFatherName); |
| | | List<Map<String, Object>> maps = classifyMapper.selectMaps(wrapper); |
| | | for (Map<String, Object> map : maps){ |
| | | LambdaQueryWrapper<Classify> wrapper1 = new LambdaQueryWrapper<>(); |
| | | wrapper1.eq(Classify::getFatherName, map.get("father_name")); |
| | | wrapper1.isNotNull(Classify::getSonName); |
| | | wrapper1.select(Classify::getId, Classify::getSonName); |
| | | List<Map<String, Object>> 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<Classify> 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<Classify> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(Classify::getId, classify.getId()); |
| | | int isUpdateClassifySuccess = classifyMapper.update(classify, updateWrapper); |
| | | return isUpdateClassifySuccess > 0; |
| | | } |
| | | } |