package com.dy.pmsPlatform.proLine; 
 | 
  
 | 
import com.dy.common.webUtil.QueryResultVo; 
 | 
import com.dy.pmsGlobal.daoPlt.PltProductionLineMapper; 
 | 
import com.dy.pmsGlobal.daoPlt.PltStationMapper; 
 | 
import com.dy.pmsGlobal.pojoPlt.PltProductionLine; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.apache.dubbo.common.utils.PojoUtils; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.stereotype.Service; 
 | 
import org.springframework.transaction.annotation.Transactional; 
 | 
  
 | 
import java.util.List; 
 | 
import java.util.Map; 
 | 
  
 | 
@Slf4j 
 | 
@Service 
 | 
public class ProLineSv { 
 | 
  
 | 
    private PltProductionLineMapper dao; 
 | 
    private PltStationMapper stationDao; 
 | 
  
 | 
    @Autowired 
 | 
    public void setDao(PltProductionLineMapper dao) { 
 | 
        this.dao = dao; 
 | 
    } 
 | 
    @Autowired 
 | 
    public void setStationDao(PltStationMapper stationDao) { 
 | 
        this.stationDao = stationDao; 
 | 
    } 
 | 
  
 | 
    @Transactional 
 | 
    public int save(PltProductionLine line) throws RuntimeException { 
 | 
        if(dao.selectByNameId(line.id,line.name)>0){ 
 | 
            throw new RuntimeException("生产线名称已存在"); 
 | 
        } 
 | 
        int count = dao.insertSelective(line); 
 | 
        return count; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 逻辑删除实体 
 | 
     * @param id 实体ID 
 | 
     * @return 影响记录数量 
 | 
     */ 
 | 
    @Transactional 
 | 
    public int delete(Long id) { 
 | 
        return this.dao.deleteLogicById(id); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    @Transactional 
 | 
    public int update(PltProductionLine line) throws RuntimeException { 
 | 
        if(dao.selectByNameId(line.id,line.name)>0){ 
 | 
            throw new RuntimeException("生产线名称已存在"); 
 | 
        } 
 | 
        int count = dao.updateByPrimaryKeySelective(line); 
 | 
        return count; 
 | 
    } 
 | 
  
 | 
  
 | 
    public PltProductionLine selectById(String lineId) { 
 | 
        return dao.selectByPrimaryKey(Long.valueOf(lineId)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取列表 
 | 
     */ 
 | 
    public QueryResultVo<List<PltProductionLine>> selectSome(QueryVo queryVo) { 
 | 
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); 
 | 
  
 | 
        //查询符合条件的记录总数 
 | 
        Long itemTotal = this.dao.selectSomeCount(params); 
 | 
  
 | 
        QueryResultVo<List<PltProductionLine>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; 
 | 
        //计算分页等信息 
 | 
        rsVo.calculateAndSet(itemTotal, params); 
 | 
  
 | 
        //查询符合条件的记录 
 | 
        rsVo.obj = this.dao.selectSome(params) ; 
 | 
        return rsVo ; 
 | 
    } 
 | 
  
 | 
    public List<PltProductionLine> selectAll() { 
 | 
        return dao.selectAll(); 
 | 
    } 
 | 
  
 | 
    @Transactional 
 | 
    public int updateStatus(PltProductionLine line) { 
 | 
        if(line.disabled){ 
 | 
            long count = stationDao.selectByLineAndStatus(line.id,false); 
 | 
            if(count>0){ 
 | 
                throw new RuntimeException("该生产线还有启用状态的工站"); 
 | 
            } 
 | 
        } 
 | 
        PltProductionLine lineParam = new PltProductionLine(); 
 | 
        lineParam.id = line.id; 
 | 
        lineParam.disabled = line.disabled; 
 | 
        return dao.updateByPrimaryKeySelective(lineParam); 
 | 
    } 
 | 
} 
 |