12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package dto
- import (
- "git.baozhida.cn/ERP_libs/lib"
- "sort"
- )
- // 入库产品mingxi
- type StockProduct struct {
- T_product_id int
- T_num int
- T_relation_sn []string
- }
- type StockProductRelationSn struct {
- T_product_id int
- T_delete_relation_sn []string
- T_add_relation_sn []string
- }
- // 比较两个StockProduct列表是否相等
- func StockProductListsEqual(a, b []StockProduct) (isEqual bool, needDelete, needAdd, needEdit map[int]StockProduct, snDiff map[int]StockProductRelationSn) {
- needDelete = make(map[int]StockProduct)
- needAdd = make(map[int]StockProduct)
- needEdit = make(map[int]StockProduct)
- snDiff = make(map[int]StockProductRelationSn)
- isEqual = false
- // 原始数据
- aMap := make(map[int]StockProduct)
- aProductList := []int{}
- for _, item := range a {
- sort.Strings(item.T_relation_sn)
- aMap[item.T_product_id] = item
- aProductList = append(aProductList, item.T_product_id)
- }
- // 修改提交的数据
- bMap := make(map[int]StockProduct)
- bProductList := []int{}
- for _, item := range b {
- sort.Strings(item.T_relation_sn)
- bMap[item.T_product_id] = item
- bProductList = append(bProductList, item.T_product_id)
- }
- // 查询需要删除的产品 和需要添加的产品
- _, commonIds, needDeleteIds, needAddIds := lib.IntListCompare(aProductList, bProductList)
- for _, product_id := range commonIds {
- equal, _, T_delete_relation_sn, T_add_relation_sn := lib.StringListCompare(aMap[product_id].T_relation_sn, bMap[product_id].T_relation_sn)
- snDiff[product_id] = StockProductRelationSn{
- T_product_id: product_id,
- T_delete_relation_sn: T_delete_relation_sn,
- T_add_relation_sn: T_add_relation_sn,
- }
- if bMap[product_id].T_num != aMap[product_id].T_num && len(bMap[product_id].T_relation_sn) == 0 {
- needEdit[product_id] = bMap[product_id]
- }
- if !equal {
- isEqual = false
- }
- }
- if len(needDelete) == 0 && len(needAdd) == 0 && len(needEdit) == 0 && isEqual {
- isEqual = true
- }
- for _, id := range needDeleteIds {
- needDelete[id] = aMap[id]
- }
- for _, id := range needAddIds {
- needAdd[id] = bMap[id]
- }
- return isEqual, needDelete, needAdd, needEdit, snDiff
- }
|