智慧保安后台管理-外网-验收版本
Administrator
2021-08-23 f435d50064d048c7bbc2fb46ffcd518cb19b9764
文件上传接口新增
5 files modified
2 files added
234 ■■■■■ changed files
src/main/java/org/springblade/common/constant/FtpConstant.java 8 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/dispatcher/controller/DispatcherController.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/dispatcher/excel/DispatcherUnitExcel.java 75 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/dispatcher/excel/DispatcherUnitImporter.java 42 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/dispatcher/service/IDispatcherUnitService.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/dispatcher/service/impl/DispatcherUnitServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java 49 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/constant/FtpConstant.java
@@ -8,22 +8,22 @@
    /**
     * sql connect
     */
//    String sql_connect_dev = "jdbc:mysql://223.82.109.183:2083/zhbaw";
    String sql_connect_dev = "jdbc:mysql://223.82.109.183:2083/zhbaw";
    /**
     * sql connect
     */
    String sql_connect_dev = "jdbc:mysql://localhost:2083/zhbaw";
//    String sql_connect_dev = "jdbc:mysql://localhost:2083/zhbaw";
    /**
     * ftp服务器IP地址
     */
//    String ftpHost_dev = "192.168.0.105";
    String ftpHost_dev = "192.168.0.105";
    /**
     * ftp服务器IP地址
     */
    String ftpHost_dev = "172.19.1.30";
//    String ftpHost_dev = "172.19.1.30";
    /**
     * ftp服务器端口
src/main/java/org/springblade/modules/dispatcher/controller/DispatcherController.java
@@ -99,6 +99,12 @@
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入dispatcher")
    public R save(@Valid @RequestBody Dispatcher dispatcher) {
        if (null != dispatcher.getUserIds() && dispatcher.getUserIds() != "") {
            //计算派遣人数
//            dispatcher.setNum(Arrays.asList(dispatcher.getUserIds().split(",")).size());
            //查询派遣单位的信息,设置行政区
            dispatcher.setJurisdiction(dispatcherUnitService.getById(dispatcher.getDispatcherUnitId()).getJurisdiction().toString());
        }
        return R.status(dispatcherService.save(dispatcher));
    }
@@ -118,35 +124,41 @@
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入dispatcher")
    public R submit(@Valid @RequestBody Dispatcher dispatcher) throws Exception {
    public R submit(@Valid @RequestBody Dispatcher dispatcher) {
        if (dispatcher.getId()==null){
            if (null!=dispatcher.getUserIds() && dispatcher.getUserIds()!=""){
                List<String> list = Arrays.asList(dispatcher.getUserIds().split(","));
                //计算派遣人数
                dispatcher.setNum(list.size());
//                List<String> list = Arrays.asList(dispatcher.getUserIds().split(","));
//                //计算派遣人数
//                dispatcher.setNum(list.size());
                //修改保安人员的派遣状态
                list.forEach(id -> {
                    User user = new User();
                    user.setId(Long.parseLong(id));
                    user.setDispatch("0");
                    userService.updateById(user);
                });
                User user = new User();
                user.setId(Long.parseLong(dispatcher.getUserIds()));
                user.setDispatch("0");
                userService.updateById(user);
                //查询派遣单位的信息,设置行政区
                dispatcher.setJurisdiction(dispatcherUnitService.getById(dispatcher.getDispatcherUnitId()).getJurisdiction().toString());
            }
        }
        else {
            if (null != dispatcher.getUserIds() && dispatcher.getUserIds() != "") {
                List<String> list = Arrays.asList(dispatcher.getUserIds().split(","));
//                List<String> list = Arrays.asList(dispatcher.getUserIds().split(","));
                //计算派遣人数
                dispatcher.setNum(list.size());
                //修改保安人员的派遣状态
                list.forEach(id -> {
//                dispatcher.setNum(list.size());
                //查询当前派遣记录
                Dispatcher dispatcher1 = dispatcherService.getById(dispatcher.getId());
                if (!dispatcher1.getUserIds().equals(dispatcher.getUserIds())){
                    //修改原保安人员的派遣状态
                    User user = new User();
                    user.setId(Long.parseLong(id));
                    user.setDispatch("0");
                    user.setId(Long.parseLong(dispatcher1.getUserIds()));
                    user.setDispatch("1");
                    userService.updateById(user);
                });
                    //修改当前保安人员的派遣状态
                    User user1 = new User();
                    user1.setId(Long.parseLong(dispatcher.getUserIds()));
                    user1.setDispatch("0");
                    userService.updateById(user1);
                }
                //查询派遣单位的信息,设置行政区
                dispatcher.setJurisdiction(dispatcherUnitService.getById(dispatcher.getDispatcherUnitId()).getJurisdiction().toString());
            }
src/main/java/org/springblade/modules/dispatcher/excel/DispatcherUnitExcel.java
New file
@@ -0,0 +1,75 @@
/*
 *      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.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * @author zhongrj
 * @since 2021-08-23
 */
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class DispatcherUnitExcel implements Serializable {
    private static final long serialVersionUID = 1L;
    @ColumnWidth(25)
    @ExcelProperty("保安公司名称")
    private String deptName;
    @ColumnWidth(25)
    @ExcelProperty("服务对象名称")
    private String name;
    @ColumnWidth(20)
    @ExcelProperty("保安员派遣总数")
    private Integer num;
    @ColumnWidth(20)
    @ExcelProperty("联系人")
    private String linkman;
    @ColumnWidth(20)
    @ExcelProperty("联系电话")
    private String phone;
    @ColumnWidth(20)
    @ExcelProperty("合同开始时间")
    private Date startTime;
    @ColumnWidth(20)
    @ExcelProperty("合同结束时间")
    private Date endTime;
}
src/main/java/org/springblade/modules/dispatcher/excel/DispatcherUnitImporter.java
New file
@@ -0,0 +1,42 @@
/*
 *      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.excel;
import lombok.RequiredArgsConstructor;
import org.springblade.core.excel.support.ExcelImporter;
import org.springblade.modules.dispatcher.service.IDispatcherUnitService;
import org.springblade.modules.exam.service.ExamScoreService;
import java.util.List;
/**
 * 派遣单位导入类
 *
 * @author zhongrj
 * @since 2021-08-23
 */
