作者 陈志颖

feat:增加合伙人编号去重

1 appname = partnermg 1 appname = partnermg
2 runmode = "${RUN_MODE||dev}" 2 runmode = "${RUN_MODE||dev}"
3 -httpport = "${HTTP_PORT||8083}" 3 +httpport = "${HTTP_PORT||8082}"
4 4
5 #开启监控 5 #开启监控
6 EnableAdmin = false 6 EnableAdmin = false
@@ -23,7 +23,7 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { @@ -23,7 +23,7 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
23 23
24 /** 24 /**
25 * @Author SteveChan 25 * @Author SteveChan
26 - * @Description //TODO 创建合伙人,判断编号是否重复 26 + * @Description // 创建合伙人
27 * @Date 15:42 2020/12/29 27 * @Date 15:42 2020/12/29
28 * @Param 28 * @Param
29 * @return 29 * @return
@@ -51,6 +51,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -51,6 +51,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
51 }); err != nil { 51 }); err != nil {
52 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 52 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
53 } 53 }
  54 +
54 ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId) 55 ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
55 if err != nil { 56 if err != nil {
56 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 57 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
@@ -59,6 +60,15 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -59,6 +60,15 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
59 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") 60 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
60 } 61 }
61 62
  63 + // 编号去重
  64 + for _, partnerCategory := range cmd.PartnerCategory {
  65 + if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {
  66 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  67 + } else if ok {
  68 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型"+""+"编号"+partnerCategory.Code+"已存在")
  69 + }
  70 + }
  71 +
62 var ( 72 var (
63 partnerInfoRepository domain.PartnerInfoRepository 73 partnerInfoRepository domain.PartnerInfoRepository
64 categoryRepository domain.PartnerCategoryRepository 74 categoryRepository domain.PartnerCategoryRepository
@@ -74,6 +84,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -74,6 +84,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
74 }); err != nil { 84 }); err != nil {
75 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 85 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
76 } 86 }
  87 +
77 var ids []int64 88 var ids []int64
78 for _, partnerCategory := range cmd.PartnerCategory { 89 for _, partnerCategory := range cmd.PartnerCategory {
79 ids = append(ids, partnerCategory.Id) 90 ids = append(ids, partnerCategory.Id)
@@ -85,6 +96,13 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -85,6 +96,13 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
85 e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) 96 e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
86 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 97 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
87 } 98 }
  99 + for i, category := range categories {
  100 + for _, partnerCategory := range cmd.PartnerCategory {
  101 + if category.Id == partnerCategory.Id {
  102 + categories[i].Code = partnerCategory.Code
  103 + }
  104 + }
  105 + }
88 106
89 newPartnerInfo := domain.PartnerInfo{ 107 newPartnerInfo := domain.PartnerInfo{
90 Partner: domain.Partner{ 108 Partner: domain.Partner{
@@ -99,6 +117,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -99,6 +117,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
99 CooperateTime: cmd.CooperateTime, 117 CooperateTime: cmd.CooperateTime,
100 CompanyId: cmd.CompanyId, 118 CompanyId: cmd.CompanyId,
101 PartnerCategoryInfos: categories, 119 PartnerCategoryInfos: categories,
  120 + Remark: cmd.Remark,
102 } 121 }
103 if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil { 122 if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
104 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 123 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
@@ -120,7 +139,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre @@ -120,7 +139,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
120 139
121 /** 140 /**
122 * @Author SteveChan 141 * @Author SteveChan
123 - * @Description //TODO 返回合伙人,增加合伙人编号字段 142 + * @Description // 返回合伙人,增加合伙人编号字段
124 * @Date 15:43 2020/12/29 143 * @Date 15:43 2020/12/29
125 * @Param 144 * @Param
126 * @return 145 * @return
@@ -129,6 +148,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI @@ -129,6 +148,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
129 var ( 148 var (
130 transactionContext, _ = factory.CreateTransactionContext(nil) 149 transactionContext, _ = factory.CreateTransactionContext(nil)
131 ) 150 )
  151 +
132 if err = q.ValidateQuery(); err != nil { 152 if err = q.ValidateQuery(); err != nil {
133 return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) 153 return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
134 } 154 }
@@ -138,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI @@ -138,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
138 defer func() { 158 defer func() {
139 transactionContext.RollbackTransaction() 159 transactionContext.RollbackTransaction()
140 }() 160 }()
  161 +
141 var ( 162 var (
142 PartnerInfoRepository domain.PartnerInfoRepository 163 PartnerInfoRepository domain.PartnerInfoRepository
143 categoryRepository domain.PartnerCategoryRepository 164 categoryRepository domain.PartnerCategoryRepository
144 categories []domain.PartnerCategory 165 categories []domain.PartnerCategory
145 partnerData *domain.PartnerInfo 166 partnerData *domain.PartnerInfo
146 ) 167 )
  168 +
147 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 169 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
148 "transactionContext": transactionContext, 170 "transactionContext": transactionContext,
149 }); err != nil { 171 }); err != nil {
150 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 172 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
151 } 173 }
  174 +
  175 + // 获取合伙人数据
152 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ 176 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
153 UserId: q.Id, CompanyId: q.CompanyId, 177 UserId: q.Id, CompanyId: q.CompanyId,
154 }) 178 })
@@ -158,6 +182,8 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI @@ -158,6 +182,8 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
158 if !partnerData.IsCompany(q.CompanyId) { 182 if !partnerData.IsCompany(q.CompanyId) {
159 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作") 183 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作")
160 } 184 }
  185 +
  186 + // 获取合伙人类别
161 if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ 187 if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
162 "transactionContext": transactionContext, 188 "transactionContext": transactionContext,
163 }); err != nil { 189 }); err != nil {
@@ -174,17 +200,31 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI @@ -174,17 +200,31 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
174 if err != nil { 200 if err != nil {
175 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 201 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
176 } 202 }
  203 + for i, category := range categories {
  204 + for _, partnerCategory := range partnerData.PartnerCategoryInfos {
  205 + if category.Id == partnerCategory.Id {
  206 + categories[i].Code = partnerCategory.Code
  207 + }
  208 + }
  209 + }
177 } 210 }
178 partnerData.PartnerCategoryInfos = categories 211 partnerData.PartnerCategoryInfos = categories
179 err = transactionContext.CommitTransaction() 212 err = transactionContext.CommitTransaction()
180 return partnerData, nil 213 return partnerData, nil
181 } 214 }
182 215
183 -//UpdatePartnerInfo 更新合伙人 216 +/**
  217 + * @Author SteveChan
  218 + * @Description // 更新合伙人
  219 + * @Date 00:07 2020/12/30
  220 + * @Param
  221 + * @return
  222 + **/
184 func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) { 223 func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) {
185 var ( 224 var (
186 transactionContext, _ = factory.CreateTransactionContext(nil) 225 transactionContext, _ = factory.CreateTransactionContext(nil)
187 ) 226 )
  227 +
188 if err = cmd.ValidateCommand(); err != nil { 228 if err = cmd.ValidateCommand(); err != nil {
189 return application.ThrowError(application.ARG_ERROR, err.Error()) 229 return application.ThrowError(application.ARG_ERROR, err.Error())
190 } 230 }
@@ -194,32 +234,62 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -194,32 +234,62 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
194 defer func() { 234 defer func() {
195 transactionContext.RollbackTransaction() 235 transactionContext.RollbackTransaction()
196 }() 236 }()
  237 +
197 var ( 238 var (
198 partnerInfoRepository domain.PartnerInfoRepository 239 partnerInfoRepository domain.PartnerInfoRepository
199 categoryRepository domain.PartnerCategoryRepository 240 categoryRepository domain.PartnerCategoryRepository
200 - categorys []domain.PartnerCategory 241 + categories []domain.PartnerCategory
  242 + partnerInfoDao *dao.PartnerInfoDao
201 ) 243 )
  244 +
  245 + if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
  246 + "transactionContext": transactionContext,
  247 + }); err != nil {
  248 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  249 + }
  250 +
