fengxiang
2018-01-26 60163c2fb5098fc522f8e80b131128d2c9a33e42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.moral.service.impl;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import com.github.pagehelper.PageHelper;
import com.moral.common.bean.Constants;
import com.moral.common.bean.PageBean;
import com.moral.common.util.ExampleUtil;
import com.moral.common.util.MyBatisBaseMapUtil;
import org.springframework.stereotype.Service;
 
import com.moral.common.util.ValidateUtil;
import com.moral.entity.MonitorPoint;
import com.moral.mapper.MonitorPointMapper;
import com.moral.service.MonitorPointService;
import tk.mybatis.mapper.entity.Example;
 
@Service
public class MonitorPointServiceImpl implements MonitorPointService {
    @Resource
    private MonitorPointMapper monitorPointMapper;
    private static Class ENTITY_CLASS = MonitorPoint.class;
    @Override
    public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("areaName"), "param.is.null");
        return monitorPointMapper.getMonitorPointsByAreaName(parameters);
    }
    @Override
    public List<MonitorPoint> queryWithStateByMap(Map<String, Object> params){
        return monitorPointMapper.selectWithStateByMap(params);
    }
    @Override
    public PageBean queryByPageBean(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
        List<Example.Criteria> criteriaList = example.getOredCriteria();
        if(criteriaList!=null&&criteriaList.size()>0){
            for(Example.Criteria cri : criteriaList){
                cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE);
            }
        }else {
            example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE);
        }
        PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
        List<MonitorPoint> monitorPointList = monitorPointMapper.selectWithAreaNameByExample(example);
        return new PageBean(monitorPointList);
    }
    @Override
   public MonitorPoint queryWithRelationById(Integer id){
         Example example = new Example(ENTITY_CLASS);
         example.or().andEqualTo("id",id);
         List<MonitorPoint> monitorPointList = monitorPointMapper.selectWithAreaNameByExample(example);
         return monitorPointList!=null&&monitorPointList.size()>0?monitorPointList.get(0):null;
    }
    @Override
    public void addOrModify(MonitorPoint monitorPoint) {
        try{
            if(monitorPoint.getId()==null){
                monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
                monitorPointMapper.insertSelective(monitorPoint);
            }else{
                monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
            }
        }
        catch (Exception ex){
            throw  ex;
        }
    }
 
    @Override
    public void deleteByIds(Integer... ids) {
        MonitorPoint monitorPoint = new MonitorPoint();
        monitorPoint.setIsDelete(Constants.IS_DELETE_TRUE);
        if(ids!=null&&ids.length>0){
            if(ids.length==1){
                monitorPoint.setId(ids[0]);
                monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
            }else{
                Example example = new Example(ENTITY_CLASS);
                example.or().andIn("id", Arrays.asList(ids));
                monitorPointMapper.updateByExampleSelective(monitorPoint,example);
            }
 
        }
    }
 
}