|
@@ -0,0 +1,180 @@
|
|
|
|
+package com.care.bms.service;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.care.common.entity.CareHouse;
|
|
|
|
+import com.care.common.entity.CareMemberInfo;
|
|
|
|
+import com.care.common.entity.CareStation;
|
|
|
|
+import com.care.common.entity.CareSysUser;
|
|
|
|
+import com.care.common.enums.KeyEscrowTypeEnum;
|
|
|
|
+import com.care.common.exception.BDException;
|
|
|
|
+import com.care.common.service.CareHouseService;
|
|
|
|
+import com.care.common.service.CareMemberInfoService;
|
|
|
|
+import com.care.common.service.CareStationService;
|
|
|
|
+import com.care.common.vo.PageReqVO;
|
|
|
|
+import com.care.common.vo.UserLogindConvertVO;
|
|
|
|
+import com.care.common.vo.device.HouseVO;
|
|
|
|
+import com.care.common.vo.sysuser.CareSysUserVO;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author: lilt
|
|
|
|
+ * @Date: 2021/7/14
|
|
|
|
+ * @Desc:
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class HouseService {
|
|
|
|
+ @Resource
|
|
|
|
+ private CareHouseService careHouseService;
|
|
|
|
+ @Resource
|
|
|
|
+ private CareMemberInfoService careMemberInfoService;
|
|
|
|
+ @Resource
|
|
|
|
+ private CareStationService careStationService;
|
|
|
|
+ /**
|
|
|
|
+ * 删除房屋
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public boolean deleteById(Long id){
|
|
|
|
+ return this.careHouseService.removeById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public HouseVO getHouseById(Long id){
|
|
|
|
+ CareHouse house = this.careHouseService.getById(id);
|
|
|
|
+ if (house!=null){
|
|
|
|
+ HouseVO vo = new HouseVO();
|
|
|
|
+ BeanUtil.copyProperties(house,vo);
|
|
|
|
+ vo.setKeyEscrowTypeName(KeyEscrowTypeEnum.getCodeToName(vo.getKeyEscrowType()));
|
|
|
|
+ if ("0".equals(vo.getStatus())){
|
|
|
|
+ vo.setStatusName("未激活");
|
|
|
|
+ }else if ("1".equals(vo.getStatus())){
|
|
|
|
+ vo.setStatusName("已激活");
|
|
|
|
+ }
|
|
|
|
+ CareStation station = this.careStationService.getById(vo.getStationId());
|
|
|
|
+ if (station!=null){
|
|
|
|
+ vo.setStationName(station.getShortName());
|
|
|
|
+ }
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存房屋
|
|
|
|
+ * @param vo
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void createHouse(HouseVO vo,UserLogindConvertVO loginUser){
|
|
|
|
+ //生成登陆账号
|
|
|
|
+ if (StrUtil.isNotEmpty(vo.getManagePhone())){
|
|
|
|
+ CareMemberInfo memberInfo = careMemberInfoService.detailByPhone(vo.getManagePhone());
|
|
|
|
+ if (memberInfo!=null){
|
|
|
|
+ throw new BDException("一个用户只能拥有一个房屋,请修改其他手机号");
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ throw new BDException("用户手机号不能为空");
|
|
|
|
+ }
|
|
|
|
+ //保存房屋
|
|
|
|
+ CareHouse house = new CareHouse();
|
|
|
|
+ BeanUtil.copyProperties(vo,house);
|
|
|
|
+ house.setCreateTime(new Date());
|
|
|
|
+ house.setName(house.getAddr());
|
|
|
|
+ house.setStatus("1");
|
|
|
|
+ house.setOrgId(loginUser.getOrgId());
|
|
|
|
+ this.careHouseService.save(house);
|
|
|
|
+ CareMemberInfo memberInfo = new CareMemberInfo();
|
|
|
|
+ memberInfo.setHouseId(house.getId());
|
|
|
|
+ memberInfo.setOlderId(null);
|
|
|
|
+ memberInfo.setName(house.getManageName());
|
|
|
|
+ memberInfo.setPhone(house.getManagePhone());
|
|
|
|
+ memberInfo.setPassword(SecureUtil.md5("123456"));
|
|
|
|
+ memberInfo.setCreateTime(new Date());
|
|
|
|
+ this.careMemberInfoService.save(memberInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存房屋
|
|
|
|
+ * @param vo
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void updateHouse(HouseVO vo){
|
|
|
|
+ //保存房屋
|
|
|
|
+ CareHouse house = this.careHouseService.getById(vo.getId());
|
|
|
|
+ BeanUtil.copyProperties(vo,house);
|
|
|
|
+ house.setModifyTime(new Date());
|
|
|
|
+ house.setName(house.getAddr());
|
|
|
|
+ this.careHouseService.updateById(house);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 列表查询
|
|
|
|
+ * @param loginUser
|
|
|
|
+ * @param pageReqVo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public IPage<HouseVO> listHouse(String addr, Long stationId, String status,UserLogindConvertVO loginUser, PageReqVO pageReqVo) {
|
|
|
|
+ IPage<CareHouse> page = new Page<>(pageReqVo.getCurrent(), pageReqVo.getPageSize());
|
|
|
|
+ QueryWrapper<CareHouse> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(StrUtil.isNotEmpty(status),CareHouse::getStatus, status)
|
|
|
|
+ .like(StrUtil.isNotEmpty(addr),CareHouse::getAddr,addr)
|
|
|
|
+ .eq(CareHouse::getOrgId,loginUser.getOrgId())
|
|
|
|
+ .eq(loginUser.getStationId()!=null,CareHouse::getStationId,loginUser.getStationId())
|
|
|
|
+ .eq(stationId!=null,CareHouse::getStationId,stationId)
|
|
|
|
+ .orderByAsc(CareHouse::getManageName);
|
|
|
|
+
|
|
|
|
+ IPage<CareHouse> pageRes = this.careHouseService.page(page, queryWrapper);
|
|
|
|
+ IPage<HouseVO> results = new Page<>(pageRes.getCurrent(),pageRes.getSize(),pageRes.getTotal());
|
|
|
|
+ if(CollUtil.isNotEmpty(pageRes.getRecords())){
|
|
|
|
+ List<HouseVO> list = new ArrayList<>();
|
|
|
|
+ pageRes.getRecords().forEach(item -> {
|
|
|
|
+ HouseVO resVO = new HouseVO();
|
|
|
|
+ BeanUtils.copyProperties(item,resVO);
|
|
|
|
+ if ("0".equals(resVO.getStatus())){
|
|
|
|
+ resVO.setStatusName("未激活");
|
|
|
|
+ }else if ("1".equals(resVO.getStatus())){
|
|
|
|
+ resVO.setStatusName("已激活");
|
|
|
|
+ }
|
|
|
|
+ resVO.setKeyEscrowType(KeyEscrowTypeEnum.getCodeToName(resVO.getKeyEscrowType()));
|
|
|
|
+ CareStation station = this.careStationService.getById(resVO.getStationId());
|
|
|
|
+ if (station!=null){
|
|
|
|
+ resVO.setStationName(station.getShortName());
|
|
|
|
+ }
|
|
|
|
+ list.add(resVO);
|
|
|
|
+ });
|
|
|
|
+ results.setRecords(list);
|
|
|
|
+ }
|
|
|
|
+ return results;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询某服务站下的房屋列表
|
|
|
|
+ * @param stationId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<HouseVO> queryHouseListByStationId(Long stationId){
|
|
|
|
+ List<HouseVO> datas = new ArrayList<>();
|
|
|
|
+ QueryWrapper<CareHouse> userQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ userQueryWrapper.lambda().eq(CareHouse::getStationId,stationId)
|
|
|
|
+ .orderByAsc(CareHouse::getManageName);
|
|
|
|
+ List<CareHouse> users = this.careHouseService.list(userQueryWrapper);
|
|
|
|
+ if (users != null){
|
|
|
|
+ users.forEach(item -> {
|
|
|
|
+ HouseVO vo = new HouseVO();
|
|
|
|
+ BeanUtil.copyProperties(item,vo);
|
|
|
|
+ datas.add(vo);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+}
|