liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.cloud.user.service.impl;
 
//import com.cloud.common.utils.AppUserUtil;
import com.cloud.common.utils.PageUtil;
import com.cloud.model.common.Page;
import com.cloud.model.sys.BbEmployeeRelation;
import com.cloud.user.dao.BbEmployeeRelationDao;
import com.cloud.user.service.BbEmployeeRelationService;
import com.cloud.user.service.TokenService;
import com.cloud.user.vo.BbEmployeeRelationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 人员关系表
 * 业务层
 */
@Service
public class BbEmployeeRelationServiceImpl implements BbEmployeeRelationService {
    
    @Autowired
    private BbEmployeeRelationDao dao;
 
    @Autowired
    private TokenService tokenService;
    /**
     * 根据主键查询
     * @param id
     * @param orgId
     */
    public BbEmployeeRelation findById(Long id, Long orgId) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        if (orgId != null && !"".equals(orgId.toString())) {
            params.put("orgId", orgId);
        }
        return dao.findById(params);
    }
    
    /**
     * 根据主键删除
     * @param params
     * @param orgId
     */
    public Integer deleteById(Map<String, Object> params, String orgId) {
        if (orgId != null && !"".equals(orgId)) {
            params.put("orgId", orgId);
        }
        return dao.deleteById(params);
    }
    
    /**
     * 添加, 没有业务
     */
    public Integer add(BbEmployeeRelation bean) {
 
        // 设置创建属性
        bean.preInsert(tokenService.currentUser());                                   //逻辑删除标记(0
        bean.setDelFlag("0");
        return dao.add(bean);
    }
 
    /**
     * 编辑, 没有业务
     */
    public BbEmployeeRelation update(BbEmployeeRelation bean) {
        // 查找要编辑的数据库实体
        BbEmployeeRelation dbBean = null;// findById(bean.getId(), bean.getOrgId());
        
        // 设置要修改的属性
        dbBean.setEmployeeId(bean.getEmployeeId());                 //被关联人Id
        dbBean.setRelationoId(bean.getRelationoId());               //关联人Id
        dbBean.setRelation(bean.getRelation());                     //家属关系
        dbBean.setRemarks(bean.getRemarks());                       //备注信息
        dbBean.setRevJson1(bean.getRevJson1());                     //预留json格式字段1
        
        dao.update(dbBean);
        return dbBean;
    }
 
    
    /**
     * 添加,包含业务
     */
    @Transactional
    public Map<String,Object> addBbEmployeeRelation(List<BbEmployeeRelationVO> beanVOs) {
        Map<String,Object> map = new HashMap<>();
        for(BbEmployeeRelation bbEmployeeRelation:beanVOs){
            Integer status = add(bbEmployeeRelation);
            if(status == 0){
                map.put("code","1");
                map.put("message","保存失败!");
                return map;
            }
        }
        map.put("code","0");
        map.put("message","保存成功!");
        return map;
    }
 
    /**
     * 编辑,包含业务
     */
    public Map<String,Object> updateBbEmployeeRelation(BbEmployeeRelationVO beanVO) {
        // 查找要编辑的数据库实体
        BbEmployeeRelation dbBean = null;//findById(beanVO.getId(), beanVO.getOrgId());
        
        // 设置要修改的属性
        dbBean.setEmployeeId(beanVO.getEmployeeId());               //被关联人Id
        dbBean.setRelationoId(beanVO.getRelationoId());             //关联人Id
        dbBean.setRelation(beanVO.getRelation());                   //家属关系
        dbBean.setRemarks(beanVO.getRemarks());                     //备注信息
        dbBean.setRevJson1(beanVO.getRevJson1());                   //预留json格式字段1
 
        dao.update(dbBean);
        return null;
    }
 
    /**
     * 去编辑,包含业务
     */
    public BbEmployeeRelation toUpdateBbEmployeeRelation(BbEmployeeRelationVO beanVO) {
        // 查找要编辑的数据库实体
        BbEmployeeRelation dbBean = null;// findById(beanVO.getId(), beanVO.getOrgId());
        return dbBean;
    }
 
    /**
     * 分页查询
     */
    public Page<BbEmployeeRelation> findBbEmployeeRelations(Map<String, Object> params) {
        params.put("orgId", tokenService.currentUser().getOrgId()+"");
        int total = dao.count(params);
        List<BbEmployeeRelation> list = Collections.emptyList();
        if (total > 0) {
            PageUtil.pageParamConver(params, true);
 
            list = dao.findData(params);
        }
        return new Page<>(total, list);
    }
 
    @Override
    public Map<String, Object> findRelationById(Map<String, Object> params) {
        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> data = dao.findRelationById(params);
        if(data.size()>0){
            map.put("code","0");
            map.put("data",data);
            map.put("message","查询成功!");
        }else {
            map.put("code","1");
            map.put("data","");
            map.put("message","查询失败!");
        }
        return map;
    }
 
}