ParkingLotGroupServiceImpl.java 8.17 KB
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<Boolean> 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<Boolean>(integer > 0);
    }

    @Override
    public BizResult<Boolean> 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<Boolean>(integer > 0);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public BizResult<Boolean> 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<Boolean>(i > 0);
    }

    private Boolean parkGroupNameExist(String groupName) {
        Boolean flg = false;
        ParkingLotGroupExample example = new ParkingLotGroupExample();
        example.createCriteria().andDataStatusEqualTo(1).andPlGroupNameEqualTo(groupName);
        List<ParkingLotGroup> parkingLotGroups = parkingLotGroupMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(parkingLotGroups) && parkingLotGroups.size() > 0) {
            flg = true;
        }

        return flg;
    }


    @Override
    public BizResult<PageBean<ParkingLotGroupDTO>> queryParkGroupForPage(ParkingLotGroupSaveReq request) {
        PageBean<ParkingLotGroupDTO> pageBean = new PageBean<ParkingLotGroupDTO>();
        PageInfo<ParkingLotGroup> pageInfo = parkingLotGroupDao.queryParkGroupForPage(request);
        PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotGroupDTO.class);
        this.ParkingLotGroupRelDao(pageBean);
        return new BizResult<PageBean<ParkingLotGroupDTO>>(pageBean);
    }

    /**
     * 保存车场关系表
     *
     * @param
     * @return
     * @Auther: wangfs
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public BizResult<Boolean> saveGroupRelReq(SaveGroupRelReq req) {
        if (req == null || req.getPlGroupNo() == null) {
            throw new BizException(ErrorType.PARAMM_NULL, "plGroupNo为空!");
        }
        Boolean flg = parkingLotGroupRelDao.saveGroupRelReq(req);
        return new BizResult<Boolean>(flg);
    }

    @Override
    public BizResult<List<ParkingLotGroupDTO>> queryParkGroupForList(ParkingLotGroupSaveReq request) {
        List<ParkingLotGroupDTO> listDTO = new ArrayList<>();
        ParkingLotGroupExample example = new ParkingLotGroupExample();
        example.createCriteria().andDataStatusEqualTo(1).andOrgIdEqualTo(request.getOrgId()).andParkNumGreaterThan(0);
        List<ParkingLotGroup> parkingLotGroups = parkingLotGroupMapper.selectByExample(example);
        ListCopyUtil.listCopyProperties(parkingLotGroups, listDTO, ParkingLotGroupDTO.class);
        return new BizResult<List<ParkingLotGroupDTO>>(listDTO);
    }

    @Override
    public BizResult<List<ParkingLotDTO>> queryParkGroupForListByplGroupNo(ParkingLotGroupQueryReq request) {
        ParkingLotGroupRelExample example = new ParkingLotGroupRelExample();
        example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
                .andPlGroupNoEqualTo(request.getPlGroupNo());
        List<ParkingLotGroupRel> parkingLotGroupRels = parkingLotGroupRelMapper.selectByExample(example);
        List<ParkingLotDTO> 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<ParkingLotGroupDTO> pageBean) {
        if (null != pageBean && !CollectionUtils.isEmpty(pageBean.getDataList())) {
            List<ParkingLotGroupDTO> dataList = pageBean.getDataList();
            for (ParkingLotGroupDTO parkingLotGroupDTO : dataList) {
                if (null == parkingLotGroupDTO || StringUtils.isEmpty(parkingLotGroupDTO.getPlGroupNo())) {
                    continue;
                }
                List<ParkingLotGroupRelDTO> listDTO = new ArrayList<>();
                List<ParkingLotGroupRel> parkingLotGroupRels = parkingLotGroupRelDao.queryParkingLotGroupRelByGroupCodeId(parkingLotGroupDTO.getPlGroupNo());
                ListCopyUtil.listCopyProperties(parkingLotGroupRels, listDTO, ParkingLotGroupRelDTO.class);
                parkingLotGroupDTO.setGroupRelList(listDTO);

            }

        }
    }


}