main
elf 2 months ago
parent 049d3160f4
commit 7a09571fdc

@ -215,3 +215,19 @@ func GetOrderNo(c *gin.Context) (result.Data, error) {
orderNo := utils.GenerateNo("order")
return result.Data{"orderNo": orderNo}, nil
}
func SaveStudentInsureInfo(c *gin.Context) (result.Data, error) {
req := request.StudentInsureInfoRequest{}
err := c.ShouldBind(&req)
if err != nil {
return nil, e.NewError("参数错误")
}
_, err = service.StudentInsureService.Save(req)
if err != nil {
return nil, e.NewError("保存错误")
}
return result.Data{}, nil
}

@ -91,6 +91,14 @@ func Surrend(c *gin.Context) {
return
}
/*orderResult, err := service.OrderService.GetOrderResultByPolicyNo(param.Data.PolicyNo)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}*/
revoke, err := service.OrderService.SaveRevoke(param)
if err != nil {
result["code"] = 501
@ -107,6 +115,8 @@ func Surrend(c *gin.Context) {
return
}
//service.OrderService.UpdateOrderAfterRevoke(orderResult.OrderNo)
c.JSON(200, result)
return
}
@ -140,6 +150,14 @@ func Claim(c *gin.Context) {
return
}
/*orderResult, err := service.OrderService.GetOrderResultByPolicyNo(param.Data.PolicyNo)
if err != nil {
result["code"] = 501
result["msg"] = err.Error()
c.JSON(200, result)
return
}*/
claim, err := service.OrderService.SaveClaim(param)
if err != nil {
result["code"] = 501
@ -156,6 +174,8 @@ func Claim(c *gin.Context) {
return
}
//service.OrderService.UpdateOrderAfterClaim(orderResult.OrderNo)
c.JSON(200, result)
return
}

@ -143,9 +143,22 @@ func Revoke(c *gin.Context) {
return
}
orderResult, err := service.OrderService.GetOrderResultByPolicyNo(revokeData.PolicyNo)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "数据异常"
c.JSON(200, result)
return
}
global.DB.Model(&model.Revoke{}).Where("policy_no", revokeData.PolicyNo).UpdateColumns(model.Revoke{Status: revokeData.Status, Msg: revokeData.Msg})
fmt.Println("revokeData", revokeData)
if revokeData.Status == "7" {
service.OrderService.UpdateOrderAfterRevoke(orderResult.OrderNo)
}
callbackParam := suixing.RevokeCallbackParam{}
callbackParam.AppID = global.Config.Suixing.AppID
callbackParam.RequestID = utils.GenerateNo("requestId")
@ -193,9 +206,22 @@ func Claim(c *gin.Context) {
return
}
orderResult, err := service.OrderService.GetOrderResultByPolicyNo(claimData.PolicyNo)
if err != nil {
fmt.Println(err.Error())
result["code"] = 201
result["msg"] = "数据异常"
c.JSON(200, result)
return
}
global.DB.Model(&model.Claim{}).Where("policy_no", claimData.PolicyNo).UpdateColumns(model.Claim{Status: claimData.Status, Msg: claimData.Msg})
fmt.Println("claimData", claimData)
if claimData.Status == "2" {
service.OrderService.UpdateOrderAfterClaim(orderResult.OrderNo)
}
callbackParam := suixing.ClaimCallbackParam{}
callbackParam.AppID = global.Config.Suixing.AppID
callbackParam.RequestID = utils.GenerateNo("requestId")

@ -18,4 +18,5 @@ type OrderQueryRequest struct {
InsureTimeStart string `form:"insureTimeStart"`
InsureTimeEnd string `form:"insureTimeEnd"`
CreatedAt string `form:"createdAt"`
Status string `form:"status"`
}

@ -0,0 +1,15 @@
package manage
type StudentInsureInfoQueryRequest struct {
SchoolName string `json:"schoolName" form:"schoolName"`
StudentName string `json:"studentName" form:"studentName"`
StudentIdentityNo string `json:"studentIdentityNo" form:"studentIdentityNo"`
ParentName string `json:"parentName" form:"parentName"`
College string `json:"college" form:"college"`
Speciality string `json:"speciality" form:"speciality"`
Class string `json:"class" form:"class"`
ParentIdentityNo string `json:"parentIdentityNo" form:"parentIdentityNo"`
ParentMobile string `json:"parentMobile" form:"parentMobile"`
UpdatedAtStart string `json:"updatedAtStart" form:"updatedAtStart"`
UpdatedAtEnd string `json:"updatedAtEnd" form:"updatedAtEnd"`
}

