forked from kidgrow-microservices-platform

luliqiang
2020-12-28 f41b3b53dad6a8468fc1ae9babb85a0270124d01
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
package com.kidgrow.oprationcenter.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kidgrow.common.model.PageResult;
import com.kidgrow.common.model.ResultBody;
import com.kidgrow.common.model.SysDoctor;
import com.kidgrow.common.model.SysUser;
import com.kidgrow.common.service.impl.SuperServiceImpl;
import com.kidgrow.oprationcenter.mapper.DataNeedMapper;
import com.kidgrow.oprationcenter.model.DataNeed;
import com.kidgrow.oprationcenter.service.IDataNeedService;
import com.kidgrow.oprationcenter.vo.DataNeedExcel;
import com.kidgrow.usercenter.feign.SysDoctorService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 * @Description: 医生的数据需求<br>
 * @Project: 用户中心<br>
 * @CreateDate: Created in 2020-04-01 09:37:04 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 * @version 1.0
 */
@Slf4j
@Service
public class DataNeedServiceImpl extends SuperServiceImpl<DataNeedMapper, DataNeed> implements IDataNeedService {
    @Autowired
    private SysDoctorService sysDoctorService;
    /**
     * 列表
     * @param params
     * @return
     */
    @Override
    public PageResult<DataNeed> findList(Map<String, Object> params){
        Page<DataNeed> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
        List<DataNeed> list  =  baseMapper.findList(page, params);
        return PageResult.<DataNeed>builder().data(list).code(0).count(page.getTotal()).build();
    }
 
    /**
   * 根据DataNeed对象当做查询条件进行查询
   * @param dataNeed
   * @return DataNeed
   */
    @Override
    public DataNeed findByObject(DataNeed dataNeed){
        return baseMapper.findByObject(dataNeed);
    }
 
    @Override
    public List<DataNeedExcel> findListExportByParam(Map<String, Object> params) {
        QueryWrapper queryWrapper=new QueryWrapper();
        String doctor_name = MapUtils.getString(params, "doctor_name");
        if(doctor_name!=null){
            queryWrapper.like("doctor_name","%"+doctor_name+"%");
        }
        String need_begintime = MapUtils.getString(params, "need_begintime");
        if(need_begintime!=null){
            queryWrapper.gt("need_begintime",need_begintime);
        }
        String need_endtime = MapUtils.getString(params, "need_endtime");
        if(need_endtime!=null){
            queryWrapper.gt("need_endtime",need_endtime);
        }
        queryWrapper.eq("is_del",0);
        List<DataNeed> dataNeeds = baseMapper.selectList(queryWrapper);
        List<DataNeedExcel> voList=new ArrayList<>();
        dataNeeds.forEach(e ->{
            DataNeedExcel vo=new DataNeedExcel();
            BeanCopier beanCopier = BeanCopier.create(DataNeed.class, DataNeedExcel.class, false);
            beanCopier.copy(e,vo,null);
            voList.add(vo);
        });
        return voList;
    }
 
    @Override
    public ResultBody updateEnabled(Map<String, Object> map) {
        Long id = MapUtils.getLong(map, "id");
        if(id==null){
            return ResultBody.failed("请选择一条数据");
        }else {
            DataNeed dataNeed = baseMapper.selectById(id);
            if (dataNeed != null) {
                Boolean enabled = MapUtils.getBoolean(map, "enabled");
                String dataFile = MapUtils.getString(map, "dataFile");
                dataNeed.setDataFile(dataFile);
                dataNeed.setEnabled(enabled);
                baseMapper.updateById(dataNeed);
            }else {
                return ResultBody.failed("查找数据失败");
            }
            return ResultBody.ok();
        }
    }
    @Override
    public ResultBody updateDelete(Long id,SysUser sysUser) {
        if(id==null){
            return ResultBody.failed("请选择一条数据");
        }else {
            DataNeed dataNeed = baseMapper.selectById(id);
            if (dataNeed != null) {
                dataNeed.setIsDel(true);
                dataNeed.setUpdateTime(new Date());
                dataNeed.setUpdateUserId(sysUser.getId());
                dataNeed.setUpdateUserName(sysUser.getUsername());
                int u=baseMapper.updateById(dataNeed);
                return ResultBody.ok().data(u>0);
            }else {
                return ResultBody.failed("查找数据失败");
            }
        }
    }
 
    @Override
    public ResultBody FindAllByHId(Map<String, Object> map, SysUser sysUser) {
            Map<String,Object> doctoerMap =new HashMap<>();
            doctoerMap.put("user_id",sysUser.getId());
            ResultBody listByMap = sysDoctorService.getListByMap(doctoerMap);
            List<SysDoctor> sysDoctors = JSON.parseArray(JSON.toJSONString(listByMap.getData()), SysDoctor.class);
            if (sysDoctors!=null&&sysDoctors.size()>0){
                Page<DataNeed> page = new Page<>(MapUtils.getInteger(map, "page"), MapUtils.getInteger(map, "limit"));
//                List<DataNeed> dataNeedList=baseMapper.findHList(map);
                List<DataNeed> list  =  baseMapper.findList(page, map);
                PageResult<DataNeed> build = PageResult.<DataNeed>builder().data(list).code(0).count(page.getTotal()).build();
                return ResultBody.ok().data(build);
            }else {
                return ResultBody.failed("非管理用户无权查看");
            }
    }
}