Newer
Older
huludao / src / main / java / com / newfiber / api / pc / service / impl / ManPumpstationServiceImpl.java
package com.newfiber.api.pc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.newfiber.api.core.commons.CustomException;
import com.newfiber.api.core.commons.PageRequestObject;
import com.newfiber.api.core.commons.PageResultObject;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.pc.dao.ManPumpstationMapper;
import com.newfiber.api.pc.model.zhz.ManPumpstation;
import com.newfiber.api.pc.service.ManPumpstationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Arrays;

/**
 * @description: 泵站基础信息业务层实现类
 * @author: 张鸿志
 * @date: 2020/12/14 9:50
 * @version: v1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ManPumpstationServiceImpl extends ServiceImpl<ManPumpstationMapper, ManPumpstation> implements ManPumpstationService {

    @Override
    public PageResultObject<ManPumpstation> queryPage(PageRequestObject<String> pageRequestObject) {
        Page<ManPumpstation> page = new Page<>(pageRequestObject.getCurrent(), pageRequestObject.getSize());
        EntityWrapper<ManPumpstation> wrapper = new EntityWrapper<>();
        if(!StringUtils.isEmpty(pageRequestObject.getObject())){
            wrapper.like("pump_name",pageRequestObject.getObject());
        }
        wrapper.orderDesc(Arrays.asList(new String[]{"create_time"}));
        Page<ManPumpstation> pumpstationPage = this.selectPage(page, wrapper);
        int count = this.selectCount(wrapper);
        return new PageResultObject<>(pageRequestObject.getCurrent(), pageRequestObject.getSize(),(long)count,pumpstationPage.getRecords());
    }

    @Override
    public void updatePumpstationInfoById(ManPumpstation info) {
        if(StringUtils.isEmpty(info.getId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        ManPumpstation manPumpstation = this.selectById(info.getId());
        if(StringUtils.isEmpty(manPumpstation)){
            throw new CustomException(500,"没有找到该主键对应的数据!");
        }
        boolean update = this.updateById(info);
        if(!update){
            throw new CustomException(ResultCode.UPDATE_ERROR);
        }

    }
}