@ -0,0 +1,16 @@
package request
type StudentInsureInfoRequest struct {
SchoolName string `json:"schoolName" form:"schoolName"`
StudentName string `json:"studentName" form:"studentName"`
StudentIdentityNo string `json:"studentIdentityNo" form:"studentIdentityNo"`
StudentIdentityType uint `json:"studentIdentityType" form:"studentIdentityType"`
ParentName string `json:"parentName" form:"parentName"`
College string `json:"college" form:"college"`
Speciality string `json:"speciality" form:"speciality"`
Class string `json:"class" form:"class"`
Relation string `json:"relation" form:"relation"`
ParentIdentityNo string `json:"parentIdentityNo" form:"parentIdentityNo"`
ParentIdentityType uint `json:"parentIdentityType" form:"parentIdentityType"`
ParentMobile string `json:"parentMobile" form:"parentMobile"`
}

BIN
insure

Binary file not shown.

@ -266,4 +266,24 @@ CREATE TABLE `claim` (
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `udx_policyno` (`policy_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='理赔记录';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='理赔记录';
CREATE TABLE `student_insure_info` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`school_name` varchar(64) NOT NULL DEFAULT '' COMMENT '学校名称',
`student_name` varchar(64) NOT NULL DEFAULT '' COMMENT '学生姓名',
`student_identity_no` varchar(32) NOT NULL DEFAULT '' COMMENT '学生证件号',
`student_identity_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '学生证件类型',
`college` varchar(150) NOT NULL DEFAULT '' COMMENT '学院',
`speciality` varchar(150) NOT NULL DEFAULT '' COMMENT '专业',
`class` varchar(150) NOT NULL DEFAULT '' COMMENT '班级',
`relation` varchar(64) NOT NULL DEFAULT '' COMMENT '家长与学生关系',
`parent_name` varchar(64) NOT NULL DEFAULT '' COMMENT '家长姓名',
`parent_identity_no` varchar(32) NOT NULL DEFAULT '' COMMENT '家长证件号',
`parent_identity_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '家长证件类型',
`parent_mobile` varchar(11) NOT NULL DEFAULT '' COMMENT '家长电话',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `udx_identity` (`student_identity_no`,`student_identity_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='学生投保信息';

@ -51,6 +51,10 @@ func (a Order) GetStatusText() string {
return "待提交"
} else if a.Status == "signed" {
return "待提交"
} else if a.Status == "revoked" {
return "已退保"
} else if a.Status == "claimed" {
return "已理赔"
}
return "待提交"
}

@ -0,0 +1,41 @@
package model
import (
"encoding/json"
"time"
)
type StudentInsureInfo struct {
ID int
SchoolName string
StudentName string
StudentIdentityNo string
StudentIdentityType uint
ParentName string
College string
Speciality string
Class string
Relation string
ParentIdentityNo string
ParentIdentityType uint
ParentMobile string
CreatedAt time.Time
UpdatedAt time.Time `json:"-"`
}
func (StudentInsureInfo) TableName() string {
return "student_insure_info"
}
func (a StudentInsureInfo) MarshalJSON() ([]byte, error) {
type Alias StudentInsureInfo
return json.Marshal(&struct {
CreatedAt string
UpdatedAt string
*Alias
}{
CreatedAt: a.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: a.UpdatedAt.Format("2006-01-02 15:04:05"),
Alias: (*Alias)(&a),
})
}

@ -250,6 +250,22 @@ func (s *orderService) GetOrderByOrderSn(orderSn string) (*model.Order, error) {
return &order, nil
}
func (s *orderService) GetOrderResultByPolicyNo(policyNo string) (*model.OrderResult, error) {
orderResult := model.OrderResult{}
err := global.DB.
Where("policy_no", policyNo).
First(&orderResult).
Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, e.NewError("记录不存在")
} else {
return nil, e.NewError("数据异常")
}
}
return &orderResult, nil
}
func (s *orderService) AddSignLog(orderNo string, param signer.UploadParam) (*model.SignLog, error) {
var err error
isUploadPdf := 1
@ -561,14 +577,14 @@ func (s *orderService) GetOrders(req manage.OrderQueryRequest) ([]model.Order, i
orders := make([]model.Order, req.PageSize)
offset := (req.Page - 1) * req.PageSize
var total int64
tx := s.buildQuery(req)
tx.Preload("User").
s.buildQuery(req).Preload("User").
Preload("Project").
Preload("Applicant").
Preload("Assured").
Preload("OrderResult").
Preload("Invoice").
Order("id desc").Offset(offset).Limit(req.PageSize).Find(&orders)
tx.Model(&model.Order{}).Count(&total)
s.buildQuery(req).Model(&model.Order{}).Count(&total)
return orders, total
}
func (s *orderService) buildQuery(req manage.OrderQueryRequest) *gorm.DB {
@ -646,31 +662,82 @@ func (s *orderService) buildQuery(req manage.OrderQueryRequest) *gorm.DB {
global.DB.Model(&model.OrderResult{}).Where("policy_no", req.PolicyNo).Pluck("order_sn", &orderSns)
tx = tx.Where("order_sn in (?)", orderSns)
}
if req.Status != "" {
statusMap := map[string][]string{
"payed": []string{"payed"},
"wait_submit": []string{"initial", "generated", "signed"},
"wait_pay": []string{"submitted"},
"claimed": []string{"claimed"},
"revoked": []string{"revoked"},
}
statusList := statusMap[req.Status]
tx = tx.Where("status in (?)", statusList)
}
return tx
}
func (s *orderService) GenerateOrdersExcel(req manage.OrderQueryRequest) *excelize.File {
pageSize := 200
lastID := 0
tx := s.buildQuery(req)
f := excel.NewFile()
headers := []string{"订单号", "项目订单编号", "项目来源", "招标项目编号", "项目名称", "保险公司", "保险产品", "保/批单号", "招标人", "投标人", "出函时间", "起保时间", "保函天数", "保费", "保额", "保单状态"}
headers := []string{
"订单号",
"项目订单编号",
"项目来源",
"招标项目编号",
"项目名称",
"标段编号",
"标段名称",
"保险公司",
"保险产品",
"保/批单号",
"招标人",
"招标人-联系人姓名",
"招标人-联系人手机号",
"代理机构",
"投标人",
"统一社会信用代码",
"投标人-联系人姓名",
"投标人-联系人手机号",
"投标人-开户行(基本户)",
"投标人-银行账号",
"接收发票的邮箱",
"出函时间",
"起保时间",
"保函天数",
"保费",
"保额",
"保单状态",
"发票抬头",
"税号",
}
excel.SetSimpleHeaders(headers, "Sheet1", f)
var allOrders []model.Order
for {
orders := make([]model.Order, pageSize)
tx.Preload("User").
s.buildQuery(req).Preload("User").
Preload("Project").
Preload("Applicant").
Preload("Assured").Where("id > ?", lastID).Limit(pageSize).Find(&orders)
Preload("Assured").
Preload("OrderResult").
Where("id > ?", lastID).
Order("id asc").
Limit(pageSize).
Find(&orders)
count := len(orders)
if count == 0 {
break
}
s.buildOrdersExcel(orders, "Sheet1", f)
lastIndex := count - 1
lastID = orders[lastIndex].ID
fmt.Println("lastID", lastID)
allOrders = append(allOrders, orders...)
}
s.buildOrdersExcel(allOrders, "Sheet1", f)
return f
}
@ -685,29 +752,65 @@ func (orderService) buildOrdersExcel(orders []model.Order, sheet string, f *exce
policyCreatedAt = order.OrderResult.CreatedAt.Format(time.DateTime)
}
assuredName := ""
assuredContactMobile := ""
assuredContactName := ""
assuredAgency := ""
if order.Assured != nil {
assuredName = order.Assured.AssuredName
assuredContactMobile = order.Assured.ContactMobile
assuredContactName = order.Assured.ContactName
assuredAgency = order.Assured.Agency
}
applicantName := ""
applicantContactMobile := ""
applicantContactName := ""
applicantCreditCode := ""
invoiceAcceptEmail := ""
if order.Applicant != nil {
applicantName = order.Applicant.ApplicantName
applicantContactMobile = order.Applicant.ContactMobile
applicantContactName = order.Applicant.ContactName
applicantCreditCode = order.Applicant.CreditCode
invoiceAcceptEmail = order.Applicant.InvoiceAcceptEmail
}
invoiceHeader := ""
invoiceTaxNumber := ""
if order.Invoice != nil {
invoiceHeader = order.Invoice.Header
invoiceTaxNumber = order.Invoice.TaxNumber
}
if order.Project == nil {
order.Project = &model.Project{}
}
f.SetCellValue(sheet, excel.CellKey(row, &col), order.OrderNo)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.OrderSn)
f.SetCellValue(sheet, excel.CellKey(row, &col), "易交易电子信息交易中心")
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.TpID)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.Name)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.BdID)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.BdName)
f.SetCellValue(sheet, excel.CellKey(row, &col), "紫金财产保险股份有限公司福建分公司")
f.SetCellValue(sheet, excel.CellKey(row, &col), "投标保证保险")
f.SetCellValue(sheet, excel.CellKey(row, &col), policyNo)
f.SetCellValue(sheet, excel.CellKey(row, &col), assuredName)
f.SetCellValue(sheet, excel.CellKey(row, &col), assuredContactName)
f.SetCellValue(sheet, excel.CellKey(row, &col), assuredContactMobile)
f.SetCellValue(sheet, excel.CellKey(row, &col), assuredAgency)
f.SetCellValue(sheet, excel.CellKey(row, &col), applicantName)
f.SetCellValue(sheet, excel.CellKey(row, &col), applicantCreditCode)
f.SetCellValue(sheet, excel.CellKey(row, &col), applicantContactName)
f.SetCellValue(sheet, excel.CellKey(row, &col), applicantContactMobile)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.User.BankName)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.User.BankCardNum)
f.SetCellValue(sheet, excel.CellKey(row, &col), invoiceAcceptEmail)
f.SetCellValue(sheet, excel.CellKey(row, &col), policyCreatedAt)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.StartDate)
f.SetCellValue(sheet, excel.CellKey(row, &col), "180天")
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.InsureAmount)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Project.Amount)
f.SetCellValue(sheet, excel.CellKey(row, &col), order.GetStatusText())
f.SetCellValue(sheet, excel.CellKey(row, &col), invoiceHeader)
f.SetCellValue(sheet, excel.CellKey(row, &col), invoiceTaxNumber)
row++
}
}
@ -839,6 +942,14 @@ func (s *orderService) UpdateOrderAfterPostToInsure(orderNo, payUrl string, orde
global.DB.Model(&model.Order{}).Where("order_no", orderNo).UpdateColumns(model.Order{Status: "submitted", PayUrl: payUrl, OrderSn: orderSn})
}
func (s *orderService) UpdateOrderAfterClaim(orderNo string) {
global.DB.Model(&model.Order{}).Where("order_no", orderNo).UpdateColumns(model.Order{Status: "claimed"})
}
func (s *orderService) UpdateOrderAfterRevoke(orderNo string) {
global.DB.Model(&model.Order{}).Where("order_no", orderNo).UpdateColumns(model.Order{Status: "revoked"})
}
func (s *orderService) GetPayInfo(token string) (*response.PayInfoResponse, error) {
order, err := s.GetOrderByToken(token)
if err != nil {

@ -0,0 +1,150 @@
package service
import (
"fmt"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
"insure/dto/request"
"insure/dto/request/manage"
"insure/global"
"insure/model"
"insure/utils/excel"
"time"
)
var StudentInsureService = studentInsureService{}
type studentInsureService struct {
}
func (s *studentInsureService) Save(r request.StudentInsureInfoRequest) (*model.StudentInsureInfo, error) {
info := model.StudentInsureInfo{}
info.SchoolName = r.SchoolName
info.StudentName = r.StudentName
info.StudentIdentityNo = r.StudentIdentityNo
info.StudentIdentityType = r.StudentIdentityType
info.College = r.College
info.Speciality = r.Speciality
info.Class = r.Class
info.Relation = r.Relation
info.ParentName = r.ParentName
info.ParentIdentityNo = r.ParentIdentityNo
info.ParentIdentityType = r.ParentIdentityType
info.ParentMobile = r.ParentMobile
err := global.DB.Save(&info).Error
if err != nil {
return nil, err
}
return &info, nil
}
func (s *studentInsureService) GetInfos(req manage.OrderQueryRequest) ([]model.StudentInsureInfo, int64) {
records := make([]model.StudentInsureInfo, req.PageSize)
offset := (req.Page - 1) * req.PageSize
var total int64
s.buildQuery(req).Order("id desc").Offset(offset).Limit(req.PageSize).Find(&records)
s.buildQuery(req).Model(&model.Order{}).Count(&total)
return records, total
}
func (s *studentInsureService) buildQuery(req manage.StudentInsureInfoQueryRequest) *gorm.DB {
tx := global.DB
if req.SchoolName != "" {
tx = tx.Where("school_name", req.SchoolName)
}
if req.StudentName != "" {
tx = tx.Where("student_name", req.StudentName)
}
if req.StudentIdentityNo != "" {
tx = tx.Where("student_identity_no", req.StudentIdentityNo)
}
if req.ParentName != "" {
tx = tx.Where("parent_name", req.ParentName)
}
if req.ParentIdentityNo != "" {
tx = tx.Where("parent_identity_no", req.ParentIdentityNo)
}
if req.ParentMobile != "" {
tx = tx.Where("parent_mobile", req.ParentMobile)
}
if req.College != "" {
tx = tx.Where("college", req.College)
}
if req.Speciality != "" {
tx = tx.Where("speciality", req.Speciality)
}
if req.Class != "" {
tx = tx.Where("class", req.Class)
}
if req.UpdatedAtStart != "" && req.UpdatedAtEnd != "" {
updatedAtStart := req.UpdatedAtStart + " 00:00:00"
updatedAtEnd := req.UpdatedAtEnd + " 23:59:59"
tx = tx.Where("updated_at >= ?", updatedAtStart).Where("updated_at <= ?", updatedAtEnd)
}
return tx
}
func (s *studentInsureService) GenerateOrdersExcel(req manage.StudentInsureInfoQueryRequest) *excelize.File {
pageSize := 200
lastID := 0
f := excel.NewFile()
headers := []string{
"学校名称",
"学生姓名",
"学生证件号",
"学生证件类型",
"学院",
"专业",
"班级",
"家长与学生关系",
"家长姓名",
"家长证件号",
"家长证件类型",
"家长电话",
"提交时间",
}
excel.SetSimpleHeaders(headers, "Sheet1", f)
var allRecords []model.StudentInsureInfo
for {
records := make([]model.StudentInsureInfo, pageSize)
s.buildQuery(req).
Where("id > ?", lastID).
Order("id asc").
Limit(pageSize).
Find(&records)
count := len(records)
if count == 0 {
break
}
lastIndex := count - 1
lastID = records[lastIndex].ID
fmt.Println("lastID", lastID)
allRecords = append(allRecords, records...)
}
s.buildOrdersExcel(allRecords, "Sheet1", f)
return f
}
func (studentInsureService) buildOrdersExcel(records []model.StudentInsureInfo, sheet string, f *excelize.File) {
row := 2
for _, record := range records {
col := 0
f.SetCellValue(sheet, excel.CellKey(row, &col), record.SchoolName)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.StudentName)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.StudentIdentityNo)
f.SetCellValue(sheet, excel.CellKey(row, &col), "身份证")
f.SetCellValue(sheet, excel.CellKey(row, &col), record.College)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Speciality)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Class)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Relation)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentName)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentIdentityNo)
f.SetCellValue(sheet, excel.CellKey(row, &col), "身份证")
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentMobile)
f.SetCellValue(sheet, excel.CellKey(row, &col), record.UpdatedAt.Format(time.DateTime))
row++
}
}

@ -35,7 +35,7 @@ func SetSimpleHeaders(headers []string, sheet string, f *excelize.File) {
}
func ColKey(i int) string {
rowKeys := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
rowKeys := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG"}
return rowKeys[i]
}

Loading…
Cancel
Save