Search in sources :

Example 1 with ElecCompMapper

use of com.cas.sim.tis.mapper.ElecCompMapper in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompServiceImpl method findElecCompGroupByType.

@Override
public Map<Integer, List<ElecComp>> findElecCompGroupByType() {
    ElecCompMapper dao = (ElecCompMapper) mapper;
    List<ElecComp> all = dao.selectAll();
    if (all == null) {
        return new HashMap<>();
    }
    return all.stream().collect(Collectors.groupingBy(ElecComp::getType));
}
Also used : ElecCompMapper(com.cas.sim.tis.mapper.ElecCompMapper) HashMap(java.util.HashMap) ElecComp(com.cas.sim.tis.entity.ElecComp)

Example 2 with ElecCompMapper

use of com.cas.sim.tis.mapper.ElecCompMapper in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompServiceImpl method findElecCompByModel.

@Override
public ElecComp findElecCompByModel(String model) {
    ElecCompMapper dao = (ElecCompMapper) mapper;
    Condition condition = new Condition(ElecComp.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("model", model);
    List<ElecComp> compList = dao.selectByCondition(condition);
    if (compList.size() == 0) {
        return null;
    } else if (compList.size() > 1) {
        throw new TooManyResultsException();
    }
    return compList.get(0);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) ElecCompMapper(com.cas.sim.tis.mapper.ElecCompMapper) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ElecComp(com.cas.sim.tis.entity.ElecComp) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Aggregations

ElecComp (com.cas.sim.tis.entity.ElecComp)2 ElecCompMapper (com.cas.sim.tis.mapper.ElecCompMapper)2 HashMap (java.util.HashMap)1 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)1 Condition (tk.mybatis.mapper.entity.Condition)1 Criteria (tk.mybatis.mapper.entity.Example.Criteria)1