202 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 251 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
203 "transactionContext": transactionContext, 252 "transactionContext": transactionContext,
204 }); err != nil { 253 }); err != nil {
205 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 254 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
206 } 255 }
  256 +
207 if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ 257 if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
208 "transactionContext": transactionContext, 258 "transactionContext": transactionContext,
209 }); err != nil { 259 }); err != nil {
210 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 260 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
211 } 261 }
  262 +
  263 + // 编号去重
  264 + for _, partnerCategory := range cmd.PartnerCategory {
  265 + if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil {
  266 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  267 + } else if ok {
  268 + return lib.ThrowError(lib.BUSINESS_ERROR, "编号"+partnerCategory.Code+"已存在")
  269 + }
  270 + }
  271 +
212 var ids []int64 272 var ids []int64
213 for _, partnerCategory := range cmd.PartnerCategory { 273 for _, partnerCategory := range cmd.PartnerCategory {
214 ids = append(ids, partnerCategory.Id) 274 ids = append(ids, partnerCategory.Id)
215 } 275 }
216 - _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ 276 +
  277 + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
217 Ids: ids, 278 Ids: ids,
218 }) 279 })
219 if err != nil { 280 if err != nil {
220 e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) 281 e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
221 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 282 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
222 } 283 }
  284 +
  285 + for i, category := range categories {
  286 + for _, partnerCategory := range cmd.PartnerCategory {
  287 + if category.Id == partnerCategory.Id {
  288 + categories[i].Code = partnerCategory.Code
  289 + }
  290 + }
  291 + }
  292 +
