| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package family
- import (
- "encoding/json"
- "strings"
- "dashoo.cn/backend/api/business/customer"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/utils"
- )
- type CustomerController struct {
- BaseController
- }
- //保存附件UI model
- type contractFormmodel struct {
- PId int
- AttachmodelList []customer.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 []customer.Customer
- svc := customer.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 customer.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 := customer.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 customer.Customer
- svc := customer.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 customer.Customer
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var entityempty customer.Customer
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := customer.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 := customer.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 := customer.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 customer.CellsContractAttachment
- attachmodel.CreateBy = this.User.Realname
- attachmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- attachmodel.PId = upmodel.PId
- svc := customer.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 := customer.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 := customer.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 customer.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()
- }
|