|
@@ -1,16 +1,27 @@
|
|
package com.huimv.eartag.service.impl;
|
|
package com.huimv.eartag.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import com.huimv.common.utils.ResultCode;
|
|
|
|
+import com.huimv.eartag.entity.BaseFarmInfo;
|
|
import com.huimv.eartag.entity.BasePigpen;
|
|
import com.huimv.eartag.entity.BasePigpen;
|
|
|
|
+import com.huimv.eartag.entity.dto.BasePigpenDto;
|
|
|
|
+import com.huimv.eartag.mapper.BaseFarmInfoMapper;
|
|
import com.huimv.eartag.mapper.BasePigpenMapper;
|
|
import com.huimv.eartag.mapper.BasePigpenMapper;
|
|
import com.huimv.eartag.service.IBasePigpenService;
|
|
import com.huimv.eartag.service.IBasePigpenService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -23,15 +34,91 @@ import java.util.Map;
|
|
@Service
|
|
@Service
|
|
public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePigpen> implements IBasePigpenService {
|
|
public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePigpen> implements IBasePigpenService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseFarmInfoMapper baseFarmInfoMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /* @Override
|
|
|
|
+ public Result pageAll(Map map) {
|
|
|
|
+
|
|
|
|
+ String searchName = (String) map.get("searchName");
|
|
|
|
+ Map map1 = new HashMap();
|
|
|
|
+ List lista = new ArrayList();
|
|
|
|
+ for (Integer farmId : farmIds) {
|
|
|
|
+ BaseFarmInfo baseFarmInfo = baseFarmInfoMapper.selectById(farmId);
|
|
|
|
+ QueryWrapper<BasePigpen> wrapper = new QueryWrapper<>();
|
|
|
|
+
|
|
|
|
+ wrapper.eq("farm_id",farmId);
|
|
|
|
+ wrapper.like(StringUtils.isNotBlank(searchName),"pigpen_name",searchName);
|
|
|
|
+
|
|
|
|
+ List<BasePigpen> list = this.list(wrapper);
|
|
|
|
+ List<BasePigpen> collect = list.stream().filter(o -> o.getParentId() == 0)
|
|
|
|
+ .peek(o -> o.setChildren(getChildBasePigpenList(o, list)))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ Map map2 = new HashMap();
|
|
|
|
+ map2.put("farmName",baseFarmInfo.getFarmName());
|
|
|
|
+ map2.put("children",collect);
|
|
|
|
+ map2.put("farmId",farmId);
|
|
|
|
+ lista.add(map2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ map1.put("records",lista);
|
|
|
|
+
|
|
|
|
+// wrapper.eq("type",1);
|
|
|
|
+
|
|
|
|
+// Page<BasePigpen> page = page(new Page<>(current, size), wrapper);
|
|
|
|
+// List<BasePigpen> records = page.getRecords();
|
|
|
|
+// for (BasePigpen record : records) {
|
|
|
|
+// record.setChildren(this.list(new QueryWrapper<BasePigpen>().eq("parent_id",record.getId())));
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS,map1);
|
|
|
|
+ }*/
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Result pageAll(Map map) {
|
|
public Result pageAll(Map map) {
|
|
- Integer current = (Integer)map.get("current");
|
|
|
|
- Integer size = (Integer) map.get("size");
|
|
|
|
|
|
+
|
|
String searchName = (String) map.get("searchName");
|
|
String searchName = (String) map.get("searchName");
|
|
|
|
+ Integer farmId = (Integer)map.get("farmId");
|
|
|
|
+
|
|
QueryWrapper<BasePigpen> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<BasePigpen> wrapper = new QueryWrapper<>();
|
|
- wrapper.like("butcher_name",searchName);
|
|
|
|
- Page<BasePigpen> page = page(new Page<>(current, size), wrapper);
|
|
|
|
|
|
|
|
- return new Result(ResultCode.SUCCESS,page);
|
|
|
|
|
|
+ wrapper.like(StringUtils.isNotBlank(searchName),"pigpen_name",searchName);
|
|
|
|
+ wrapper.eq("farm_id",farmId);
|
|
|
|
+
|
|
|
|
+ List<BasePigpen> list = this.list(wrapper);
|
|
|
|
+
|
|
|
|
+ List<BasePigpenDto> basePigpenDtos = BeanUtil.copyToList(list, BasePigpenDto.class);
|
|
|
|
+
|
|
|
|
+ basePigpenDtos.stream().filter(o -> o.getType().equals(3))
|
|
|
|
+ .forEach(o -> o.setGrandId(getGrandId(o.getParentId(), basePigpenDtos)));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<BasePigpenDto> collect = basePigpenDtos.stream().filter(o -> o.getParentId() == 0)
|
|
|
|
+ .peek(o -> o.setChildren(getChildBasePigpenList(o, basePigpenDtos)))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map map1 = new HashMap();
|
|
|
|
+ map1.put("records",collect);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,map1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Integer getGrandId(Integer parentId, List<BasePigpenDto> basePigpenDtos) {
|
|
|
|
+ List<BasePigpenDto> collect = basePigpenDtos.stream().filter(o -> o.getId().equals(parentId))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return collect.get(0).getParentId();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private List<BasePigpenDto> getChildBasePigpenList(BasePigpenDto basePigpenDto, List<BasePigpenDto> list) {
|
|
|
|
+ return list.stream().filter(o -> o.getParentId().equals(basePigpenDto.getId()))
|
|
|
|
+ .peek(o -> o.setChildren(getChildBasePigpenList(o, list)))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|