package com.zteits.park.biz.parkgroup; import com.clouds.common.utils.ListCopyUtil; import com.clouds.common.utils.SequenceUtil; import com.github.pagehelper.PageInfo; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.bean.PageBean; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.apibase.constants.ErrorType; import com.zteits.clouds.api.apibase.exception.BizException; import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO; import com.zteits.clouds.api.dto.park.dto.parkgroup.ParkingLotGroupDTO; import com.zteits.clouds.api.dto.park.dto.parkgroup.ParkingLotGroupRelDTO; import com.zteits.clouds.api.dto.park.param.parkgroup.ParkingLotGroupQueryReq; import com.zteits.clouds.api.dto.park.param.parkgroup.ParkingLotGroupSaveReq; import com.zteits.clouds.api.dto.park.param.parkgroup.SaveGroupRelReq; import com.zteits.clouds.api.service.park.parkgroup.ParkingLotGroupService; import com.zteits.park.dao.ParkingLotGroupDao; import com.zteits.park.dao.ParkingLotGroupRelDao; import com.zteits.park.domain.ParkingLotGroup; import com.zteits.park.domain.ParkingLotGroupExample; import com.zteits.park.domain.ParkingLotGroupRel; import com.zteits.park.domain.ParkingLotGroupRelExample; import com.zteits.park.mapper.ParkingLotGroupMapper; import com.zteits.park.mapper.ParkingLotGroupRelMapper; import com.zteits.park.pagepager.PageBeanUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; /** * Copyright: Copyright (c) 2017 zteits * * @ClassName: ParkingLotGroupServiceImpl.java * @Description: * @version: v1.0.0 * @author: wangfs * @date: 2021-04-19 10:53 * Modification History: * Date Author Version Description * ---------------------------------------------------------* * 2021-04-19 wangfs v1.0.0 创建 */ @Service("com.zteits.park.biz.parkgroup.ParkingLotGroupServiceImpl") public class ParkingLotGroupServiceImpl implements ParkingLotGroupService { @Autowired private ParkingLotGroupDao parkingLotGroupDao; @Autowired private ParkingLotGroupRelDao parkingLotGroupRelDao; @Autowired private ParkingLotGroupMapper parkingLotGroupMapper; @Autowired private ParkingLotGroupRelMapper parkingLotGroupRelMapper; /** * 车场组 * * @param * @return * @Auther: wangfs */ @Transactional(rollbackFor = Exception.class) @Override public BizResult saveParkingLotGroup(ParkingLotGroupSaveReq req) { Long parkGroupNo = SequenceUtil.getNextId(); req.setPlGroupNo(parkGroupNo + ""); Boolean aBoolean = this.parkGroupNameExist(req.getPlGroupName()); if (aBoolean) { throw new BizException(ErrorType.OBJECT_EXISTS, "组名称已经存在!"); } Integer integer = parkingLotGroupDao.saveParkingLotGroup(req); return new BizResult(integer > 0); } @Override public BizResult updateParkingLotGroupById(ParkingLotGroupSaveReq req) { if (req == null || req.getId() == null) { throw new BizException(ErrorType.PARAMM_NULL, "id为空!"); } Boolean aBoolean = this.parkGroupNameExist(req.getPlGroupName()); if (aBoolean) { throw new BizException(ErrorType.OBJECT_EXISTS, "组名称已经存在!"); } Integer integer = parkingLotGroupDao.updateParkingLotGroup(req); return new BizResult(integer > 0); } @Transactional(rollbackFor = Exception.class) @Override public BizResult deleteParkingLotGroupById(ParkingLotGroupSaveReq req) { if (req == null || req.getId() == null) { throw new BizException(ErrorType.PARAMM_NULL, "id为空!"); } ParkingLotGroup parkingLotGroup = parkingLotGroupMapper.selectByPrimaryKey(req.getId()); parkingLotGroupMapper.deleteByPrimaryKey(req.getId()); ParkingLotGroupRelExample example = new ParkingLotGroupRelExample(); example.createCriteria().andPlGroupNoEqualTo(parkingLotGroup.getPlGroupNo()); int i = parkingLotGroupRelMapper.deleteByExample(example); return new BizResult(i > 0); } private Boolean parkGroupNameExist(String groupName) { Boolean flg = false; ParkingLotGroupExample example = new ParkingLotGroupExample(); example.createCriteria().andDataStatusEqualTo(1).andPlGroupNameEqualTo(groupName); List parkingLotGroups = parkingLotGroupMapper.selectByExample(example); if (!CollectionUtils.isEmpty(parkingLotGroups) && parkingLotGroups.size() > 0) { flg = true; } return flg; } @Override public BizResult> queryParkGroupForPage(ParkingLotGroupSaveReq request) { PageBean pageBean = new PageBean(); PageInfo pageInfo = parkingLotGroupDao.queryParkGroupForPage(request); PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotGroupDTO.class); this.ParkingLotGroupRelDao(pageBean); return new BizResult>(pageBean); } /** * 保存车场关系表 * * @param * @return * @Auther: wangfs */ @Transactional(rollbackFor = Exception.class) @Override public BizResult saveGroupRelReq(SaveGroupRelReq req) { if (req == null || req.getPlGroupNo() == null) { throw new BizException(ErrorType.PARAMM_NULL, "plGroupNo为空!"); } Boolean flg = parkingLotGroupRelDao.saveGroupRelReq(req); return new BizResult(flg); } @Override public BizResult> queryParkGroupForList(ParkingLotGroupSaveReq request) { List listDTO = new ArrayList<>(); ParkingLotGroupExample example = new ParkingLotGroupExample(); example.createCriteria().andDataStatusEqualTo(1).andOrgIdEqualTo(request.getOrgId()).andParkNumGreaterThan(0); List parkingLotGroups = parkingLotGroupMapper.selectByExample(example); ListCopyUtil.listCopyProperties(parkingLotGroups, listDTO, ParkingLotGroupDTO.class); return new BizResult>(listDTO); } @Override public BizResult> queryParkGroupForListByplGroupNo(ParkingLotGroupQueryReq request) { ParkingLotGroupRelExample example = new ParkingLotGroupRelExample(); example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()) .andPlGroupNoEqualTo(request.getPlGroupNo()); List parkingLotGroupRels = parkingLotGroupRelMapper.selectByExample(example); List parkingLotDTOS = new ArrayList<>(); if (CollectionUtils.isEmpty(parkingLotGroupRels)) { return new BizResult<>(parkingLotDTOS); } ListCopyUtil.listCopyProperties(parkingLotGroupRels,parkingLotDTOS,ParkingLotDTO.class); return new BizResult<>(parkingLotDTOS); } private void ParkingLotGroupRelDao(PageBean pageBean) { if (null != pageBean && !CollectionUtils.isEmpty(pageBean.getDataList())) { List dataList = pageBean.getDataList(); for (ParkingLotGroupDTO parkingLotGroupDTO : dataList) { if (null == parkingLotGroupDTO || StringUtils.isEmpty(parkingLotGroupDTO.getPlGroupNo())) { continue; } List listDTO = new ArrayList<>(); List parkingLotGroupRels = parkingLotGroupRelDao.queryParkingLotGroupRelByGroupCodeId(parkingLotGroupDTO.getPlGroupNo()); ListCopyUtil.listCopyProperties(parkingLotGroupRels, listDTO, ParkingLotGroupRelDTO.class); parkingLotGroupDTO.setGroupRelList(listDTO); } } } }