|
@@ -0,0 +1,106 @@
|
|
|
+package com.huimv.admin.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+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.huimv.admin.common.utils.Result;
|
|
|
+import com.huimv.admin.common.utils.ResultCode;
|
|
|
+import com.huimv.admin.common.utils.ResultUtil;
|
|
|
+import com.huimv.admin.entity.BaseBuilding;
|
|
|
+import com.huimv.admin.entity.ProtSheepInfo;
|
|
|
+import com.huimv.admin.entity.vo.TreeBaseBuilding;
|
|
|
+import com.huimv.admin.mapper.BaseBuildingMapper;
|
|
|
+import com.huimv.admin.mapper.ProtSheepInfoMapper;
|
|
|
+import com.huimv.admin.service.IBaseBuildingService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author author
|
|
|
+ * @since 2024-08-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BaseBuildingServiceImpl extends ServiceImpl<BaseBuildingMapper, BaseBuilding> implements IBaseBuildingService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseBuildingMapper baseBuildingMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProtSheepInfoMapper sheepInfoMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result addBuilding(BaseBuilding baseBuilding) {
|
|
|
+ if (this.count(new QueryWrapper<BaseBuilding>().eq("build_name",baseBuilding.getBuildName())) != 0) {
|
|
|
+ return new Result(10001,"栋舍名已存在",false);
|
|
|
+ }
|
|
|
+ baseBuilding.setParentId(0);
|
|
|
+ baseBuilding.setFType(1);
|
|
|
+ this.save(baseBuilding);
|
|
|
+ return Result.SUCCESS();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result updateBuilding(BaseBuilding baseBuilding) {
|
|
|
+ if (this.count(new QueryWrapper<BaseBuilding>().eq("build_name",baseBuilding.getBuildName()).ne("id",baseBuilding.getId())) != 0) {
|
|
|
+ return new Result(10001,"栋舍名已存在",false);
|
|
|
+ }
|
|
|
+ //TODO:后面补充羊只和设备的名称修改
|
|
|
+ baseBuildingMapper.updateById(baseBuilding);
|
|
|
+ return ResultUtil.updateResult(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result deleteBuilding(Map<String, Integer> map) {
|
|
|
+ Integer id = map.get("id");
|
|
|
+ List<Integer> cageIds = baseBuildingMapper.getCageById(id);
|
|
|
+ //TODO:后面再进行补充羊只和设备情况
|
|
|
+// if (ObjectUtil.isNotEmpty(cageIds)){
|
|
|
+// if (ObjectUtil.isNotEmpty(baseDuckInfoMapper.selectList(new QueryWrapper<BaseDuckInfo>().in("unit_id",cageIds)))) {
|
|
|
+// return new Result(10001,"删除失败,该栋舍下属笼中存在鸭只",false);
|
|
|
+// }
|
|
|
+// if (ObjectUtil.isNotEmpty(envDeviceMapper.selectList(new QueryWrapper<EnvDevice>().in("unit_id",cageIds)))) {
|
|
|
+// return new Result(10001,"删除失败,该栋舍下属笼中存在设备",false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (ObjectUtil.isNotEmpty(envDeviceMapper.selectList(new QueryWrapper<EnvDevice>().eq("unit_id",id)))) {
|
|
|
+// return new Result(10001,"删除失败,该栋舍存在设备",false);
|
|
|
+// }
|
|
|
+ if (this.removeById(id) && this.removeByIds(cageIds)){
|
|
|
+ return new Result(10000, "删除成功", true);
|
|
|
+ }else {
|
|
|
+ return new Result(10001, "删除失败", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listBuilding(Map<String, String> map) {
|
|
|
+ String farmId = map.get("farmId");
|
|
|
+ QueryWrapper<BaseBuilding> queryWrapper = new QueryWrapper<BaseBuilding>()
|
|
|
+ .eq("farm_id", farmId)
|
|
|
+ .eq("f_type", 1);
|
|
|
+ return new Result(ResultCode.SUCCESS,baseBuildingMapper.selectList(queryWrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listTreeBuilding(Map<String, String> map) {
|
|
|
+ String farmId = map.get("farmId");
|
|
|
+ List<BaseBuilding> baseBuildings = this.list(new QueryWrapper<BaseBuilding>()
|
|
|
+ .eq("farm_id", farmId)
|
|
|
+ .orderByAsc("id"));
|
|
|
+ return new Result(ResultCode.SUCCESS,baseBuildings);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|