@RequiredArgsConstructor
public class DispatcherUnitImporter implements ExcelImporter<DispatcherUnitExcel> {
    private final IDispatcherUnitService service;
    private final Boolean isCovered;
    @Override
    public void save(List<DispatcherUnitExcel> data) {
        service.importDispatcherUnit(data, isCovered);
    }
}
src/main/java/org/springblade/modules/dispatcher/service/IDispatcherUnitService.java
@@ -20,6 +20,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
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.vo.DispatcherUnitVO;
import org.springblade.modules.dispatcher.vo.DispatcherVO;
@@ -55,4 +56,11 @@
     * @return
     */
    List<DispatcherUnitVO> selectDispatcherUnitPageTree(DispatcherUnitVO dispatcher);
    /**
     * 派遣导入
     * @param data
     * @param isCovered
     */
    void importDispatcherUnit(List<DispatcherUnitExcel> data, Boolean isCovered);
}
src/main/java/org/springblade/modules/dispatcher/service/impl/DispatcherUnitServiceImpl.java
@@ -21,6 +21,7 @@
import lombok.AllArgsConstructor;
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;
@@ -73,4 +74,9 @@
    public List<DispatcherUnitVO> selectDispatcherUnitPageTree(DispatcherUnitVO dispatcher) {
        return baseMapper.selectDispatcherUnitPageTree(dispatcher);
    }
    @Override
    public void importDispatcherUnit(List<DispatcherUnitExcel> data, Boolean isCovered) {
    }
}
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -215,6 +215,55 @@
        return R.data(urls);
    }
    /**
     *
     * 文件上传,自定义上传
     * @param file 图片对象
     */
    @PostMapping("put-files")
    public R putFiles(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
        //填写你文件上传的地址以及相应信息
        String url = "http://223.82.109.183:2081";
        String access = "zhbaadmin";
        String secret = "zhbapassword";
        String bucket = "zhba";
        MinioClient minioClient =
            MinioClient.builder()
                .endpoint(url)
                .credentials(access, secret)
                .build();
        // 检查存储桶是否已经存在
        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (!isExist) {
            // 创建一个名为zip的存储桶,用于zip文件。
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
        }
        String fileName = file.getOriginalFilename();
        String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
            + fileName.substring(fileName.lastIndexOf("."));
        InputStream in = file.getInputStream();
        //创建头部信息
        Map<String, String> headers = new HashMap<>(1 << 2);
        //添加自定义内容类型
        headers.put("Content-Type", "application/octet-stream");
        //上传
        minioClient.putObject(
            PutObjectArgs.builder().bucket(bucket).object(newName).stream(
                in, in.available(), -1)
                .headers(headers)
                .build());
        in.close();
        String urls = "http://223.82.109.183:2081/zhba/" + newName;
        //数据封装
        Map<String, Object> map = new HashMap<>(2);
        map.put("name",newName);
        map.put("url",urls);
        //返回
        return R.data(map);
    }
    /**
     * 上传文件
     *