ParkingLotGroupRelDaoImpl.java 3.01 KB
package com.zteits.park.dao.impl;

import com.zteits.clouds.api.dto.park.param.parkgroup.ParkGroupParkDTO;
import com.zteits.clouds.api.dto.park.param.parkgroup.SaveGroupRelReq;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * Copyright: Copyright (c) 2017  zteits
 *
 * @ClassName: ParkingLotGroupRelDaoImpl.java
 * @Description:
 * @version: v1.0.0
 * @author: wangfs
 * @date: 2021-04-20 14:53
 * Modification History:
 * Date             Author          Version            Description
 * ---------------------------------------------------------*
 * 2021-04-20     wangfs              v1.0.0               创建
 */
@Component
public class ParkingLotGroupRelDaoImpl implements ParkingLotGroupRelDao {


    @Autowired
    private ParkingLotGroupRelMapper parkingLotGroupRelMapper;

    @Autowired
    private ParkingLotGroupMapper parkingLotGroupMapper;

    @Override
    public List<ParkingLotGroupRel> queryParkingLotGroupRelByGroupCodeId(String plGroupNo) {
        ParkingLotGroupRelExample example = new ParkingLotGroupRelExample();
        example.createCriteria().andPlGroupNoEqualTo(plGroupNo).andDataStatusEqualTo(1);
        return parkingLotGroupRelMapper.selectByExample(example);
    }

    @Override
    public Boolean saveGroupRelReq(SaveGroupRelReq req) {
        int insertCount =0;
        ParkingLotGroupRelExample example = new ParkingLotGroupRelExample();
        example.createCriteria().andPlGroupNoEqualTo(req.getPlGroupNo());
        parkingLotGroupRelMapper.deleteByExample(example);
        if(!CollectionUtils.isEmpty(req.getParkGroupParkList())){
            for(ParkGroupParkDTO parkGroupParkDTO :req.getParkGroupParkList()){
                ParkingLotGroupRel record = new ParkingLotGroupRel();
                record.setPlGroupNo(req.getPlGroupNo());
                record.setPlNo(parkGroupParkDTO.getPlNo());
                record.setPlName(parkGroupParkDTO.getPlName());
                record.setDataStatus(1);
                record.setCreateEmpid("sys");
                record.setCreateDate(new Date());
                insertCount = parkingLotGroupRelMapper.insert(record);
            }

            ParkingLotGroup record = new ParkingLotGroup();
            record.setParkNum(req.getParkGroupParkList().size());
            ParkingLotGroupExample exampleTwo = new ParkingLotGroupExample();
            exampleTwo.createCriteria().andPlGroupNoEqualTo(req.getPlGroupNo());
            parkingLotGroupMapper.updateByExampleSelective(record,exampleTwo);
        }


        return insertCount >0;
    }
}