223 partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ 293 partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
224 UserId: cmd.Id, 294 UserId: cmd.Id,
225 CompanyId: cmd.CompanyId, 295 CompanyId: cmd.CompanyId,
@@ -230,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -230,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
230 if !partnerInfo.IsCompany(cmd.CompanyId) { 300 if !partnerInfo.IsCompany(cmd.CompanyId) {
231 return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作") 301 return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
232 } 302 }
  303 +
233 partnerInfo.Salesman = cmd.Salesman 304 partnerInfo.Salesman = cmd.Salesman
234 partnerInfo.Status = cmd.Status 305 partnerInfo.Status = cmd.Status
235 partnerInfo.RegionInfo = *cmd.RegionInfo 306 partnerInfo.RegionInfo = *cmd.RegionInfo
236 partnerInfo.CooperateTime = cmd.CooperateTime 307 partnerInfo.CooperateTime = cmd.CooperateTime
237 - partnerInfo.PartnerCategoryInfos = categorys 308 + partnerInfo.PartnerCategoryInfos = categories
  309 + partnerInfo.Remark = cmd.Remark
  310 +
238 if err = partnerInfoRepository.Save(partnerInfo); err != nil { 311 if err = partnerInfoRepository.Save(partnerInfo); err != nil {
239 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 312 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
240 } 313 }
@@ -254,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -254,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
254 return 327 return
255 } 328 }
256 329
257 -// ListPartnerInfo 合伙人列表 330 +/**
  331 + * @Author SteveChan
  332 + * @Description //合伙人列表,返回合伙人编号
  333 + * @Date 00:07 2020/12/30
  334 + * @Param
  335 + * @return
  336 + **/
258 func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) { 337 func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) {
259 var ( 338 var (
260 transactionContext, _ = factory.CreateTransactionContext(nil) 339 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -318,6 +397,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue @@ -318,6 +397,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
318 var categoryInPartner []domain.PartnerCategory 397 var categoryInPartner []domain.PartnerCategory
319 for _, vv := range partnerInfos[i].PartnerCategoryInfos { 398 for _, vv := range partnerInfos[i].PartnerCategoryInfos {
320 if categoryData, ok := categoriesMap[vv.Id]; ok { 399 if categoryData, ok := categoriesMap[vv.Id]; ok {
  400 + categoryData.Code = vv.Code
321 categoryInPartner = append(categoryInPartner, categoryData) 401 categoryInPartner = append(categoryInPartner, categoryData)
322 } 402 }
323 } 403 }
@@ -350,6 +430,23 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo @@ -350,6 +430,23 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo
350 transactionContext.RollbackTransaction() 430 transactionContext.RollbackTransaction()
351 }() 431 }()
352 432
  433 + var (
  434 + partnerInfoRepository domain.PartnerInfoRepository
  435 + )
  436 +
  437 + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  438 + "transactionContext": transactionContext,
  439 + }); err != nil {
  440 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  441 + }
  442 +
  443 + // 判断合伙人是否有业务数据
  444 +
  445 + if err = partnerInfoRepository.Remove(cmd.Id); err != nil {
  446 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  447 + }
  448 +
  449 + transactionContext.CommitTransaction()
