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
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.user.dao.BbFaceDao;
import com.cloud.user.model.BbFace;
import com.cloud.user.service.BbFaceService;
import com.cloud.user.service.TokenService;
import com.cloud.user.vo.BbFaceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 人脸特征
 * 业务层
 */
@Service
public class BbFaceServiceImpl implements BbFaceService {
    
    @Autowired
    private BbFaceDao dao;
 
    @Autowired
    private TokenService tokenService;
 
    /**
     * 根据主键查询
     * @param orgId
     */
    public BbFace findById(Long id, Long orgId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        if (orgId != null && !"".equals(orgId)) {
            params.put("orgId", orgId);
        }
        return dao.findById(params);
    }
    
    /**
     * 根据主键删除
     * @param orgId
     */
    public Integer deleteById(Long id, Long orgId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        if (orgId != null && !"".equals(orgId)) {
            params.put("orgId", orgId);
        }
        return dao.deleteById(params);
    }
    
    /**
     * 添加, 没有业务
     */
    public BbFace add(BbFace bean) {
        bean.preInsert(tokenService.currentUser());
        // 设置创建属性
 
        dao.save(bean);
        return bean;
    }
 
    /**
     * 编辑, 没有业务
     */
    public BbFace update(BbFace bean) {
        bean.preUpdate(tokenService.currentUser());
        // 查找要编辑的数据库实体
        BbFace dbBean = findById(bean.getId(), bean.getOrgId());
        if (dbBean != null) {
 
            // 设置要修改的属性
            dbBean.setResourceId(bean.getResourceId());                 //关联人Id(eployeeid
            dbBean.setFeature(bean.getFeature());                       //人脸特征
            
            dao.update(dbBean);
            return dbBean;
        } else {
            return null;
        }
    }
 
    
    /**
     * 添加,包含业务
     */
    public BbFace addBbFace(BbFaceVO beanVO) {
        add(beanVO);
        return beanVO;
    }
 
    /**
     * 编辑,包含业务
     */
    public BbFace updateBbFace(BbFaceVO beanVO) {
        // 查找要编辑的数据库实体
        BbFace dbBean = findById(beanVO.getId(), beanVO.getOrgId());
        if (dbBean != null) {
            // 设置要修改的属性
            dbBean.setResourceId(beanVO.getResourceId());               //关联人Id(eployeeid
            dbBean.setFeature(beanVO.getFeature());                     //人脸特征
            update(dbBean);
            return dbBean;
        } else {
            return null;
        }
    }
 
    /**
     * 去编辑,包含业务
     */
    public BbFace toUpdateBbFace(Long id, Long orgId) {
        // 查找要编辑的数据库实体
        BbFace dbBean = findById(id, orgId);
        return dbBean;
    }
 
    /**
     * 分页查询
     */
    public Page<BbFace> findBbFaces(Map<String, Object> params) {
        params.put("orgId", tokenService.currentUser().getOrgId()+"");
        int total = dao.count(params);
        List<BbFace> list = Collections.emptyList();
        if (total > 0) {
            PageUtil.pageParamConver(params, true);
 
            list = dao.findData(params);
        }
        return new Page<>(total, list);
    }
 
    /**
     * 根据人脸ID获取人员Id
     * @param params
     * @return
     */
    public Map<String, Object> findEmpIdByFaceId(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<>();
        List<Integer> empIds = dao.findEmpIdByFaceId(params);
        if(empIds.size() > 0){
            map.put("total",empIds.size());
            map.put("data",empIds);
            return map;
        }
        map.put("提示","暂无数据!");
        return map;
    }
}