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;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @author 江苏鵷雏网络科技有限公司
|
* @since 2023-07-20
|
*/
|
@Service
|
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {
|
|
@Resource
|
private ClassifyMapper classifyMapper;
|
|
@Override
|
public Integer addClassifyInformation(Classify classify) {
|
List<Classify> classify1 = classifyMapper.selectOneByName(classify);
|
if (classify1.size()>0){
|
return 2;
|
} else {
|
classify.setCreateTime(DateUtil.date());
|
return classifyMapper.insert(classify);
|
}
|
}
|
|
@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;
|
}
|
}
|