作者 yangfu

申请列表修改

package service
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"strconv"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -81,9 +82,13 @@ func (srv CooperationApplicationsService) SearchCooperationApplications(applicat
IsCanceled: 1,
})
for i := 0; i < len(resultApplications.Grid.List); i++ {
resultApplications.Grid.List[i].Department.DepartmentID = resultApplications.Grid.List[i].Org.OrgID
resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].Org.OrgName
resultApplications.Grid.List[i].Department.DepartmentID = int(resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentId)
resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentName
if len(resultApplications.Grid.List[i].Department.DepartmentName) == 0 && resultApplications.Grid.List[i].Department.DepartmentID == 0 {
resultApplications.Grid.List[i].Department.DepartmentName = domain.CooperationUserDepartmentName
}
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ... @@ -168,10 +173,6 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap
}
// var dataList []dto.CooperationApplication
// for i := range resultApplications.Gride.List {
// item := dto.ToCooperationApplication(&resultApplications.Gride.List[i])
// dataList = append(dataList, *item)
// }
return resultApplications, nil
}
... ...
... ... @@ -69,3 +69,7 @@ const (
// 导入共创用户
ExportCooperationUser = "ExportCooperationUser"
)
const (
CooperationUserDepartmentName = "共创用户"
)
... ...
... ... @@ -13,13 +13,56 @@ func PKCS5Padding(plaintext []byte, blockSize int) []byte {
}
//@brief:去除填充数据
func PKCS5UnPadding(origData []byte) []byte {
func PKCS5UnPadding(origData []byte, blockSize int) []byte {
length := len(origData)
unpadding := int(origData[length-1])
return origData[:(length - unpadding)]
}
//@brief:AES加密
// PKCS7Padding right-pads the given byte slice with 1 to n bytes, where
// n is the block size. The size of the result is x times n, where x
// is at least 1.
func PKCS7Padding(b []byte, blockSize int) []byte {
if blockSize <= 0 {
return nil
}
if b == nil || len(b) == 0 {
return nil
}
n := blockSize - (len(b) % blockSize)
pb := make([]byte, len(b)+n)
copy(pb, b)
copy(pb[len(b):], bytes.Repeat([]byte{byte(n)}, n))
return pb
}
// PKCS7UnPadding validates and unpads data from the given bytes slice.
// The returned value will be 1 to n bytes smaller depending on the
// amount of padding, where n is the block size.
func PKCS7UnPadding(b []byte, blockSize int) []byte {
if blockSize <= 0 {
return nil
}
if b == nil || len(b) == 0 {
return nil
}
if len(b)%blockSize != 0 {
return nil
}
c := b[len(b)-1]
n := int(c)
if n == 0 || n > len(b) {
return nil
}
for i := 0; i < n; i++ {
if b[len(b)-n+i] != c {
return nil
}
}
return b[:len(b)-n]
}
// AES加密
func AesEncrypt(origData, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
... ... @@ -28,14 +71,14 @@ func AesEncrypt(origData, key []byte) ([]byte, error) {
//AES分组长度为128位,所以blockSize=16,单位字节
blockSize := block.BlockSize()
origData = PKCS5Padding(origData, blockSize)
origData = PKCS7Padding(origData, blockSize)
blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
crypted := make([]byte, len(origData))
blockMode.CryptBlocks(crypted, origData)
return crypted, nil
}
//@brief:AES解密
// AES解密
func AesDecrypt(crypted, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
... ... @@ -47,6 +90,6 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) {
blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
origData := make([]byte, len(crypted))
blockMode.CryptBlocks(origData, crypted)
origData = PKCS5UnPadding(origData)
origData = PKCS7UnPadding(origData, blockSize)
return origData, nil
}
... ...
... ... @@ -8,7 +8,7 @@ import (
func Test_Aes(t *testing.T) {
//key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256
var aeskey = []byte("12345678abcdefgh")
var aeskey = []byte("mmm.qrcode.(%^&)")
pass := []byte("vdncloud123456")
xpass, err := AesEncrypt(pass, aeskey)
if err != nil {
... ...