353 return nil 450 return nil
354 } 451 }
355 452
@@ -4,9 +4,9 @@ import "os" @@ -4,9 +4,9 @@ import "os"
4 4
5 var POSTGRESQL_DB_NAME = "partner_test" 5 var POSTGRESQL_DB_NAME = "partner_test"
6 var POSTGRESQL_USER = "postgres" 6 var POSTGRESQL_USER = "postgres"
7 -var POSTGRESQL_PASSWORD = "eagle1010"  
8 -var POSTGRESQL_HOST = "114.55.200.59"  
9 -var POSTGRESQL_PORT = "31543" 7 +var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010
  8 +var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59
  9 +var POSTGRESQL_PORT = "5432" // 31543
10 var DISABLE_CREATE_TABLE = true 10 var DISABLE_CREATE_TABLE = true
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
@@ -74,6 +74,7 @@ type PartnerFindQuery struct { @@ -74,6 +74,7 @@ type PartnerFindQuery struct {
74 PartnerName string //合伙人姓名 74 PartnerName string //合伙人姓名
75 CompanyId int64 75 CompanyId int64
76 Ids []int64 76 Ids []int64
  77 + PartnerType []*PartnerCategory
77 } 78 }
78 79
79 type PartnerInfoRepository interface { 80 type PartnerInfoRepository interface {
@@ -2,7 +2,7 @@ package dao @@ -2,7 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - 5 + "github.com/go-pg/pg/v10"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
8 ) 8 )
@@ -28,7 +28,6 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) ( @@ -28,7 +28,6 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) (
28 Where("account=?", account). 28 Where("account=?", account).
29 Where("company_id=?", companyId). 29 Where("company_id=?", companyId).
30 Exists() 30 Exists()
31 -  
32 return ok, err 31 return ok, err
33 } 32 }
34 33
@@ -45,11 +44,18 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat @@ -45,11 +44,18 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat
45 44
46 /** 45 /**
47 * @Author SteveChan 46 * @Author SteveChan
48 - * @Description //TODO 编号查重 47 + * @Description // 编号查重
49 * @Date 17:55 2020/12/28 48 * @Date 17:55 2020/12/28
50 * @Param 49 * @Param
51 * @return 50 * @return
52 **/ 51 **/
53 -func (dao PartnerInfoDao) CheckDuplication() {  
54 - 52 +func (dao PartnerInfoDao) PartnerCodeExist(categoryId int64, code string, companyId int64, id int64) (bool, error) {
  53 + tx := dao.transactionContext.PgDd
  54 + m := &models.PartnerInfo{}
  55 + ok, err := tx.Model(m).
  56 + Where(`partner_category_infos@> '[{"id":?,"code":?}]'`, categoryId, pg.Ident(code)).
  57 + Where("company_id=?", companyId).
  58 + Where("id <> ?", id).
  59 + Exists()
  60 + return ok, err
55 } 61 }
@@ -55,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { @@ -55,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
55 } else { 55 } else {
56 _, err = tx.Model(m).WherePK(). 56 _, err = tx.Model(m).WherePK().
57 Column("partner_name", "account", "password", "status", "partner_category", "salesman", 57 Column("partner_name", "account", "password", "status", "partner_category", "salesman",
58 - "region_info", "cooperate_time", "update_at", "partner_category_infos, remark"). 58 + "region_info", "cooperate_time", "update_at", "partner_category_infos", "remark").
59 Update() 59 Update()
60 if err != nil { 60 if err != nil {
61 return err 61 return err
@@ -43,6 +43,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -43,6 +43,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
43 CooperationTime string `json:"cooperationTime"` 43 CooperationTime string `json:"cooperationTime"`
44 SalesmanName string `json:"salesmanName"` 44 SalesmanName string `json:"salesmanName"`
45 Phone string `json:"phone"` 45 Phone string `json:"phone"`
  46 + Remark string `json:"remark"`
46 } 47 }
47 var ( 48 var (
48 param Parameter 49 param Parameter
@@ -69,6 +70,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -69,6 +70,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
69 PartnerCategory: param.PartnerType, 70 PartnerCategory: param.PartnerType,
70 CooperateTime: cooperateTime, 71 CooperateTime: cooperateTime,
71 CompanyId: companyId, 72 CompanyId: companyId,
  73 + Remark: param.Remark,
72 } 74 }
73 if len(param.SalesmanName) > 0 || len(param.Phone) > 0 { 75 if len(param.SalesmanName) > 0 || len(param.Phone) > 0 {
74 cmd.Salesman = []domain.Salesman{ 76 cmd.Salesman = []domain.Salesman{
@@ -110,6 +112,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -110,6 +112,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
110 CooperationTime string `json:"cooperationTime"` 112 CooperationTime string `json:"cooperationTime"`
111 SalesmanName string `json:"salesmanName"` 113 SalesmanName string `json:"salesmanName"`
112 Phone string `json:"phone"` 114 Phone string `json:"phone"`
  115 + Remark string `json:"remark"`
113 } 116 }
114 var ( 117 var (
115 param Parameter 118 param Parameter
@@ -142,6 +145,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -142,6 +145,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
142 }, 145 },
143 }, 146 },
144 CompanyId: companyId, 147 CompanyId: companyId,
  148 + Remark: param.Remark,
145 } 149 }
146 serve := partnerInfoService.NewPartnerInfoService(nil) 150 serve := partnerInfoService.NewPartnerInfoService(nil)
147 err = serve.UpdatePartnerInfo(&cmd) 151 err = serve.UpdatePartnerInfo(&cmd)
@@ -190,6 +194,7 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -190,6 +194,7 @@ func (c *PartnerInfoController) GetPartnerInfo() {
190 "cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"), 194 "cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"),
191 "state": partnerInfo.Status, 195 "state": partnerInfo.Status,
192 "id": partnerInfo.Partner.Id, 196 "id": partnerInfo.Partner.Id,
  197 + "remark": partnerInfo.Remark,
