101captain
2022-06-10 51afd91af98ce2962a59eaa4a8718c38bec4950b
bug修改
1个文件已添加
3个文件已修改
158 ■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/java/com/panzhihua/auth/config/MyAESUtil.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/java/com/panzhihua/auth/handel/UserAuthenticationProvider.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/resources/bootstrap.yml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java 81 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/java/com/panzhihua/auth/config/MyAESUtil.java
New file
@@ -0,0 +1,52 @@
package com.panzhihua.auth.config;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class MyAESUtil {
    // 加密
    public static String Encrypt(String sSrc, String sKey) throws Exception {
        if (sKey == null) {
            System.out.print("Key为空null");
            return null;
        }
        // 判断Key是否为16位
        if (sKey.length() != 16) {
            System.out.print("Key长度不是16位");
            return null;
        }
        byte[] raw = sKey.getBytes("utf-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
        return new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
    }
    // 解密
    public static String Decrypt(String sSrc, String sKey) throws Exception {
        try {
            byte[] raw = sKey.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);//先用base64解密
            try {
                byte[] original = cipher.doFinal(encrypted1);
                String originalString = new String(original,"utf-8");
                return originalString;
            } catch (Exception e) {
                System.out.println(e.toString());
                return null;
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
            return null;
        }
    }
}
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/java/com/panzhihua/auth/handel/UserAuthenticationProvider.java
@@ -1,11 +1,21 @@
package com.panzhihua.auth.handel;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import com.panzhihua.auth.config.MyAESUtil;
import com.panzhihua.common.model.helper.AESUtil;
import com.panzhihua.common.utlis.AES;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.LockedException;
@@ -33,13 +43,20 @@
public class UserAuthenticationProvider implements AuthenticationProvider {
    @Resource
    private UserService userService;
    @Resource
    private RedisTemplate redisTemplate;
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        // 获取表单输入中返回的用户名
        String userName = (String)authentication.getPrincipal();
        // 获取表单中输入的密码
        String password = (String)authentication.getCredentials();
        try {
            password = MyAESUtil.Decrypt((String)authentication.getCredentials(),"Ryo7M3n8loC5Abcd");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 查询用户是否存在
        R<LoginUserInfoVO> r = userService.getUserInfo(userName);
        if (r.getCode() != 200) {
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/resources/bootstrap.yml
@@ -30,3 +30,9 @@
  metrics:
    tags:
      application: huacheng-auth
#实体加密、解密、字段脱敏拦截设置
domain:
  decrypt: true
  encrypt: true
  aesKey: Ryo7M3n8loC5
  sensitive: true
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java
@@ -17,23 +17,26 @@
import com.panzhihua.common.model.vos.community.reserve.FiveCount;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseApplyExcelVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.utlis.FileUtil;
import com.panzhihua.common.utlis.SFTPUtil;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.community_backstage.config.MinioUtil;
import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler;
import com.sun.imageio.plugins.common.ImageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.util.ImageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
@@ -68,6 +71,8 @@
    // FTP 端口
    @Value("${ftp.port}")
    private int port;
    @Resource
    private MinioUtil minioUtil;
    /**
     * 分页查询所有数据
@@ -137,6 +142,9 @@
    @PostMapping("/export")
    public R export(@RequestBody ComActAcidRecordDTO comActAcidRecordDTO) {
        String name = "防疫登记信息导出.xlsx";
        String property = System.getProperty("user.dir");
        String sourceFile =property+File.separator+"acid"+File.separator+System.currentTimeMillis()+File.separator;
        String zipFile=property+File.separator+"zip"+File.separator;
        String ftpUrl = "/mnt/data/web/excel/";
        // 用户搜索了就下载搜索的用户否则下载所有用户
        if(StringUtils.isEmpty(comActAcidRecordDTO.getLocalCity())){
@@ -144,6 +152,10 @@
        }
        R r = communityService.exportComActAcidRecord(comActAcidRecordDTO);
        if (R.isOk(r)) {
            File directory=new File(sourceFile);
            if(!directory.exists()){
                directory.mkdirs();
            }
            List<ComActAcidRecordExcelVO> excelVOS=new ArrayList<>();
            List<ComActAcidRecordExcelReturn> list= JSONArray.parseArray(JSONArray.toJSONString(r.getData()), ComActAcidRecordExcelReturn.class);
            if(!CollectionUtils.isEmpty(list)){
@@ -152,28 +164,34 @@
                    BeanUtils.copyProperties(li,comActAcidRecordExcelVO);
                    if(StringUtils.isNotEmpty(li.getTravelImage())){
                        try {
                            File image=new File(sourceFile+"/"+li.getName()+"行程码.jpg");
                            FileUtils.copyURLToFile(new URL(li.getTravelImage()),image);
                            //comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
                            comActAcidRecordExcelVO.setTravelImage(new URL(li.getTravelImage()));
                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
                        } catch (MalformedURLException e) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if(StringUtils.isNotEmpty(li.getColorImage())){
                        try {
                            File image=new File(sourceFile+"/"+li.getName()+"健康码.jpg");
                            FileUtils.copyURLToFile(new URL(li.getColorImage()),image);
                            //comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
                            comActAcidRecordExcelVO.setColorImage(new URL(li.getColorImage()));
                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
                        } catch (MalformedURLException e) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if(StringUtils.isNotEmpty(li.getAcidImage())){
                        try {
                            File image=new File(sourceFile+"/"+li.getName()+"核酸截图.jpg");
                            FileUtils.copyURLToFile(new URL(li.getAcidImage()),image);
                            comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
                            //comActAcidRecordExcelVO.setColorImage(new URL(li.getColorImage()));
                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
                        } catch (MalformedURLException e) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
@@ -191,8 +209,7 @@
                sftp.login();
                boolean existDir = sftp.isExistDir(ftpUrl + name);
                if (!existDir) {
                    String property = System.getProperty("user.dir");
                    String fileName = property + File.separator + name;
                    String fileName = sourceFile + File.separator + name;
                    // 这里 需要指定写用哪个class去写
                    ExcelWriter excelWriter = null;
                    InputStream inputStream = null;
@@ -202,17 +219,7 @@
                                .registerWriteHandler(new CustomSheetWriteHandler()).build();
                        WriteSheet writeSheet = EasyExcel.writerSheet( "导出").build();
                        excelWriter.write(excelVOS, writeSheet);
                        excelWriter.finish();
                        File file = new File(fileName);
                        inputStream = new FileInputStream(file);
                        sftp.uploadMore(ftpUrl, name, inputStream);
                        sftp.logout();
                        inputStream.close();
                        String absolutePath = file.getAbsolutePath();
                        boolean delete = file.delete();
                        log.info("删除excel【{}】结果【{}】", absolutePath, delete);
                    } finally {
                        // 千万别忘记finish 会帮忙关闭流
                        if (inputStream != null) {
@@ -223,7 +230,14 @@
                        }
                    }
                }
                return R.ok(excelUrl + name);
                FileUtil.compressToZip(sourceFile,zipFile,"防疫登记信息.zip");
                String currentDateString = String.valueOf(System.currentTimeMillis());
                String zipName = "防疫登记信息_"+ currentDateString+".zip";
                InputStream input=new FileInputStream(zipFile+"防疫登记信息.zip");
                sftp.uploadMore(ftpUrl, zipName , input);
                sftp.logout();
                input.close();
                return R.ok(excelUrl + zipName);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("文件传输失败【{}】", e.getMessage());
@@ -263,4 +277,29 @@
    public R statics(@RequestParam("date")String date){
        return this.communityService.comActAcidRecordStatics(date);
    }
    public String downloadPicture(String urlString, String fileName,String dir) throws Exception {
        // 构造URL
        URL url = new URL(urlString);
        // 打开连接
        URLConnection con = url.openConnection();
        // 输入流
        InputStream is = con.getInputStream();
        // 1K的数据缓冲
        byte[] bs = new byte[1024];
        // 读取到的数据长度
        int len;
        // 输出的文件流
        String filename = dir + fileName + ".jpg"; // 下载路径及下载图片名称
        File file = new File(filename);
        FileOutputStream os = new FileOutputStream(file, true);
        // 开始读取
        while ((len = is.read(bs)) != -1) {
            os.write(bs, 0, len);
        }
        // 完毕,关闭所有链接
        os.close();
        is.close();
        return filename;
    }
}