|
|
@ -3,12 +3,8 @@ package main |
|
|
|
import ( |
|
|
|
"database/sql" |
|
|
|
"fmt" |
|
|
|
"golang.org/x/image/bmp" |
|
|
|
"golang.org/x/image/tiff" |
|
|
|
"image/gif" |
|
|
|
"image/jpeg" |
|
|
|
"image/png" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
@ -16,246 +12,61 @@ import ( |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
) |
|
|
|
|
|
|
|
var demo = "select a0101 name from a01" |
|
|
|
|
|
|
|
var hzbSQL = "select concat('copy D:\\\\insigma\\\\old\\\\', PHOTONAME, ' D:\\\\insigma\\\\new\\\\', a0184, substr(PHOTONAME, instr(PHOTONAME,'.'))) name " + |
|
|
|
"from a57 join a01 on a57.a0000=a01.a0000 where PHOTONAME not REGEXP '^[0-9A-Za-z]' or " + |
|
|
|
"lower(substr(PHOTONAME, instr(PHOTONAME,'.')+1)) not in ('jpg', 'jpeg')" |
|
|
|
var mysqlSQL = "select concat('copy D:\\\\insigma\\\\old\\\\', a5714, ' D:\\\\insigma\\\\old\\\\', a0184, substr(a5714, instr(a5714,'.'))) name " + |
|
|
|
"from a57 join a01 on a57.id=a01.id where a5714 not REGEXP '^[0-9A-Za-z]' or a5714 like '%|%' or " + |
|
|
|
"lower(substr(a5714, instr(a5714,'.')+1)) not in ('jpg', 'jpeg')" |
|
|
|
|
|
|
|
func main() { |
|
|
|
|
|
|
|
args := os.Args |
|
|
|
dir, _ := filepath.Abs("./") |
|
|
|
if args[1] == "hzb" { |
|
|
|
queryHzb() |
|
|
|
} else if args[1] == "mysql" { |
|
|
|
queryMySQL() |
|
|
|
} else if args[1] == "img" { |
|
|
|
makeImg(dir) |
|
|
|
dir = strings.Replace(dir, "\\", "\\\\", -1) |
|
|
|
fmt.Printf("当前目录:%s\n", dir) |
|
|
|
if len(args) == 1 || args[1] == "hzbcz" { |
|
|
|
queryHzbcz(dir) |
|
|
|
} else { |
|
|
|
fmt.Println("您操作可能存在问题!\n" + |
|
|
|
"请联系张献维...\n" + |
|
|
|
"hzb : Hzb数据库照片问题处理,生产脚本!\n" + |
|
|
|
"mysql : MySQL数据库照片问题处理,生产脚本!\n" + |
|
|
|
"img : 照片格式处理,新照片存储同目录下!") |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
func makeImg(dir string) { |
|
|
|
newStr, dirStr := "", "" |
|
|
|
dirs, _ := getDirList(dir) |
|
|
|
for i, j := 0, len(dirs); i < j; i++ { |
|
|
|
dirStr = dirs[i] |
|
|
|
if strings.HasSuffix(dirStr, ".png") || strings.HasSuffix(dirStr, ".PNG") { |
|
|
|
newStr = strings.Replace(dirStr, ".png", ".jpg", -1) |
|
|
|
newStr = strings.Replace(newStr, ".PNG", ".jpg", -1) |
|
|
|
runPng(dirStr, newStr) |
|
|
|
} else if strings.HasSuffix(dirStr, ".tiff") || strings.HasSuffix(dirStr, ".TIFF") { |
|
|
|
newStr = strings.Replace(dirStr, ".tiff", ".jpg", -1) |
|
|
|
newStr = strings.Replace(newStr, ".TIFF", ".jpg", -1) |
|
|
|
runTiff(dirStr, newStr) |
|
|
|
} else if strings.HasSuffix(dirStr, ".pic") || strings.HasSuffix(dirStr, ".PIC") { |
|
|
|
newStr = strings.Replace(dirStr, ".pic", ".jpg", -1) |
|
|
|
newStr = strings.Replace(newStr, ".PIC", ".jpg", -1) |
|
|
|
runPic(dirStr, newStr) |
|
|
|
} else if strings.HasSuffix(dirStr, ".bmp") || strings.HasSuffix(dirStr, ".BMP") { |
|
|
|
newStr = strings.Replace(dirStr, ".bmp", ".jpg", -1) |
|
|
|
newStr = strings.Replace(newStr, ".BMP", ".jpg", -1) |
|
|
|
runBmp(dirStr, newStr) |
|
|
|
} else if strings.HasSuffix(dirStr, ".gif") || strings.HasSuffix(dirStr, ".GIF") { |
|
|
|
newStr = strings.Replace(dirStr, ".gif", ".jpg", -1) |
|
|
|
newStr = strings.Replace(newStr, ".GIF", ".jpg", -1) |
|
|
|
runGif(dirStr, newStr) |
|
|
|
} |
|
|
|
"hzbcz : 辞职数据库照片问题处理,更新文件名称,保持与数据库一致!") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func getDirList(dirpath string) ([]string, error) { |
|
|
|
var dirList []string |
|
|
|
dirErr := filepath.Walk(dirpath, |
|
|
|
func(path string, f os.FileInfo, err error) error { |
|
|
|
if f == nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if !f.IsDir() && !strings.HasSuffix(f.Name(), ".jpeg") && !strings.HasSuffix(f.Name(), ".jpg") && !strings.HasSuffix(f.Name(), ".JPEG") && !strings.HasSuffix(f.Name(), ".JPG") { |
|
|
|
dirList = append(dirList, path) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
|
return dirList, dirErr |
|
|
|
} |
|
|
|
|
|
|
|
func writeFile(allStr string) { |
|
|
|
file3, _ := os.Create(time.Now().Format("20060102150405") + ".txt") |
|
|
|
file3.WriteString(allStr) |
|
|
|
file3.Close() |
|
|
|
} |
|
|
|
|
|
|
|
func queryHzb() { |
|
|
|
db, err := sql.Open("mysql", "root:admin@tcp(localhost:35017)/hy_qggwy?charset=utf8") |
|
|
|
_, err := file3.WriteString(allStr) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
_ = fmt.Errorf("[writeFile::1]发生异常:%s", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
rows, _ := db.Query(hzbSQL) |
|
|
|
fmt.Println(hzbSQL) |
|
|
|
name, _ := rows.Columns() |
|
|
|
endStr := "" |
|
|
|
for rows.Next() { |
|
|
|
rows.Scan(&name[0]) |
|
|
|
endStr = endStr + "\r\n" + name[0] |
|
|
|
} |
|
|
|
writeFile(endStr) |
|
|
|
_ = file3.Close() |
|
|
|
} |
|
|
|
|
|
|
|
func queryMySQL() { |
|
|
|
db, err := sql.Open("mysql", "gwydb:gwydbpwd@tcp(localhost:7953)/gwybase?charset=utf8") |
|
|
|
// queryHzbcz 辞职数据库照片问题处理,解决信息操作
|
|
|
|
func queryHzbcz(dir string) { |
|
|
|
db, err := sql.Open("mysql", "root:admin@tcp(192.168.1.111:35017)/hy_qggwy?charset=utf8") |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
_ = fmt.Errorf("[queryHzb::1]发生异常:%s", err) |
|
|
|
} |
|
|
|
|
|
|
|
rows, _ := db.Query(mysqlSQL) |
|
|
|
fmt.Println(mysqlSQL) |
|
|
|
name, endStr := "", "" |
|
|
|
for rows.Next() { |
|
|
|
rows.Scan(&name) |
|
|
|
endStr = endStr + "\r\n" + name |
|
|
|
} |
|
|
|
writeFile(endStr) |
|
|
|
} |
|
|
|
|
|
|
|
func runTiff(fPath, tPath string) { |
|
|
|
fmt.Println(fPath, " ", tPath) |
|
|
|
file, err := os.Open(fPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := tiff.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func runPic(fPath, tPath string) { |
|
|
|
fmt.Println(fPath, " ", tPath) |
|
|
|
file, err := os.Open(fPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := jpeg.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func runBmp(fPath, tPath string) { |
|
|
|
fmt.Println(fPath, " ", tPath) |
|
|
|
file, err := os.Open(fPath) |
|
|
|
cmd := exec.Command("cmd", "/C", "del", "E:\\a.txt") |
|
|
|
err = cmd.Run() |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
_ = fmt.Errorf("[queryHzb::2]发生异常:%s", err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
err = cmd.Wait() //执行Start会在此处等待10秒
|
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := bmp.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func runGif(fPath, tPath string) { |
|
|
|
fmt.Println(fPath, " ", tPath) |
|
|
|
file, err := os.Open(fPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := gif.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func runPng(fPath, tPath string) { |
|
|
|
fmt.Println(fPath, " ", tPath) |
|
|
|
file, err := os.Open(fPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := png.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func runJpg(fPath, tPath string) { |
|
|
|
file, err := os.Open(fPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
file1, err := os.Create(tPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
defer file1.Close() |
|
|
|
|
|
|
|
img, err := jpeg.Decode(file) //解码
|
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
sqlStr := fmt.Sprintf(`select |
|
|
|
concat('move "%s/', substr(a0000,1,1), '/', substr(a0000,2,1), '/', a0000, '.jpg" "%s/', a5714, '"') name |
|
|
|
from c01 where instr(a5714, a0000) = 0 and a5714 is not null and a5714 <> ''`, dir, dir) |
|
|
|
fmt.Printf("执行脚本:%s\n", sqlStr) |
|
|
|
rows, _ := db.Query(sqlStr) |
|
|
|
name, _ := rows.Columns() |
|
|
|
endStr := "" |
|
|
|
for rows.Next() { |
|
|
|
err := rows.Scan(&name[0]) |
|
|
|
if err != nil { |
|
|
|
_ = fmt.Errorf("[queryHzbcz::3]发生异常:%s", err) |
|
|
|
return |
|
|
|
} |
|
|
|
endStr = endStr + "\r\n" + name[0] |
|
|
|
/* 创建文件文件 */ |
|
|
|
exec.Command("cmd", "/C", name[0]).Start() |
|
|
|
} |
|
|
|
jpeg.Encode(file1, img, nil) //编码,但是将图像质量从100改成5
|
|
|
|
|
|
|
|
writeFile(endStr) |
|
|
|
} |
|
|
|