智慧保安后台管理-外网项目备份
Administrator
2021-11-29 d23d3a11db4df64fda1100791f3421a5c14e18f4
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
/*
 *      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.dispatcher.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.dispatcher.entity.Dispatcher;
import org.springblade.modules.dispatcher.entity.DispatcherUnit;
import org.springblade.modules.dispatcher.excel.DispatcherUnitExcel;
import org.springblade.modules.dispatcher.mapper.DispatcherMapper;
import org.springblade.modules.dispatcher.mapper.DispatcherUnitMapper;
import org.springblade.modules.dispatcher.service.IDispatcherService;
import org.springblade.modules.dispatcher.service.IDispatcherUnitService;
import org.springblade.modules.dispatcher.vo.DispatcherUnitVO;
import org.springblade.modules.dispatcher.vo.DispatcherVO;
import org.springblade.modules.system.service.IUserDeptService;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/**
 *  服务实现类
 *
 * @author BladeX
 * @since 2021-07-07
 */
@Service
@AllArgsConstructor
public class DispatcherUnitServiceImpl extends ServiceImpl<DispatcherUnitMapper, DispatcherUnit> implements IDispatcherUnitService {
 
 
    private final IDispatcherService dispatcherService;
 
    private final IUserDeptService userDeptService;
 
    @Override
    public IPage<DispatcherUnitVO> selectDispatcherUnitPage(IPage<DispatcherUnitVO> page, DispatcherUnitVO dispatcherUnitVO) {
        List<DispatcherUnitVO> dispatcherUnitVOS = baseMapper.selectDispatcherUnitPage(page, dispatcherUnitVO);
//        dispatcherUnitVOS.forEach(dispatcherUnitVO1 -> {
//            //查询派遣记录条数
//            dispatcherUnitVO1.setNum(dispatcherService.getDispatcherCount(dispatcherUnitVO1));
//        });
        return page.setRecords(dispatcherUnitVOS);
    }
 
    /**
     * 派遣公司信息详情
     * @param dispatcherUnit 派遣信息对象
     * @return
     */
    @Override
    public DispatcherUnitVO selectDispatcherUnitInfo(DispatcherUnit dispatcherUnit) {
        return baseMapper.selectDispatcherUnitInfo(dispatcherUnit);
    }
 
    /**
     * 自定义树
     * @param dispatcher
     * @return
     */
    @Override
    public List<DispatcherUnitVO> selectDispatcherUnitPageTree(DispatcherUnitVO dispatcher) {
        return baseMapper.selectDispatcherUnitPageTree(dispatcher);
    }
 
    /**
     * 派遣导入
     * @param data
     * @param isCovered
     */
    @Override
    public void importDispatcherUnit(List<DispatcherUnitExcel> data, Boolean isCovered) {
        //派遣数据导入
        data.forEach(dispatcherUnitExcel -> {
            //派遣单位
            DispatcherUnit dispatcherUnit = new DispatcherUnit();
            //数据获取
            if (dispatcherUnitExcel.getDeptName()!=null && dispatcherUnitExcel.getDeptName()!=""){
                String deptId = userDeptService.selectIn(dispatcherUnitExcel.getDeptName());
                dispatcherUnit.setDeptId(Long.parseLong(deptId));
            }
 
            if (dispatcherUnitExcel.getName()!=null && dispatcherUnitExcel.getName()!=""){
                //仅中文
//                String chinese = "^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$";
//                Pattern compile = Pattern.compile(chinese);
//                String name = compile.matcher(dispatcherUnitExcel.getName()).replaceAll("");
                dispatcherUnit.setName(dispatcherUnitExcel.getName());
            }
 
            if (dispatcherUnitExcel.getLinkman()!=null && dispatcherUnitExcel.getLinkman()!=""){
                dispatcherUnit.setLinkman(dispatcherUnitExcel.getLinkman());
            }
 
            if (dispatcherUnitExcel.getPhone()!=null && dispatcherUnitExcel.getPhone()!=""){
                dispatcherUnit.setPhone(dispatcherUnitExcel.getPhone());
            }
 
            if (dispatcherUnitExcel.getSecurityLinkman()!=null && dispatcherUnitExcel.getSecurityLinkman()!=""){
                dispatcherUnit.setSecurityLinkman(dispatcherUnitExcel.getSecurityLinkman());
            }
 
            if (dispatcherUnitExcel.getCell()!=null && dispatcherUnitExcel.getCell()!=""){
                dispatcherUnit.setCell(dispatcherUnitExcel.getCell());
            }
 
            if (dispatcherUnitExcel.getServeType()!=null && dispatcherUnitExcel.getServeType()!=""){
                dispatcherUnit.setServeType(dispatcherUnitExcel.getServeType());
            }
 
            if (dispatcherUnitExcel.getNum()!=null){
                dispatcherUnit.setNum(dispatcherUnitExcel.getNum());
            }
 
            dispatcherUnit.setStartTime(dispatcherUnitExcel.getStartTime());
            dispatcherUnit.setEndTime(dispatcherUnitExcel.getEndTime());
 
//            if (dispatcherUnitExcel.getStartTime()!=null){
//                String year = dispatcherUnitExcel.getStartTime().substring(0, 4);
//                String month = dispatcherUnitExcel.getStartTime().substring(4, 6);
//                String day = dispatcherUnitExcel.getStartTime().substring(6, 8);
//                String dateFormat = year + "-" +month+"-" +day;
//                try {
//                    Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateFormat);
//                    dispatcherUnit.setStartTime(date);
//                } catch (ParseException e) {
//                    e.printStackTrace();
//                }
//            }
//
//            if (dispatcherUnitExcel.getEndTime()!=null){
//                String year = dispatcherUnitExcel.getEndTime().substring(0, 4);
//                String month = dispatcherUnitExcel.getEndTime().substring(4, 6);
//                String day = dispatcherUnitExcel.getEndTime().substring(6, 8);
//                String dateFormat = year + "-" +month+"-" +day;
//                try {
//                    Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateFormat);
//                    dispatcherUnit.setEndTime(date);
//                } catch (ParseException e) {
//                    e.printStackTrace();
//                }
//            }
 
            dispatcherUnit.setCreateTime(new Date());
 
            //新增
            this.save(dispatcherUnit);
 
            //数据同步
            String s1 =
                "insert into sys_dispatcher_unit(id,name,dept_id,linkman,phone,create_time,start_time,end_time,serve_type,security_linkman,cell,num) " +
                    "values(" + "'" + dispatcherUnit.getId() + "'" + "," +
                    "'" + dispatcherUnit.getName() + "'" + "," +
                    "'" + dispatcherUnit.getDeptId() + "'" + "," +
                    "'" + dispatcherUnit.getLinkman() + "'" + "," +
                    "'" + dispatcherUnit.getPhone() + "'" + "," +
                    "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcherUnit.getCreateTime()) + "'" + "," +
                    "'" + new SimpleDateFormat("yyyy/MM/dd").format(dispatcherUnit.getStartTime()) + "'" + "," +
                    "'" + new SimpleDateFormat("yyyy/MM/dd").format(dispatcherUnit.getEndTime()) + "'" + "," +
                    "'" + dispatcherUnit.getServeType() + "'" + "," +
                    "'" + dispatcherUnit.getSecurityLinkman() + "'" + "," +
                    "'" + dispatcherUnit.getCell() + "'" + "," +
                    "'" + dispatcherUnit.getNum() + "'" + ")";
            FtpUtil.sqlFileUpload(s1);
        });
    }
}