mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package com.sinata.modular.system.controller;
 
import com.sinata.common.enums.EnumIsDelete;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import com.sinata.modular.member.model.MemMerchant;
import com.sinata.modular.member.service.IMemMerchantService;
import com.sinata.modular.system.model.AreaCity;
import com.sinata.modular.system.service.IAreaCityService;
import com.sinata.modular.system.service.RedisTemplateService;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.sinata.core.common.constant.factory.PageFactory;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sinata.core.common.annotion.BussinessLog;
import com.sinata.core.common.annotion.Permission;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinata.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.sinata.modular.system.model.MyDoctor;
import com.sinata.modular.system.service.IMyDoctorService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.springframework.util.StringUtils;
 
import javax.servlet.http.HttpServletResponse;
 
/**
 * 美牙医生控制器
 * @author goku
 */
@Controller
@RequestMapping("/myDoctor")
public class MyDoctorController extends BaseController {
 
    private String PREFIX = "/system/myDoctor/";
 
    @Autowired
    private IMyDoctorService myDoctorService;
 
    @Autowired
    private IMemMerchantService merchantService;
 
    @Autowired
    private RedisTemplateService redis;
 
    @Autowired
    private IAreaCityService areaCityService;
 
    /**
     * 跳转到美牙医生首页
     */
    @RequestMapping("")
    public String index(Model model) {
        Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
        wrapper2.eq("is_open",1);
        wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
        model.addAttribute("cityAreaList",areaCityService.selectList(wrapper2));
        return PREFIX + "myDoctor.html";
    }
 
    /**
     * 跳转到添加美牙医生
     */
    @RequestMapping("/myDoctor_add")
    public String myDoctorAdd(Model model) {
        Page<MemMerchant> page = new PageFactory().defaultPage(999999,0);
        // 查询数据列表
        List<MemMerchant> list = merchantService.queryMerchantList(page, null, null, null, null, null, null);
        model.addAttribute("merchantList",list);
        Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
        wrapper2.eq("is_open",1);
        wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
        model.addAttribute("cityAreaList",areaCityService.selectList(wrapper2));
        return PREFIX + "myDoctor_add.html";
    }
 
    /**
     * 跳转到修改美牙医生
     */
    @RequestMapping("/myDoctor_update/{myDoctorId}")
    public String myDoctorUpdate(@PathVariable Integer myDoctorId, Model model) {
        Page<MemMerchant> page = new PageFactory().defaultPage(999999,0);
        // 查询数据列表
        List<MemMerchant> list = merchantService.queryMerchantList(page, null,  null, null,  null, null, null);
        model.addAttribute("merchantList",list);
        MyDoctor myDoctor = myDoctorService.selectById(myDoctorId);
        model.addAttribute("item",myDoctor);
        Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
        wrapper2.eq("is_open",1);
        wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
        model.addAttribute("cityAreaList",areaCityService.selectList(wrapper2));
        LogObjectHolder.me().set(myDoctor);
        return PREFIX + "myDoctor_edit.html";
    }
 
