作者 yangfu

申请列表修改

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
4 "strconv" 5 "strconv"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
@@ -81,9 +82,13 @@ func (srv CooperationApplicationsService) SearchCooperationApplications(applicat @@ -81,9 +82,13 @@ func (srv CooperationApplicationsService) SearchCooperationApplications(applicat
81 IsCanceled: 1, 82 IsCanceled: 1,
82 }) 83 })
83 for i := 0; i < len(resultApplications.Grid.List); i++ { 84 for i := 0; i < len(resultApplications.Grid.List); i++ {
84 - resultApplications.Grid.List[i].Department.DepartmentID = resultApplications.Grid.List[i].Org.OrgID  
85 - resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].Org.OrgName 85 + resultApplications.Grid.List[i].Department.DepartmentID = int(resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentId)
  86 + resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentName
  87 + if len(resultApplications.Grid.List[i].Department.DepartmentName) == 0 && resultApplications.Grid.List[i].Department.DepartmentID == 0 {
  88 + resultApplications.Grid.List[i].Department.DepartmentName = domain.CooperationUserDepartmentName
86 } 89 }
  90 + }
  91 +
87 if err != nil { 92 if err != nil {
88 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 93 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
89 } 94 }
@@ -168,10 +173,6 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap @@ -168,10 +173,6 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap
168 } 173 }
169 // var dataList []dto.CooperationApplication 174 // var dataList []dto.CooperationApplication
170 175
171 - // for i := range resultApplications.Gride.List {  
172 - // item := dto.ToCooperationApplication(&resultApplications.Gride.List[i])  
173 - // dataList = append(dataList, *item)  
174 - // }  
175 return resultApplications, nil 176 return resultApplications, nil
176 } 177 }
177 178
@@ -69,3 +69,7 @@ const ( @@ -69,3 +69,7 @@ const (
69 // 导入共创用户 69 // 导入共创用户
70 ExportCooperationUser = "ExportCooperationUser" 70 ExportCooperationUser = "ExportCooperationUser"
71 ) 71 )
  72 +
  73 +const (
  74 + CooperationUserDepartmentName = "共创用户"
  75 +)
@@ -13,13 +13,56 @@ func PKCS5Padding(plaintext []byte, blockSize int) []byte { @@ -13,13 +13,56 @@ func PKCS5Padding(plaintext []byte, blockSize int) []byte {
13 } 13 }
14 14
15 //@brief:去除填充数据 15 //@brief:去除填充数据
16 -func PKCS5UnPadding(origData []byte) []byte { 16 +func PKCS5UnPadding(origData []byte, blockSize int) []byte {
17 length := len(origData) 17 length := len(origData)
18 unpadding := int(origData[length-1]) 18 unpadding := int(origData[length-1])
19 return origData[:(length - unpadding)] 19 return origData[:(length - unpadding)]
20 } 20 }
21 21
22 -//@brief:AES加密 22 +// PKCS7Padding right-pads the given byte slice with 1 to n bytes, where
  23 +// n is the block size. The size of the result is x times n, where x
  24 +// is at least 1.
  25 +func PKCS7Padding(b []byte, blockSize int) []byte {
  26 + if blockSize <= 0 {
  27 + return nil
  28 + }
  29 + if b == nil || len(b) == 0 {
  30 + return nil
  31 + }
  32 + n := blockSize - (len(b) % blockSize)
  33 + pb := make([]byte, len(b)+n)
  34 + copy(pb, b)
  35 + copy(pb[len(b):], bytes.Repeat([]byte{byte(n)}, n))
  36 + return pb
  37 +}
  38 +
  39 +// PKCS7UnPadding validates and unpads data from the given bytes slice.
  40 +// The returned value will be 1 to n bytes smaller depending on the
  41 +// amount of padding, where n is the block size.
  42 +func PKCS7UnPadding(b []byte, blockSize int) []byte {
  43 + if blockSize <= 0 {
  44 + return nil
  45 + }
  46 + if b == nil || len(b) == 0 {
  47 + return nil
  48 + }
  49 + if len(b)%blockSize != 0 {
  50 + return nil
  51 + }
  52 + c := b[len(b)-1]
  53 + n := int(c)
  54 + if n == 0 || n > len(b) {
  55 + return nil
  56 + }
  57 + for i := 0; i < n; i++ {
  58 + if b[len(b)-n+i] != c {
  59 + return nil
  60 + }
  61 + }
  62 + return b[:len(b)-n]
  63 +}
  64 +
  65 +// AES加密
23 func AesEncrypt(origData, key []byte) ([]byte, error) { 66 func AesEncrypt(origData, key []byte) ([]byte, error) {
24 block, err := aes.NewCipher(key) 67 block, err := aes.NewCipher(key)
25 if err != nil { 68 if err != nil {
@@ -28,14 +71,14 @@ func AesEncrypt(origData, key []byte) ([]byte, error) { @@ -28,14 +71,14 @@ func AesEncrypt(origData, key []byte) ([]byte, error) {
28 71
29 //AES分组长度为128位,所以blockSize=16,单位字节 72 //AES分组长度为128位,所以blockSize=16,单位字节
30 blockSize := block.BlockSize() 73 blockSize := block.BlockSize()
31 - origData = PKCS5Padding(origData, blockSize) 74 + origData = PKCS7Padding(origData, blockSize)
32 blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节 75 blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
33 crypted := make([]byte, len(origData)) 76 crypted := make([]byte, len(origData))
34 blockMode.CryptBlocks(crypted, origData) 77 blockMode.CryptBlocks(crypted, origData)
35 return crypted, nil 78 return crypted, nil
36 } 79 }
37 80
38 -//@brief:AES解密 81 +// AES解密
39 func AesDecrypt(crypted, key []byte) ([]byte, error) { 82 func AesDecrypt(crypted, key []byte) ([]byte, error) {
40 block, err := aes.NewCipher(key) 83 block, err := aes.NewCipher(key)
41 if err != nil { 84 if err != nil {
@@ -47,6 +90,6 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) { @@ -47,6 +90,6 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) {
47 blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节 90 blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
48 origData := make([]byte, len(crypted)) 91 origData := make([]byte, len(crypted))
49 blockMode.CryptBlocks(origData, crypted) 92 blockMode.CryptBlocks(origData, crypted)
50 - origData = PKCS5UnPadding(origData) 93 + origData = PKCS7UnPadding(origData, blockSize)
51 return origData, nil 94 return origData, nil
52 } 95 }
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 8
9 func Test_Aes(t *testing.T) { 9 func Test_Aes(t *testing.T) {
10 //key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256 10 //key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256
11 - var aeskey = []byte("12345678abcdefgh") 11 + var aeskey = []byte("mmm.qrcode.(%^&)")
12 pass := []byte("vdncloud123456") 12 pass := []byte("vdncloud123456")
13 xpass, err := AesEncrypt(pass, aeskey) 13 xpass, err := AesEncrypt(pass, aeskey)
14 if err != nil { 14 if err != nil {