annotate qtuti/95_tmpl.go @ 0:aaaa401818a1 draft

first commit.
author pyon <pyon@macmini>
date Mon, 24 May 2021 21:32:58 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
1 /*
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
2 95.go: Qfuhi Tsuchi
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
3
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
4 Last Change: 2020-09-11 金 10:42:16.
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
5 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
6
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
7 package main
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
8
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
9 /*
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
10 #cgo LDFLAGS: -L. -lxdwapi -static
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
11 ##### C_SOURCE #####
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
12 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
13 import "C"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
14
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
15 import (
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
16 "bufio"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
17 "regexp"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
18 "encoding/json"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
19 "flag"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
20 "fmt"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
21 "io/ioutil"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
22 "log"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
23 "os"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
24 "path/filepath"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
25 "sort"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
26 "strings"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
27
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
28 "golang.org/x/text/encoding/japanese"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
29 "golang.org/x/text/transform"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
30 )
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
31
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
32 type Hhs struct {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
33 No string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
34 Name string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
35 Page int // sinsei page
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
36 Tsuchi bool
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
37 Kaigo string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
38 Xdw []string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
39 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
40
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
41 func(h *Hhs) AppendXdw(xdw string) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
42 h.Xdw = append(h.Xdw, xdw)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
43 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
44
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
45 func(h *Hhs) CsvString() string {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
46 q := ""
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
47 if h.Tsuchi {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
48 q = "○"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
49 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
50 k := strings.Split(h.Kaigo, "")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
51 return strings.Join([]string{h.No, h.Name, q, k[1] + k[3]}, ",")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
52 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
53
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
54 func(h *Hhs) Dump() string {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
55 q := "false"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
56 if h.Tsuchi {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
57 q = "true"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
58 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
59 p := fmt.Sprintf("%05d", h.Page)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
60 x := strings.Join(h.Xdw, ",")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
61 return strings.Join([]string{h.No, h.Name, q, h.Kaigo, p, x}, ",")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
62 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
63
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
64 type Config struct {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
65 Indir string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
66 Outdir string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
67 Workdir string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
68 Hhsdb string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
69 Atnfile[] string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
70 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
71
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
72 var (
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
73 ver = "0.1"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
74 conf Config
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
75 confjson = "95.json"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
76 logfile = "95.log"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
77 osirase = "KBPA316G.xdw"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
78 sinsei = "KBPA406G.xdw"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
79 rule_s = "rules.ann"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
80
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
81 out_o = "o.xdw"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
82 out_s = "s.xdw"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
83 out_q = "q.xdw"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
84 out_l = "l.csv"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
85
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
86 re_hhsno, re_name, re_kaigo *regexp.Regexp
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
87
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
88 // option parameters
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
89 version bool
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
90 )
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
91
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
92 func init() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
93 /* コンフィグファイルは JSON */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
94 content, err := ioutil.ReadFile(confjson)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
95 if err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
96 log.Fatal(err)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
97 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
98 if err := json.Unmarshal(content, &conf); err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
99 log.Fatal(err)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
100 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
101
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
102 osirase = filepath.Join(conf.Indir, osirase)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
103 sinsei = filepath.Join(conf.Indir, sinsei)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
104
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
105 out_o = filepath.Join(conf.Outdir, out_o)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
106 out_s = filepath.Join(conf.Outdir, out_s)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
107 out_q = filepath.Join(conf.Outdir, out_q)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
108 out_l = filepath.Join(conf.Outdir, out_l)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
109
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
110 logfile = filepath.Join(conf.Workdir, logfile)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
111
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
112 /* 一時ファイル消去 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
113 os.RemoveAll(conf.Outdir)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
114 os.RemoveAll(conf.Workdir)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
115 os.Mkdir(conf.Outdir, 0755)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
116 os.Mkdir(conf.Workdir, 0755)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
117
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
118 /* 変数初期化 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
119 re_hhsno = regexp.MustCompile(`0[1238]00\d{6}`)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
120 re_name = regexp.MustCompile(`日.{30}`)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
121 re_kaigo = regexp.MustCompile(`要((介護)|(支援)).`)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
122
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
123 flag.BoolVar(&version, "v", false, "print version")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
124 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
125
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
126 func main() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
127 flag.Parse()
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
128
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
129 if version {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
130 fmt.Println("95 - version", ver)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
131 os.Exit(0)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
132 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
133
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
134 hash_Hhs := make(map[string]Hhs)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
135
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
136 /* 申請書を漁り,構造体を初期化 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
137 for p, t := range xdw2txt(sinsei) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
138 hno := re_hhsno.FindString(t)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
139 name := re_name.FindString(t)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
140 name = strings.Replace(name, "日", "", 1)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
141 kaigo := re_kaigo.FindString(t)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
142 o := fmt.Sprintf("o_%05d.xdw", p + 1)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
143 s := fmt.Sprintf("s_%05d.xdw", p + 1)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
144 h := Hhs{No: hno, Name: name, Kaigo: kaigo, Page:p + 1, Xdw: []string{o, s}}
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
145 hash_Hhs[hno] = h
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
146 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
147
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
148 /* バックグラウンドで給付費通知から勧奨対象者を抽出 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
149 ch := make(chan int)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
150 go func() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
151 files, err := ioutil.ReadDir(conf.Indir)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
152 if err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
153 log.Fatal(err)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
154 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
155
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
156 qn := 1
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
157 for _, file := range files {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
158 if !strings.HasSuffix(file.Name(), ".xdw") {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
159 continue
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
160 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
161 if strings.HasPrefix(file.Name(), "KDPK016G") || strings.HasPrefix(file.Name(), "KDPK126G") {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
162 qtsuchi := filepath.Join(conf.Indir, file.Name())
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
163 tmptxt := filepath.Join(conf.Workdir, "tmp95.txt")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
164 for p, t := range xdw2txtb(qtsuchi, tmptxt) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
165 hno := re_hhsno.FindString(t)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
166 if h, ok := hash_Hhs[hno]; ok {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
167 h.Tsuchi = true
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
168 q := fmt.Sprintf("q_%05d.xdw", qn)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
169 h.AppendXdw(q)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
170 hash_Hhs[hno] = h
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
171 q = filepath.Join(conf.Workdir, q)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
172 C.xdwextpage(C.CString(qtsuchi), C.int(p + 1), C.CString(q))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
173 qn++
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
174 //fmt.Println(qtsuchi, p, hno, h.Kaigo, h.Xdw)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
175 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
176 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
177 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
178 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
179
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
180 ch <- 1
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
181 }()
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
182
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
183 /* そのあいだにバラす */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
184 C.xdwsplit1(C.CString(osirase), C.CString(conf.Workdir), C.CString("o_"))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
185 C.xdwsplit1(C.CString(sinsei), C.CString(conf.Workdir), C.CString("s_"))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
186 <-ch
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
187
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
188 /* ソート & マージ */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
189 var slice_Hhs []Hhs
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
190 for _, h := range hash_Hhs {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
191 slice_Hhs = append(slice_Hhs, h)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
192 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
193 sort.Slice(slice_Hhs, func(i, j int) bool {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
194 if slice_Hhs[i].Tsuchi != slice_Hhs[j].Tsuchi {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
195 return slice_Hhs[i].Tsuchi
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
196 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
197 if slice_Hhs[i].Kaigo != slice_Hhs[j].Kaigo {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
198 return slice_Hhs[i].Kaigo < slice_Hhs[j].Kaigo
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
199 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
200 if slice_Hhs[i].Page != slice_Hhs[j].Page {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
201 return slice_Hhs[i].Page < slice_Hhs[j].Page
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
202 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
203 return false
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
204 })
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
205
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
206 var list_o, list_s, list_q []string
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
207 for _, h := range slice_Hhs {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
208 list_o = append(list_o, filepath.Join(conf.Workdir, h.Xdw[0]))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
209 list_s = append(list_s, filepath.Join(conf.Workdir, h.Xdw[1]))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
210 if h.Tsuchi {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
211 for i, x := range h.Xdw {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
212 if i > 1 {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
213 buf := filepath.Join(conf.Workdir, x)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
214 list_q = append(list_q, buf)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
215 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
216 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
217 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
218 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
219 xdwmerge(list_o, out_o)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
220 xdwmerge(list_s, out_s)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
221 xdwmerge(list_q, out_q)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
222
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
223 /* リスト出力 & ログダンプ */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
224 csvtxt := ""
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
225 logtxt := ""
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
226 for _, h := range slice_Hhs {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
227 csvtxt += h.CsvString() + "\n"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
228 logtxt += h.Dump() + "\n"
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
229 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
230 csvtxt, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), csvtxt)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
231 if err := ioutil.WriteFile(out_l, []byte(csvtxt), 0644); err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
232 log.Fatal(err)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
233 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
234 if err := ioutil.WriteFile(logfile, []byte(logtxt), 0644); err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
235 log.Fatal(err)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
236 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
237
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
238 /* バックグラウンドで給付費通知を校正 */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
239 ch2 := make(chan int)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
240 go func() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
241 for _, a := range conf.Atnfile {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
242 xdwaddatn(out_q, a)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
243 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
244 ch2 <- 1
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
245 } ()
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
246
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
247 /* そのあいだに申請書に枠付け */
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
248 xdwaddatntool(out_s, rule_s, 2, 1497, 803)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
249 <-ch2
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
250 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
251
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
252 func xdw2txt(file string) (txt []string) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
253 s := C.GoString(C.xdw2txt(C.CString(file)))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
254 r := strings.NewReader(s)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
255 tr := transform.NewReader(r, japanese.ShiftJIS.NewDecoder())
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
256 buf := bufio.NewScanner(tr)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
257 for buf.Scan() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
258 txt = append(txt, buf.Text())
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
259 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
260 return
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
261 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
262
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
263 func xdw2txtb(xdwfile, txtfile string) (txt []string) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
264 if _, err := os.Stat(txtfile); os.IsExist(err) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
265 os.Remove(txtfile)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
266 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
267
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
268 C.xdw2txtb(C.CString(xdwfile), C.CString(txtfile))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
269 content, err := ioutil.ReadFile(txtfile)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
270 if err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
271 return nil
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
272 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
273
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
274 r := strings.NewReader(string(content))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
275 tr := transform.NewReader(r, japanese.ShiftJIS.NewDecoder())
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
276 buf := bufio.NewScanner(tr)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
277 for buf.Scan() {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
278 txt = append(txt, buf.Text())
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
279 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
280 return
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
281 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
282
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
283 func xdwmerge(list []string, outfile string) (err error) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
284 order := strings.Join(list, "\n")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
285 order, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), order)
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
286 orderfile := filepath.Join(conf.Workdir, "order95.txt")
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
287 if err := ioutil.WriteFile(orderfile, []byte(order), 0644); err != nil {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
288 return err
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
289 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
290 C.xdwmerge(C.CString(orderfile), C.CString(outfile))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
291 return nil
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
292 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
293
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
294 func xdwaddatn(xdwfile, atnfile string) (err error) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
295 C.xdwaddatn(C.CString(xdwfile), C.CString(atnfile))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
296 return nil
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
297 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
298
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
299 func xdwaddatntool(xdwfile, toolfile string, n, x, y int) (err error) {
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
300 C.xdwaddatntool(C.CString(xdwfile), C.CString(toolfile), C.int(n), C.int(x), C.int(y))
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
301 return nil
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
302 }
aaaa401818a1 first commit.
pyon <pyon@macmini>
parents:
diff changeset
303