|
@@ -1,10 +1,35 @@
|
|
|
package com.usky.iot.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.iot.domain.BaseBuild;
|
|
|
+import com.usky.iot.domain.BaseBuildFacilityRelate;
|
|
|
+import com.usky.iot.domain.BaseFacilityType;
|
|
|
+import com.usky.iot.domain.BaseGgpFacility;
|
|
|
import com.usky.iot.mapper.BaseBuildMapper;
|
|
|
+import com.usky.iot.service.BaseBuildFacilityRelateService;
|
|
|
import com.usky.iot.service.BaseBuildService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.iot.service.BaseFacilityTypeService;
|
|
|
+import com.usky.iot.service.BaseGgpFacilityService;
|
|
|
+import com.usky.iot.service.vo.BuildFacilityRelateRequestVO;
|
|
|
+import com.usky.iot.service.vo.BuildFacilityRelateResponeVO;
|
|
|
+import com.usky.iot.service.vo.BuildFacilityStatusVO;
|
|
|
+import org.apache.tomcat.jni.Local;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import sun.security.util.Length;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +42,150 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class BaseBuildServiceImpl extends AbstractCrudService<BaseBuildMapper, BaseBuild> implements BaseBuildService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseBuildFacilityRelateService baseBuildFacilityRelateService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseGgpFacilityService baseGgpFacilityService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseFacilityTypeService baseFacilityTypeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(BaseBuild baseBuild){
|
|
|
+// if(checkNameUnique(baseBuild)){
|
|
|
+// throw new BusinessException("新增建筑名称"+baseBuild.getBuildName()+"失败,该建筑名称已存在");
|
|
|
+// }
|
|
|
+ baseBuild.setBuildNum("jz-"+new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()));
|
|
|
+ baseBuild.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ baseBuild.setCreateTime(LocalDateTime.now());
|
|
|
+ baseBuild.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ this.save(baseBuild);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void update(BaseBuild baseBuild){
|
|
|
+// if(checkNameUnique(baseBuild)){
|
|
|
+// throw new BusinessException("修改建筑名称"+baseBuild.getBuildName()+"失败,该建筑名称已存在");
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ baseBuild.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ baseBuild.setUpdateTime(LocalDateTime.now());
|
|
|
+ this.updateById(baseBuild);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void remove(Integer id){
|
|
|
+ BaseBuild baseBuild = this.getById(id);
|
|
|
+ Optional.ofNullable(baseBuild).orElseThrow(() -> new BusinessException("该建筑不存在"));
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseBuildFacilityRelate> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BaseBuildFacilityRelate::getBuildId,baseBuild.getBuildNum());
|
|
|
+ Integer count = baseBuildFacilityRelateService.count(queryWrapper);
|
|
|
+ if(count > 0){
|
|
|
+ throw new BusinessException("该建筑下面有关联建筑设施,不能删除");
|
|
|
+ }
|
|
|
+ this.removeById(id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BaseBuild> dataList(){
|
|
|
+ LambdaQueryWrapper<BaseBuild> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BaseBuild::getDeleteFlag,0)
|
|
|
+ .eq(BaseBuild::getTenantId,SecurityUtils.getTenantId());
|
|
|
+ List<BaseBuild> list = this.list(queryWrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(list)){
|
|
|
+ for(int i=0;i<list.size();i++){
|
|
|
+ LambdaQueryWrapper<BaseBuildFacilityRelate> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(BaseBuildFacilityRelate::getBuildId,list.get(i).getBuildNum());
|
|
|
+ Integer count = baseBuildFacilityRelateService.count(queryWrapper1);
|
|
|
+ list.get(i).setBuildFacilityCount(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<BuildFacilityRelateResponeVO> buildFacilityRelateList(BuildFacilityRelateRequestVO requestVO){
|
|
|
+ List<BuildFacilityRelateResponeVO> list = new ArrayList<>();
|
|
|
+ IPage<BaseGgpFacility> page = new Page<>(requestVO.getCurrent(),requestVO.getSize());
|
|
|
+ LambdaQueryWrapper<BaseGgpFacility> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(requestVO.getFacilityNum()),BaseGgpFacility::getFacilityNum,requestVO.getFacilityNum())
|
|
|
+ .eq(requestVO.getFacilityType() != null,BaseGgpFacility::getFacilityType,requestVO.getFacilityType())
|
|
|
+ .eq(BaseGgpFacility::getTenantId,SecurityUtils.getTenantId());
|
|
|
+ page = baseGgpFacilityService.page(page,queryWrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(page.getRecords())){
|
|
|
+ for(int i=0;i<page.getRecords().size();i++){
|
|
|
+ BuildFacilityRelateResponeVO responeVO = new BuildFacilityRelateResponeVO();
|
|
|
+ responeVO.setBuildId(requestVO.getBuildId());
|
|
|
+ responeVO.setFacilityNum(page.getRecords().get(i).getFacilityNum());
|
|
|
+ responeVO.setFacilityName(page.getRecords().get(i).getFacilityName());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseFacilityType> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(BaseFacilityType::getTypeCode,page.getRecords().get(i).getFacilityType());
|
|
|
+ BaseFacilityType one = baseFacilityTypeService.getOne(queryWrapper1);
|
|
|
+ responeVO.setFacilityType(one.getTypeName());
|
|
|
+
|
|
|
+ responeVO.setAddress(page.getRecords().get(i).getAddress());
|
|
|
+
|
|
|
+ if(page.getRecords().get(i).getId().equals(requestVO.getBuildFacilityId())){
|
|
|
+ responeVO.setStatus(1);
|
|
|
+ }else{
|
|
|
+ responeVO.setStatus(0);
|
|
|
+ }
|
|
|
+ list.add(responeVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new CommonPage<>(list,page.getTotal(),page.getSize(),page.getCurrent());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setBuildFacilityStatus(BuildFacilityStatusVO statusVO){
|
|
|
+ BaseBuild baseBuild = new BaseBuild();
|
|
|
+
|
|
|
+ if(statusVO.getStatus() == 1){
|
|
|
+ LambdaQueryWrapper<BaseBuild> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BaseBuild::getDeleteFlag,0)
|
|
|
+ .eq(BaseBuild::getId,statusVO.getBuildId())
|
|
|
+ .eq(BaseBuild::getTenantId,SecurityUtils.getTenantId());
|
|
|
+ BaseBuild one = this.getOne(queryWrapper);
|
|
|
+
|
|
|
+ if(one.getFacilityId() != null && (""+one.getFacilityId()).length() > 0){
|
|
|
+ throw new BusinessException("绑定失败,该建筑已绑定设施");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<BaseGgpFacility> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.like(BaseGgpFacility::getFacilityNum,statusVO.getFacilityNum())
|
|
|
+ .eq(BaseGgpFacility::getTenantId,SecurityUtils.getTenantId());
|
|
|
+ BaseGgpFacility one1 = baseGgpFacilityService.getOne(queryWrapper1);
|
|
|
+
|
|
|
+ baseBuild.setId(statusVO.getBuildId());
|
|
|
+ baseBuild.setFacilityId(one1.getId());
|
|
|
+ }else{
|
|
|
+ baseBuild.setId(statusVO.getBuildId());
|
|
|
+ baseBuild.setFacilityId(null);
|
|
|
+ }
|
|
|
+ this.updateById(baseBuild);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public boolean checkNameUnique(BaseBuild baseBuild){
|
|
|
+// Integer id = null == baseBuild.getId()?-1:baseBuild.getId();
|
|
|
+// LambdaQueryWrapper<BaseBuild> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+// queryWrapper.eq(BaseBuild::getBuildName,baseBuild.getBuildName())
|
|
|
+// .eq(BaseBuild::getDeleteFlag,0)
|
|
|
+// .eq(BaseBuild::getTenantId,SecurityUtils.getTenantId());
|
|
|
+// BaseBuild one = this.getOne(queryWrapper);
|
|
|
+// return null != one && !Objects.equals(one.getId(),id);
|
|
|
+// }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|