|
|
@@ -0,0 +1,323 @@
|
|
|
+package lims
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ . "dashoo.cn/backend/api/controllers"
|
|
|
+ customer2 "dashoo.cn/backend/api/business/customer"
|
|
|
+ "dashoo.cn/utils"
|
|
|
+)
|
|
|
+
|
|
|
+type CustomerController struct {
|
|
|
+ BaseController
|
|
|
+}
|
|
|
+// 附件model
|
|
|
+type ContractAttachmentarrt struct {
|
|
|
+ Host string
|
|
|
+ FileId string
|
|
|
+ FileName string
|
|
|
+ FileSize int32
|
|
|
+ UploadDesc string
|
|
|
+}
|
|
|
+
|
|
|
+//保存附件UI model
|
|
|
+type contractFormmodel struct {
|
|
|
+ PId int
|
|
|
+ AttachmodelList []ContractAttachmentarrt // 上传附件
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 根据用户AccCode get检验主表 客户原始信息内容
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object} models.Userblood
|
|
|
+// @router /customerlist [get]
|
|
|
+func (this *CustomerController) Customerlist() {
|
|
|
+ page := this.GetPageInfoForm()
|
|
|
+ danwei := this.GetString("danwei")
|
|
|
+ lianxiren := this.GetString("lianxiren")
|
|
|
+ telephone := this.GetString("telephone")
|
|
|
+ CreateBy := this.GetString("CreateBy")
|
|
|
+ var list []customer2.Customer
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ where := " 1=1 "
|
|
|
+ orderby := "Id"
|
|
|
+ asc := false
|
|
|
+ Order := this.GetString("Order")
|
|
|
+ Prop := this.GetString("Prop")
|
|
|
+ if Order != "" && Prop != "" {
|
|
|
+ orderby = Prop
|
|
|
+ if Order == "asc" {
|
|
|
+ asc = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if danwei != "" {
|
|
|
+ where = where + " and CustomerName like '%" + danwei + "%'"
|
|
|
+ }
|
|
|
+ if CreateBy != "" {
|
|
|
+ where = where + " and CreateBy like '%" + CreateBy + "%'"
|
|
|
+ }
|
|
|
+ if lianxiren != "" {
|
|
|
+ where = where + " and Person like '%" + lianxiren + "%'"
|
|
|
+ }
|
|
|
+ if telephone != "" {
|
|
|
+ where = where + " and Telephone like '%" + telephone + "%'"
|
|
|
+ }
|
|
|
+ CreateOn := this.GetString("CreateOn")
|
|
|
+ if CreateOn != "" {
|
|
|
+ dates := strings.Split(CreateOn, ",")
|
|
|
+ if len(dates) == 2 {
|
|
|
+ minDate := dates[0]
|
|
|
+ maxDate := dates[1]
|
|
|
+ where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = list
|
|
|
+ datainfo.CurrentItemCount = total
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 添加客户原始信息内容
|
|
|
+// @Description 新增客户原始信息内容
|
|
|
+// @Param body body business.device.DeviceChannels "客户原始信息内容"
|
|
|
+// @Success 200 {object} controllers.Request
|
|
|
+// @router /customerlistadd [post]
|
|
|
+func (this *CustomerController) Customerlistadd() {
|
|
|
+ var testlistentity customer2.Customer
|
|
|
+ var jsonblob = this.Ctx.Input.RequestBody
|
|
|
+ json.Unmarshal(jsonblob, &testlistentity)
|
|
|
+ testlistentity.CreateBy = this.User.Realname
|
|
|
+ testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
|
|
|
+ testlistentity.AuthCode = utils.GetGuid()
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ _, err := svc.InsertEntityBytbl(this.User.AccCode+CustomerName, &testlistentity)
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "操作成功!"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 获取编辑时的客户原始信息内容
|
|
|
+// @Description 获取编辑时的客户原始信息内容
|
|
|
+// @Success 200 {object} business.device.DeviceChannels
|
|
|
+// @router /getcustomerlist/:id [get]
|
|
|
+func (this *CustomerController) Getcustomerlist() {
|
|
|
+ id := this.Ctx.Input.Param(":id")
|
|
|
+ var model customer2.Customer
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ svc.GetEntityByIdBytbl(this.User.AccCode+CustomerName, id, &model) //修改时获取列表
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = model
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 编辑试管信息
|
|
|
+// @Description 编辑试管信息
|
|
|
+// @Param id path string true "需要修改的试管信息"
|
|
|
+// @Param body body business.device.DeviceChannels "试管信息"
|
|
|
+// @Success 200 {object} controllers.Request
|
|
|
+// @router /customerlistedit/:id [put]
|
|
|
+func (this *CustomerController) Customerlistedit() {
|
|
|
+ id := this.Ctx.Input.Param(":id")
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if id == "" {
|
|
|
+ errinfo.Message = "操作失败!请求信息不完整"
|
|
|
+ errinfo.Code = -2
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var model customer2.Customer
|
|
|
+ var jsonblob = this.Ctx.Input.RequestBody
|
|
|
+ json.Unmarshal(jsonblob, &model)
|
|
|
+ var entityempty customer2.Customer
|
|
|
+ model.ModifiedBy = this.User.Realname
|
|
|
+ model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+
|
|
|
+ opdesc := "检验-" + model.Person
|
|
|
+ var cols []string = []string{"CustomerName", "Person", "Telephone", "Mailbox", "Address", "AuthCode", "CustomerName", "CustomerCode", "Established", "EmployeesNum", "EnterpriseType", "ZipCode", "FaxTelephone", "Website", "Representative", "MainBusiness", "ViceBusiness", "ModifiedBy", "ModifiedUserId"}
|
|
|
+ err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+CustomerName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "客户管理")
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "操作成功!"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 删除单条信息
|
|
|
+// @Description
|
|
|
+// @Success 200 {object} ErrorInfo
|
|
|
+// @Failure 403 :id 为空
|
|
|
+// @router /customerlistdelete/:Id [delete]
|
|
|
+func (this *CustomerController) Customerlistdelete() {
|
|
|
+ Id := this.Ctx.Input.Param(":Id")
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if Id == "" {
|
|
|
+ errinfo.Message = "操作失败!请求信息不完整"
|
|
|
+ errinfo.Code = -2
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ where := " Id= " + Id
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ err := svc.DeleteEntityBytbl(this.User.AccCode+CustomerName, where)
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "删除成功"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 判断合同是否存在
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object} models.Userblood
|
|
|
+// @router /contractNoorlist [get]
|
|
|
+func (this *CustomerController) ContractNoorlist() {
|
|
|
+ ContractNo := this.GetString("ContractNo")
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ where := " ContractNo= '" + ContractNo + "'"
|
|
|
+ total := svc.GetContractNo(this.User.AccCode+CellsContractName, where)
|
|
|
+
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = total
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 保存附件
|
|
|
+// @Description 保存附件
|
|
|
+// @Success 200 {object}
|
|
|
+// @router /savesampleattach [put]
|
|
|
+func (this *CustomerController) SaveSampleAttach() {
|
|
|
+ // 获得前端传输的model
|
|
|
+ var jsonblob = this.Ctx.Input.RequestBody
|
|
|
+ var upmodel contractFormmodel
|
|
|
+ json.Unmarshal(jsonblob, &upmodel)
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if len(upmodel.AttachmodelList) == 0 {
|
|
|
+ errinfo.Message = "上传失败!无附件信息"
|
|
|
+ errinfo.Code = -3
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //---附件---
|
|
|
+ var attachmodel customer2.CellsContractAttachment
|
|
|
+ attachmodel.CreateBy = this.User.Realname
|
|
|
+ attachmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
|
|
|
+ attachmodel.PId = upmodel.PId
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ var err error
|
|
|
+ for _, val := range upmodel.AttachmodelList {
|
|
|
+
|
|
|
+ attachmodel.FileId = val.FileId
|
|
|
+ attachmodel.FileName = val.FileName
|
|
|
+ attachmodel.FileSize = val.FileSize
|
|
|
+ attachmodel.Host = val.Host
|
|
|
+ attachmodel.UploadDesc = val.UploadDesc
|
|
|
+ _, err = svc.InsertEntityBytbl(this.User.AccCode+CellsContractAttachmentName, &attachmodel)
|
|
|
+ }
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "保存成功"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "上传失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 质量管理根据id信息查询附件
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object} models.Userblood
|
|
|
+// @router /getcontractAttachment [get]
|
|
|
+func (this *CustomerController) GetcontractAttachment() {
|
|
|
+ PId := this.GetString("PId")
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+ where := " PId= '" + PId + "'"
|
|
|
+ total := svc.GetCustomerAttachment(this.User.AccCode+CellsContractAttachmentName, where)
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = total
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 根据id删除合同管理附件
|
|
|
+// @Description
|
|
|
+// @Success 200 {object} ErrorInfo
|
|
|
+// @Failure 403 :id 为空
|
|
|
+// @router /contractAttachmentdeletearrt/:Id [delete]
|
|
|
+func (this *CustomerController) ContractAttachmentdeletearrt() {
|
|
|
+ Id := this.Ctx.Input.Param(":Id")
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if Id == "" {
|
|
|
+ errinfo.Message = "操作失败!请求信息不完整"
|
|
|
+ errinfo.Code = -2
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ where := " PId= " + Id
|
|
|
+ svc := customer2.GetCustomerService(utils.DBE)
|
|
|
+
|
|
|
+ err := svc.DeleteEntityBytbl(this.User.AccCode+CellsContractAttachmentName, where)
|
|
|
+
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "删除成功"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 更改用户授权码
|
|
|
+// @Description 更改用户授权码
|
|
|
+// @Param body body business.device.DeviceChannels "更改用户授权码"
|
|
|
+// @Success 200 {object} controllers.Request
|
|
|
+// @router /authCodeedit [get]
|
|
|
+func (this *CustomerController) GetauthCode() {
|
|
|
+ var testlistentity customer2.Customer
|
|
|
+ var jsonblob = this.Ctx.Input.RequestBody
|
|
|
+ json.Unmarshal(jsonblob, &testlistentity)
|
|
|
+ testlistentity.AuthCode = utils.GetGuid()
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = testlistentity.AuthCode
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+
|
|
|
+}
|