123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*
- * @description: 编号规则
- * @Author: LanJianRong
- * @Date: 2020-11-27
- * @FilePath: \construction_management\web\api\rule_api.go
- */
- package api
- import (
- "fmt"
- "github.com/kataras/iris/v12"
- "go.mod/services"
- "go.mod/web/utils"
- )
- type RuleApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- RuleService services.RuleService
- }
- // @Summary 获取编号规则
- // @Tags 编号规则
- // @Description 获得制定pid、bid的编号规则
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId path string true "标段ID"
- // @Param projectId path string true "项目ID"
- // @Success 200 {object} viewmodels.ViewRule "{code:0成功,data:viewmodels.Safe,msg:请求成功}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/rule [get]
- func (c *RuleApi) Get() {
- // 1.规则验证
- safeData, err := c.RuleService.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- pid, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
- return
- }
- bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- rule := c.RuleService.Get(pid, bidsectionId)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- "data": rule,
- })
- }
- // @Summary 提交编号规则
- // @Tags 编号规则
- // @Description 提交规则
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId body string true "标段ID"
- // @Param type body string true "规则类型" eg:"safeRule、qualityRule、contractRule"
- // @Param value body string true "编号规则" eg:"'['202011', 'cc3']'"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/rule [post]
- func (c *RuleApi) Post() {
- // 1.规则验证
- safeData, err := c.RuleService.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- pid, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
- return
- }
- bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- err = c.RuleService.Post(pid, bidsectionId, safeData.Type, safeData.Rule)
- if err == nil {
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- })
- } else {
- c.Ctx.JSON(iris.Map{
- "code": -1,
- "msg": fmt.Sprintf("%s", err),
- })
- }
- }
- // @Summary 生成编号
- // @Tags 编号规则
- // @Description 提交规则
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId body string true "标段ID"
- // @Param type body string true "规则类型" eg:"safeRule、qualityRule、contractRule"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/rule/auto [post]
- func (c *RuleApi) PostAuto() {
- // 1.规则验证
- safeData, err := c.RuleService.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- pid, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
- return
- }
- bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- rule, newCode, err := c.RuleService.AutoCode(bidsectionId, pid, safeData.Type)
- data := map[string]interface{}{
- "rule": rule,
- "newCode": newCode,
- }
- if err != nil {
- c.Ctx.JSON(iris.Map{
- "code": -1,
- "msg": fmt.Sprintf("%s", err),
- })
- } else {
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- "data": data,
- })
- }
- }
|