    /**
     * 获取美牙医生列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String condition,Integer cityId,Integer sex,Integer workTime) {
        Page<MyDoctor> page = new PageFactory().defaultPage();
 
        // 时间搜索
        if(!StringUtils.isEmpty(beginTime)) {
            beginTime  = beginTime + " 00:00:00";
        }
        if(!StringUtils.isEmpty(endTime)) {
            endTime = endTime + " 23:59:59";
        }
 
        // 查询数据列表
        List<MyDoctor> list = myDoctorService.queryMyDoctorList( beginTime,  endTime,  condition, cityId, sex, workTime,page);
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    /**
     * 新增美牙医生
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "新增美牙医生")
    @RequestMapping(value = "/add")
    public Object add(MyDoctor myDoctor) {
        myDoctorService.insert(myDoctor);
        return SUCCESS_TIP;
    }
    /**
     * 删除/批量删除
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "删除/批量删除美牙医生")
    @RequestMapping(value = "/delete")
    public Object delete(@RequestParam String ids) {
        // 逻辑删除
        myDoctorService.updateForSet("is_delete = 1", new EntityWrapper<MyDoctor>().in("id", ids.split(",")));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改美牙医生
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "修改美牙医生")
    @RequestMapping(value = "/update")
    public Object update(MyDoctor myDoctor) {
        myDoctorService.updateById(myDoctor);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改美牙医生状态
     */
    @ResponseBody
    @BussinessLog(value = "修改美牙医生状态")
    @RequestMapping(value = "/updateState")
    public Object updateState(Integer myDoctorId, Integer state) {
        myDoctorService.updateForSet("state = " + state, new EntityWrapper<MyDoctor>().eq("id", myDoctorId));
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转美牙医生详情
     */
    @RequestMapping(value = "/detail/{myDoctorId}")
    public Object detail(@PathVariable("myDoctorId") Integer myDoctorId, Model model) {
        Page<MemMerchant> page = new PageFactory().defaultPage(999999,0);
        // 查询数据列表
        List<MemMerchant> list = merchantService.queryMerchantList(page,null,  null, null, null, null, null);
        model.addAttribute("merchantList",list);
        MyDoctor myDoctor = myDoctorService.selectById(myDoctorId);
        model.addAttribute("item",myDoctor);
        Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
        wrapper2.eq("is_open",1);
        wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
        model.addAttribute("cityAreaList",areaCityService.selectList(wrapper2));
        LogObjectHolder.me().set(myDoctor);
        return PREFIX + "myDoctor_detail.html";
    }
 
    @RequestMapping(value = "/export")
    @ResponseBody
    public Object export(String beginTime, String endTime, String condition,Integer cityId,Integer sex,Integer workTime,HttpServletResponse response) {
        Page<MyDoctor> page = new PageFactory().defaultPage(999999,0);
 
        // 时间搜索
        if(!StringUtils.isEmpty(beginTime)) {
            beginTime  = beginTime + " 00:00:00";
        }
        if(!StringUtils.isEmpty(endTime)) {
            endTime = endTime + " 23:59:59";
        }
 
        // 查询数据列表
        List<MyDoctor> list = myDoctorService.queryMyDoctorList( beginTime,  endTime,  condition, cityId, sex, workTime,page);
 
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("添加时间");
        shellList.add("医生头像");
        shellList.add("医生名称");
        shellList.add("所在城市");
        shellList.add("所在门店");
        shellList.add("入职时间");
        shellList.add("性别");
        shellList.add("联系电话");
        shellList.add("职级");
        shellList.add("擅长领域");
        shellList.add("个人介绍");
        shellList.add("从业年限");
        dataList.add(shellList);
 
        // 详细数据列【封装】
        for (MyDoctor map : list) {
            shellList = new ArrayList<>();
            shellList.add(DateUtils2.getTime(map.getCreateTime()));
            shellList.add( map.getAvatar());
            shellList.add( map.getName());
            shellList.add( map.getCityName());
            shellList.add( map.getMerchantName());
            shellList.add(DateUtils2.getTime(map.getJoinTime()));
            shellList.add( map.getSex().equals("1")?"男":"女");
            shellList.add( map.getPhone());
            shellList.add( map.getPosition());
            shellList.add( map.getTechnique());
            shellList.add( map.getRemark());
            shellList.add( map.getWorkTimeNum());
            dataList.add( shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("导出数据"+ DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    @RequestMapping(value = "/title/image")
    public Object titleImage( Model model) {
        Object doctor_title_image = "";
        try {
            doctor_title_image = redis.get("DOCTOR_TITLE_IMAGE");
        } catch (Exception e) {
            e.printStackTrace();
        }
        model.addAttribute("item", doctor_title_image);
        return PREFIX + "myDoctorImage.html";
    }
 
    @RequestMapping(value = "/set/title/image")
    @ResponseBody
    public Object setTitleImage(String image) {
        redis.set("DOCTOR_TITLE_IMAGE",image);
        return SUCCESS_TIP;
    }
}