package com.dy.pmsPlatform.tstCommand; 
 | 
  
 | 
import com.dy.common.webFilter.UserTokenContext; 
 | 
import com.dy.common.webUtil.QueryResultVo; 
 | 
import com.dy.pmsGlobal.daoTst.TstCommandMapper; 
 | 
import com.dy.pmsGlobal.pojoBa.BaUser; 
 | 
import com.dy.pmsGlobal.pojoTst.TstCommand; 
 | 
import com.dy.pmsGlobal.util.UserUtil; 
 | 
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.Date; 
 | 
import java.util.List; 
 | 
import java.util.Map; 
 | 
  
 | 
@Slf4j 
 | 
@Service 
 | 
public class TstCommandSv { 
 | 
    private TstCommandMapper dao; 
 | 
    private UserUtil userUtil; 
 | 
  
 | 
    @Autowired 
 | 
    public void setDao(TstCommandMapper dao) { 
 | 
        this.dao = dao; 
 | 
    } 
 | 
    @Autowired 
 | 
    public void setUserUtil(UserUtil userUtil) { 
 | 
        this.userUtil = userUtil; 
 | 
    } 
 | 
  
 | 
    @Transactional 
 | 
    public int save(TstCommand command) throws RuntimeException { 
 | 
        if(dao.selectByNameId(command.id,command.proId,command.name)>0){ 
 | 
            throw new RuntimeException("指令名称已存在"); 
 | 
        } 
 | 
        command.disabled = false; 
 | 
        command.deleted = false; 
 | 
        BaUser loginUser = userUtil.getUser(UserTokenContext.get()); 
 | 
        if (loginUser != null) { 
 | 
            command.creator = loginUser.id; 
 | 
        } 
 | 
        command.dt = new Date(); 
 | 
        int count = dao.insertSelective(command); 
 | 
        return count; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 逻辑删除实体 
 | 
     * @param id 实体ID 
 | 
     * @return 影响记录数量 
 | 
     */ 
 | 
    @Transactional 
 | 
    public int delete(Long id) { 
 | 
        return this.dao.deleteLogicById(id); 
 | 
    } 
 | 
  
 | 
  
 | 
    @Transactional 
 | 
    public int update(TstCommand command) throws RuntimeException { 
 | 
        if(dao.selectByNameId(command.id,command.proId,command.name)>0){ 
 | 
            throw new RuntimeException("指令名称已存在"); 
 | 
        } 
 | 
        BaUser loginUser = userUtil.getUser(UserTokenContext.get()); 
 | 
        if (loginUser != null) { 
 | 
            command.updatedBy = loginUser.id; 
 | 
        } 
 | 
        command.updatedDate = new Date(); 
 | 
        int count = dao.updateByPrimaryKeySelective(command); 
 | 
        return count; 
 | 
    } 
 | 
  
 | 
    public TstCommand selectById(String id) { 
 | 
        return dao.selectByPrimaryKey(Long.valueOf(id)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取列表 
 | 
     */ 
 | 
    public QueryResultVo<List<TstCommand>> selectSome(QueryVo queryVo) { 
 | 
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); 
 | 
  
 | 
        //查询符合条件的记录总数 
 | 
        Long itemTotal = this.dao.selectSomeCount(params); 
 | 
  
 | 
        QueryResultVo<List<TstCommand>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; 
 | 
        //计算分页等信息 
 | 
        rsVo.calculateAndSet(itemTotal, params); 
 | 
  
 | 
        //查询符合条件的记录 
 | 
        rsVo.obj = this.dao.selectSome(params) ; 
 | 
        return rsVo ; 
 | 
    } 
 | 
  
 | 
    public List<TstCommand> selectAll() { 
 | 
        return dao.selectAll(); 
 | 
    } 
 | 
} 
 |