智慧保安后台管理-外网
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.information.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.alibaba.fastjson.JSON;
import org.springblade.common.cache.DictCache;
import org.springblade.common.config.FtpConfig;
import org.springblade.common.enums.DictEnum;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.FTP.OutJson;
import org.springblade.modules.information.entity.Information;
import org.springblade.modules.information.excel.ExportInformationExcel;
import org.springblade.modules.information.excel.ExportInformationSecurityStatistics;
import org.springblade.modules.information.excel.InforExcel;
import org.springblade.modules.information.excel.InforImporter;
import org.springblade.modules.information.service.IInformationService;
import org.springblade.modules.information.vo.InformationVO;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
 
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
 
 
/**
 * 控制器
 *
 * @author BladeX
 * @since 2021-07-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/information")
@Api(value = "", tags = "接口")
public class InformationController extends BladeController {
    //ftp服务器IP地址
    private static String ftpHost = "192.168.0.105";
    //ftp服务器端口
    private static int ftpPort = 21;
    //ftp服务器用户名
    private static String ftpUserName = "yly";
    //ftp服务器密码
    private static String ftpPassword = "Yly@123";
    //本地路径
    private static String localPath = "D:\\anbao";
 
    private final IInformationService informationService;
    private final IDeptService iDeptService;
 
 
    private final IUserService userService;
 
    private final IRoleService roleService;
 
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入information")
    public R<Information> detail(Information information) {
        Information detail = informationService.getOne(Condition.getQueryWrapper(information));
        return R.data(detail);
    }
 
    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入information")
    public R<IPage<Information>> list(Information information, Query query) {
        IPage<Information> pages = informationService.page(Condition.getPage(query), Condition.getQueryWrapper(information));
        return R.data(pages);
    }
 
    /**
     * 自定义分页
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入information")
    public R<IPage<InformationVO>> page(InformationVO information, Query query) {
        IPage<InformationVO> pages = informationService.selectInformationPage(Condition.getPage(query), information);
        return R.data(pages);
    }
 
 
    /**
     * 培训公司信息查询
     */
    @GetMapping("/security-page")
    public R<IPage<InformationVO>> securityPage(InformationVO information, Query query) {
        IPage<InformationVO> pages = informationService.securityPage(Condition.getPage(query), information);
        return R.data(pages);
    }
 
 
    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入information")
    public R save(@Valid @RequestBody Information information){
        Dept dept = new Dept();
        //自招保安公司
        if (information.getStats().equals("0")) {
            dept.setParentId(1420222768149966850L);
            dept.setAncestors("0,1420222768149966850");
        }
        //保安培训公司
        if (information.getStats().equals("1")) {
            dept.setParentId(1418458374477549569L);
            dept.setAncestors("0,1418458374477549569");
        }
        //保安服务公司
        if (information.getStats().equals("2")) {
            dept.setParentId(1413470343230877697L);
            dept.setAncestors("0,1413470343230877697");
        }
        //武装守押公司
        if (information.getStats().equals("3")) {
            dept.setParentId(1420222961377357825L);
            dept.setAncestors("0,1420222961377357825");
        }
        //跨区域保安公司
        if (information.getStats().equals("4")) {
            dept.setParentId(1425366663452196865L);
            dept.setAncestors("0,1425366663452196865");
        }
        dept.setTenantId("000000");
        dept.setDeptName(information.getEnterprisename());
        dept.setDeptCategory(1);
 
        if (iDeptService.submit(dept)) {
            CacheUtil.clear(SYS_CACHE);
            // 返回懒加载树更新节点所需字段
            Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId())
                .set("deptCategoryName", DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory()));
            String id = kv.get("id").toString();
            information.setDepartmentid(id);
        }
 
        information.setCreateTime(new Date());
 
        //公司新增
        boolean status = informationService.save(information);
 
        //公司新增成功则创建默认账户,公司名即为账号名,默认密码为 123456
        if (status) {
            User user = new User();
            user.setAccount(information.getEnterprisename());
            user.setPassword(DigestUtil.encrypt("123456"));
            Integer userCount = userService.selectCount(information.getEnterprisename());
            if (userCount > 0 && Func.isEmpty(user.getId())) {
                throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
            }
            user.setDeptId(information.getDepartmentid());
            user.setTenantId("000000");
            user.setCreateTime(new Date());
            user.setUpdateTime(new Date());
            user.setStatus(1);
            user.setIsDeleted(0);
            //分配保安角色
            //如果是本市保安公司,分公司,自招保安公司,分配保安公司管理员角色,如果是培训学校,则分配的是培训公司管理员角色
            Role role = new Role();
            if (information.getStats().equals("1")){
                role.setRoleAlias("培训公司管理员");
            }else {
                role.setRoleAlias("保安公司管理员");
            }
            Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
            user.setRoleId(oneRole.getId().toString());
            //插入用户数据
            userService.save(user);
 
            Integer isDeleted = 0;
            //Integer id = information.getId();
            String s = "insert into sys_information(id,creditCode,enterpriseName,representative" +
                        ",registeredCapital,organizationCode,registrationNumber, enterprises, address," +
                        " business,region,registration,industry,departmentid,stats,jurisdiction,representativecell," +
                        "contacts,contactscell,create_time,create_user_id) " +
                        "values(" + "'" + information.getId() + "'" +
                        "," + "'" + information.getCreditcode() + "'" +
                        "," + "'" + information.getEnterprisename() + "'" +
                        "," + "'" + information.getRepresentative() + "'" +
                        "," + "'" + information.getRegisteredcapital() + "'" +
                        "," + "'" + information.getOrganizationcode() + "'" +
                        "," + "'" + information.getRegistrationnumber() + "'" +
                        "," + "'" + information.getEnterprises() + "'" +
                        "," + "'" + information.getAddress() + "'" +
                        "," + "'" + information.getBusiness() + "'" +
                        "," + "'" + information.getRegion() + "'" +
                        "," + "'" + information.getRegistration() + "'" +
                        "," + "'" + information.getIndustry() + "'" +
                        "," + "'" + information.getDepartmentid() + "'" +
                        "," + "'" + information.getStats() + "'" +
                        "," + "'" + information.getJurisdiction() + "'" +
                        "," + "'" + information.getRepresentativecell() + "'" +
                        "," + "'" + information.getContacts() + "'" +
                        "," + "'" + information.getContactscell() + "'" +
                        "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(information.getCreateTime()) + "'" +
                        "," + "'" + information.getCreateUserId() + "'" + ");" +
                        "insert into blade_dept(id,parent_id,tenant_id,dept_name,ancestors,dept_category,is_deleted) values(" + "'" + information.getDepartmentid() + "'" + "," + "'" + dept.getParentId() + "'" + ","
                        + "'" + dept.getTenantId() + "'" +
                        "," + "'" + information.getEnterprisename() + "'" +
                        "," + "'" + dept.getAncestors() + "'" +
                        "," + "'" + dept.getDeptCategory() + "'" +
                        "," + "'" + isDeleted + "'" + ");" +
                        "insert into blade_user(id,tenant_id,account,password,role_id,dept_id,create_time,update_time,status,is_deleted) " +
                        "values(" + "'" + user.getId() + "'" +
                        "," + "'" + user.getTenantId() + "'"
                        + "," + "'" + user.getAccount() + "'" +
                        "," + "'" + user.getPassword() + "'" +
                        "," + "'" + user.getRoleId() + "'" +
                        "," + "'" + user.getDeptId() + "'" +
                        "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" +
                        "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
                        "," + "'" + user.getStatus() + "'" +
                        "," + "'" + user.getIsDeleted() + "'" + ")";
            FtpUtil.sqlFileUpload(s);
        }
        return R.success("成功");
    }
 
    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入information")
    public R update(@Valid @RequestBody Information information) throws Exception {
        informationService.updateById(information);
        String businessLicense = null;
        String businessLicenses = null;
        String licence = null;
        String licences = null;
        String format = "";
        if (information.getBusinessLicense() != null && !"".equals(information.getBusinessLicense())) {
            businessLicense = information.getBusinessLicense().substring(26, information.getBusinessLicense().length());
            businessLicenses = FtpConfig.ip + businessLicense;
        } else {
            businessLicenses = "";
        }
        if (information.getLicence() != null && !"".equals(information.getLicence())) {
            licence = information.getLicence().substring(26, information.getLicence().length());
            licences = FtpConfig.ip + licence;
        } else {
            licences = "";
        }
        if (information.getEstablishtime() != null && !"".equals(information.getEstablishtime())) {
            format = new SimpleDateFormat("yyyy-MM-dd").format(information.getEstablishtime());
        }
        //内网同步
        String s1 = "update sys_information set creditCode = " + "'" + information.getCreditcode() + "'" +
            ",enterpriseName = " + "'" + information.getEnterprisename() + "'" +
            ",representative = " + "'" + information.getRepresentative() + "'" +
            ",establishTime = " + "'" + format + "'" +
            ",registeredCapital = " + "'" + information.getRegisteredcapital() + "'" +
            ",jurisdiction = " + "'" + information.getJurisdiction() + "'" +
            ",enterprises = " + "'" + information.getEnterprises() + "'" +
            ",address = " + "'" + information.getAddress() + "'" +
            ",business = " + "'" + information.getBusiness() + "'" +
            ",region = " + "'" + information.getRegion() + "'" +
            ",registration = " + "'" + information.getRegistration() + "'" +
            ",industry = " + "'" + information.getIndustry() + "'" +
            ",departmentid = " + "'" + information.getDepartmentid() + "'" +
            ",stats = " + "'" + information.getStats() + "'" +
            ",representativecell = " + "'" + information.getRepresentativecell() + "'" +
            ",contacts = " + "'" + information.getContacts() + "'" +
            ",contactscell = " + "'" + information.getContactscell() + "'" +
            ",business_License = " + "'" + businessLicenses + "'" +
            ",licence = " + "'" + licences + "'" +
            " " + "where id = " + "'" + information.getId() + "'";
        FtpUtil.sqlFileUpload(s1);
        return R.success("修改成功");
    }
 
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入information")
    public R submit(@Valid @RequestBody Information information) {
        return R.status(informationService.saveOrUpdate(information));
    }
 
 
    /**
     * 删除
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(String creditcode, String departmentid) throws Exception {
        List<String> list = Arrays.asList(departmentid.split(","));
        list.forEach(s -> {
            //公司信息删除
            informationService.deleteIn(s);
            //主要管理人员信息删除
            informationService.deleteSh(s);
            //出资人信息删除
            informationService.deleteMe(s);
            //机构删除
            informationService.deleteDept(s);
            //当前公司下人员逻辑删除
              informationService.deleteUserByDeptId(s);
            //保安公司信息
            String s1 = "delete from sys_information where departmentid = " + "'" + s + "'";
            FtpUtil.sqlFileUpload(s1);
            //主要管理人
            String s2 = "delete from sys_shareholder where dept_id = " + "'" + s + "'";
            FtpUtil.sqlFileUpload(s2);
            //出资人
            String s3 = "delete from sys_member where dept_id = " + "'" + s + "'";
            FtpUtil.sqlFileUpload(s3);
            //组织机构信息逻辑删除
            String s4 = "update blade_dept set is_deleted  = 1 where id = " + "'" + s + "'";
            FtpUtil.sqlFileUpload(s4);
            //保安公司人员信息删除
            String s5 = "update blade_user set is_deleted  = 1 where dept_id " + "'" + s + "'";
            FtpUtil.sqlFileUpload(s5);
        });
        //返回
        return R.success("删除成功");
    }
 
    /**
     * 统计保安员资格异常的数量
     */
    @PostMapping("/selectExtype")
    public R selectExtype(String deptid, String jurisdiction) {
        List<Map<Object, Object>> lists = informationService.selectExtype(deptid, jurisdiction);
        return R.data(lists);
    }
 
    /**
     * 统计保安员持证的数量
     */
    @PostMapping("/selectHold")
    public R selectHold(String deptid, String jurisdiction) {
        List<Map<Object, Object>> lists = informationService.selectHold(deptid, jurisdiction);
        return R.data(lists);
    }
 
    /**
     * 派遣服务单位统计
     */
    @PostMapping("/selectDis")
    public R selectDis(String deptid) {
        List<Map<Object, Object>> lists = informationService.selectDis(deptid);
        return R.data(lists);
    }
 
    /**
     * 保安派遣数量统计
     */
    @PostMapping("/selectDisp")
    public R selectDisp(String deptid, String jurisdiction) {
        List<Map<Object, Object>> lists = informationService.selectDisp(deptid, jurisdiction);
        return R.data(lists);
    }
 
    /**
     * 社保统计
     */
    @PostMapping("/selectSoil")
    public R selectSoil(String deptid, String jurisdiction) {
        List<Map<Object, Object>> lists = informationService.selectSoil(deptid, jurisdiction);
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < lists.size(); i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String numj = lists.get(i).get("numj").toString();
            Integer a = Integer.valueOf(numj);
            String numz = lists.get(i).get("numz").toString();
            Integer b = Integer.valueOf(numz);
            //Integer c = b - a;
            map.put("numj", a);
            map.put("nmuwj", b);
            list.add(map);
        }
        return R.data(list);
    }
 
    /**
     * 导入单位信息
     */
    @PostMapping("import-informaton")
    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "导入单位", notes = "传入excel")
    public R importUser(MultipartFile file, Integer isCovered) {
        InforImporter inforImporter = new InforImporter(informationService, false);
        ExcelUtil.save(file, inforImporter, InforExcel.class);
        return R.success("操作成功");
    }
 
    /**
     * 查询本年所有月份的客户数量
     *
     * @return
     */
    @PostMapping("/queryYearKh")
    public List queryYearKh(String jurisdiction, String deptid) {
        Calendar cal = Calendar.getInstance();
        String year = String.valueOf(cal.get(Calendar.YEAR));
        List list = informationService.queryYearKh(year, jurisdiction, deptid);
        return list;
    }
 
    //升序
    public static Map<String, String> sortMapBykeyAsc(Map<String, String> oriMap) {
        Map<String, String> sortedMap = new LinkedHashMap<String, String>();
        try {
            if (oriMap != null && !oriMap.isEmpty()) {
                List<Map.Entry<String, String>> entryList = new ArrayList<Map.Entry<String, String>>(oriMap.entrySet());
                Collections.sort(entryList,
                    new Comparator<Map.Entry<String, String>>() {
                        public int compare(Map.Entry<String, String> entry2,
                                           Map.Entry<String, String> entry1) {
                            int value2 = 0, value1 = 0;
                            try {
                                value2 = Integer.parseInt(entry1.getKey());
                                value1 = Integer.parseInt(entry2.getKey());
                            } catch (NumberFormatException e) {
                                value2 = 0;
                                value1 = 0;
                            }
                            return value1 - value2;
                        }
                    });
                Iterator<Map.Entry<String, String>> iter = entryList.iterator();
                Map.Entry<String, String> tmpEntry = null;
                while (iter.hasNext()) {
                    tmpEntry = iter.next();
                    sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
                }
            }
        } catch (Exception e) {
        }
        return sortedMap;
    }
 
    /**
     * 业务统计情况
     */
    @GetMapping("/selectBusinessStatistics")
    public R<IPage> selectBusinessStatistics(InformationVO information, Query query) {
        IPage list = informationService.selectBusinessStatistics(Condition.getPage(query), information);
        return R.data(list);
    }
 
    /**
     * 保安员情况统计
     */
    @GetMapping("/selectSecurityStatistics")
    public R<IPage> selectSecurityStatistics(InformationVO information, Query query) {
        IPage list = informationService.selectSecurityStatistics(Condition.getPage(query), information);
        return R.data(list);
    }
 
    /**
     * 业务统计情况导出
     */
    @GetMapping("/export-business-statis")
    public void exportBusinessStatis(HttpServletResponse response, InformationVO information) {
        List<ExportInformationExcel> list= informationService.exportBusinessStatis(information);
        ExcelUtil.export(response, "业务统计数据" + DateUtil.time(), "业务统计数据表", list, ExportInformationExcel.class);
    }
 
    /**
     * 保安员情况统计导出
     */
    @GetMapping("/export-security-statis-info")
    public void exportSecurityStatisInfo(HttpServletResponse response,InformationVO information) {
        List<ExportInformationSecurityStatistics> list = informationService.exportSecurityStatisInfo(information);
        ExcelUtil.export(response, "保安员统计数据" + DateUtil.time(), "保安员统计数据表", list, ExportInformationSecurityStatistics.class);
    }
 
    /**
     * 保安员详情
     */
    @PostMapping("/selectUIn")
    public R<IPage> selectUIn(String deptid, String name, String hold, String photo, String examinationtype, String dispatch, String soil, Query query) {
        IPage list = informationService.selectUIn(Condition.getPage(query), deptid, name, hold, photo, examinationtype, dispatch, soil);
        return R.data(list);
    }
 
}