193 } 198 }
194 if len(partnerInfo.Salesman) > 0 { 199 if len(partnerInfo.Salesman) > 0 {
195 rspResult["salesmanName"] = partnerInfo.Salesman[0].Name 200 rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
@@ -217,7 +222,30 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -217,7 +222,30 @@ func (c *PartnerInfoController) GetPartnerInfo() {
217 * @return 222 * @return
218 **/ 223 **/
219 func (c *PartnerInfoController) RemovePartnerInfo() { 224 func (c *PartnerInfoController) RemovePartnerInfo() {
220 - 225 + //用与适配前端定义的数据结构
  226 + type Parameter struct {
  227 + ID int64 `json:"id"`
  228 + }
  229 + var (
  230 + param Parameter
  231 + err error
  232 + )
  233 + if err = c.BindJsonData(&param); err != nil {
  234 + logs.Error(err)
  235 + c.ResponseError(errors.New("json数据解析失败"))
  236 + return
  237 + }
  238 + cmd := partnerInfoCmd.RemovePartnerInfoCommand{
  239 + Id: param.ID,
  240 + }
  241 + serve := partnerInfoService.NewPartnerInfoService(nil)
  242 + err = serve.RemovePartnerInfo(cmd)
  243 + if err != nil {
  244 + c.ResponseError(err)
  245 + return
  246 + }
  247 + c.ResponseData(nil)
  248 + return
221 } 249 }
222 250
223 //PartnerInfoSetState 合伙人批量禁用.启用 251 //PartnerInfoSetState 合伙人批量禁用.启用
@@ -321,6 +349,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { @@ -321,6 +349,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
321 "partnerType": partners[i].PartnerCategoryInfos, 349 "partnerType": partners[i].PartnerCategoryInfos,
322 "salesmanName": "", 350 "salesmanName": "",
323 "phone": "", 351 "phone": "",
  352 + "remark": partners[i].Remark,
324 } 353 }
325 if len(partners[i].Salesman) > 0 { 354 if len(partners[i].Salesman) > 0 {
326 m["salesmanName"] = partners[i].Salesman[0].Name 355 m["salesmanName"] = partners[i].Salesman[0].Name
@@ -23,7 +23,7 @@ func init() { @@ -23,7 +23,7 @@ func init() {
23 beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"), 23 beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
24 beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), 24 beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
25 beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), 25 beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
26 - beego.NSRouter("/:id", &controllers.PartnerInfoController{}, "DELETE:RemovePartnerInfo"), 26 + beego.NSRouter("/remove", &controllers.PartnerInfoController{}, "POST:RemovePartnerInfo"),
27 ), 27 ),
28 beego.NSNamespace("/dividends", 28 beego.NSNamespace("/dividends",
29 beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), 29 beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),