|
@@ -0,0 +1,181 @@
|
|
|
+package com.qmrb.system.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.qmrb.system.pojo.entity.Contract;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.qmrb.system.common.enums.StatusEnum;
|
|
|
+import com.qmrb.system.pojo.vo.Option;
|
|
|
+import com.qmrb.system.converter.VirtualParkingSlotConverter;
|
|
|
+import com.qmrb.system.pojo.entity.VirtualParkingSlot;
|
|
|
+import com.qmrb.system.pojo.form.VirtualParkingSlotForm;
|
|
|
+import com.qmrb.system.pojo.vo.VirtualParkingSlotVO;
|
|
|
+import com.qmrb.system.pojo.query.VirtualParkingSlotQuery;
|
|
|
+import com.qmrb.system.mapper.VirtualParkingSlotMapper;
|
|
|
+import com.qmrb.system.service.IVirtualParkingSlotService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import jakarta.validation.Valid;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 虚拟车位表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author gs
|
|
|
+ * @since 2025-04-15
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class VirtualParkingSlotServiceImpl extends ServiceImpl<VirtualParkingSlotMapper, VirtualParkingSlot> implements IVirtualParkingSlotService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VirtualParkingSlotConverter converter;
|
|
|
+
|
|
|
+ /**分页查询
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Page<VirtualParkingSlotVO> getPage(VirtualParkingSlotQuery queryParams) {
|
|
|
+ // 查询参数
|
|
|
+ int pageNum = queryParams.getPageNum();
|
|
|
+ int pageSize = queryParams.getPageSize();
|
|
|
+ String status = queryParams.getStatus();
|
|
|
+ //String keywords = queryParams.getKeywords();
|
|
|
+
|
|
|
+ // 查询数据
|
|
|
+ Page<VirtualParkingSlot> dictItemPage = this.page(
|
|
|
+ new Page<>(pageNum, pageSize),
|
|
|
+ new LambdaQueryWrapper<VirtualParkingSlot>()
|
|
|
+ .eq(StrUtil.isNotBlank(status), VirtualParkingSlot::getStatus,status)
|
|
|
+ //.like(StrUtil.isNotBlank(keywords), VirtualParkingSlot::getCategoryName, keywords)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 实体转换
|
|
|
+ Page<VirtualParkingSlotVO> pageResult = converter.entity2Page(dictItemPage);
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存表单
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public VirtualParkingSlotForm saveForm(@Valid VirtualParkingSlotForm form) {
|
|
|
+ // 实体对象转换 form->entity
|
|
|
+ VirtualParkingSlot entity = converter.form2Entity(form);
|
|
|
+ // 持久化
|
|
|
+ this.save(entity);
|
|
|
+ VirtualParkingSlotForm result = converter.entity2Form(entity);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新包租协议新增虚拟车位
|
|
|
+ * @param contract
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void createFormsByContract(Contract contract) {
|
|
|
+ // 1 判断该包租协议是否已创建虚拟车位
|
|
|
+ List<VirtualParkingSlot> list = this.list(new LambdaQueryWrapper<VirtualParkingSlot>().eq(VirtualParkingSlot::getContractId, contract.getId())
|
|
|
+ .ne(VirtualParkingSlot::getStatus,"2").orderByAsc(VirtualParkingSlot::getId));
|
|
|
+ if(CollectionUtil.isNotEmpty(list)){
|
|
|
+ List<VirtualParkingSlot> allVirtuals = this.list(new LambdaQueryWrapper<VirtualParkingSlot>().eq(VirtualParkingSlot::getContractId, contract.getId()).orderByAsc(VirtualParkingSlot::getId));
|
|
|
+ // 若包租协议得最大车位数小于虚拟车位数,则停用超出部分得虚拟车位
|
|
|
+ if(contract.getMaxParkingLotNum() < list.size()){
|
|
|
+ List<VirtualParkingSlot> outVirtuals = list.subList(contract.getMaxParkingLotNum(), list.size());
|
|
|
+ if(CollectionUtil.isNotEmpty(outVirtuals)){
|
|
|
+ outVirtuals = outVirtuals.stream().map(iter->{
|
|
|
+ iter.setStatus("2");
|
|
|
+ return iter;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ log.info("1==============>:{}",outVirtuals.size());
|
|
|
+ // todo 如果已停车,是否释放
|
|
|
+ this.updateBatchById(outVirtuals);
|
|
|
+ }
|
|
|
+ }else if(contract.getMaxParkingLotNum()>list.size() && contract.getMaxParkingLotNum() < allVirtuals.size()){
|
|
|
+ ArrayList<VirtualParkingSlot> virtualParkingSlots = new ArrayList<>();
|
|
|
+ // 如果包租协议最大车位数大于启用虚拟车位,但小于总虚拟车位
|
|
|
+ // 更新部分虚拟车位状态为空闲
|
|
|
+ List<VirtualParkingSlot> outVirtuals = allVirtuals.subList(list.size(), contract.getMaxParkingLotNum());
|
|
|
+ outVirtuals = outVirtuals.stream().map(iter -> {
|
|
|
+ iter.setStatus("0");
|
|
|
+ return iter;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ log.info("2==============>:{}",outVirtuals.size());
|
|
|
+ this.updateBatchById(outVirtuals);
|
|
|
+
|
|
|
+ }else if(contract.getMaxParkingLotNum() > allVirtuals.size()){
|
|
|
+ // 如果包租协议最大车位数大于启用虚拟车位,但小于总虚拟车位
|
|
|
+ list = allVirtuals.stream().map(iter->{
|
|
|
+ if(StrUtil.equals("2",iter.getStatus())){
|
|
|
+ iter.setStatus("0");
|
|
|
+ }
|
|
|
+ return iter;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 增加虚拟车位
|
|
|
+ Integer index = allVirtuals.size() + 1;;
|
|
|
+ List<VirtualParkingSlot> newVirtuals = new ArrayList<>();
|
|
|
+ for(int i = contract.getMaxParkingLotNum(); i > allVirtuals.size();i--){
|
|
|
+ VirtualParkingSlot virtualParkingSlot = new VirtualParkingSlot();
|
|
|
+ virtualParkingSlot.setContractId(contract.getId());
|
|
|
+ virtualParkingSlot.setVirtualSlotNumber("A"+index);
|
|
|
+ newVirtuals.add(virtualParkingSlot);
|
|
|
+ index ++;
|
|
|
+ }
|
|
|
+ list.addAll(newVirtuals);
|
|
|
+ list.sort((s1, s2) -> s1.getVirtualSlotNumber().compareTo(s2.getVirtualSlotNumber()));
|
|
|
+ log.info("3==============>:{}",list.size());
|
|
|
+ this.saveOrUpdateBatch(list);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 首次创建包租协议,初始化虚拟车位
|
|
|
+ list = new ArrayList<>();
|
|
|
+ Integer index = 1;
|
|
|
+ for(int i = contract.getMaxParkingLotNum(); i > 0;i--){
|
|
|
+ VirtualParkingSlot virtualParkingSlot = new VirtualParkingSlot();
|
|
|
+ virtualParkingSlot.setContractId(contract.getId());
|
|
|
+ virtualParkingSlot.setVirtualSlotNumber("A"+index);
|
|
|
+ list.add(virtualParkingSlot);
|
|
|
+ index ++;
|
|
|
+ }
|
|
|
+ this.saveBatch(list);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**更新
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public boolean updateForm(Long id, VirtualParkingSlotForm form) {
|
|
|
+ VirtualParkingSlot entity = converter.form2Entity(form);
|
|
|
+ entity.setId(id);
|
|
|
+ boolean result = this.updateById(entity);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**获取表单数据
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public VirtualParkingSlotForm getFormData(Long id) {
|
|
|
+ // 获取entity
|
|
|
+ VirtualParkingSlot entity = this.getById(id);
|
|
|
+ Assert.isTrue(entity != null, "虚拟车位表不存在");
|
|
|
+
|
|
|
+ // 实体转换
|
|
|
+ VirtualParkingSlotForm form = converter.entity2Form(entity);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|