package ${package.Controller};

import org.springframework.web.bind.annotation.*;
    #if(${restControllerStyle})
    #else
import org.springframework.stereotype.Controller;
    #end
    #if(${superControllerClassPackage})
import ${superControllerClassPackage};
    #end
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
    #if(${cfg.ResponseData})
    import ${cfg.ResponseData};
    #end
import java.util.Map;
import java.io.Serializable;
/**
 *   @description : ${entity} 默认控制器,仅供生成器使用
 *   ---------------------------------
 *   @since ${date}
 */
/*@Slf4j*/
#if(${restControllerStyle})
@RestController("core${table.controllerName}")
#else
@Controller("core${table.controllerName}")
#end
@RequestMapping("/#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
public class ${table.controllerName} extends BaseController {

    @Autowired
    private ${table.serviceName} ${table.entityPath}Service;

    /**
    * 定义一些通用的错误信息,供其他 api引用
    * @apiDefine DefaultException
    * @apiError {String} code 错误码
    * @apiError {String} msg 错误描述
    * @apiError {String} requestId 请求id标识
    *
    * @apiErrorExample Error-Response:
    *     HTTP/1.1 200
    *     {
    *       "code": "UNAUTHORIZED",
    *       "msg": "未授权,请先登录",
    *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
    *     }
    *
    */

    /**
     * 定义标准对象请求的结构体,供api引用
     * @apiDefine ${entity}Req
#foreach($field in ${table.fields})
    #if(${field.keyFlag})
        #set($keyPropertyName=${field.propertyName})
    #end
     * @apiParam {${field.propertyType}} ${field.propertyName} #if("$!field.comment" != "")${field.comment}#end
#end
     */


    /**
     * 定义标准对象返回的结构体,供api引用
     * @apiDefine ${entity}Resp
#foreach($field in ${table.fields})
    #if(${field.keyFlag})
        #set($keyPropertyName=${field.propertyName})
    #end
     * @apiSuccess {${field.propertyType}} ${field.propertyName} #if("$!field.comment" != "")${field.comment}#end
#end
     */

    /**
     * 定义标准头部,供api引用
     * @apiDefine ${entity}Header
     * @apiHeader {String} Authorization 用户授权token
     * @apiHeaderExample {json} Header-Example:
     *     {
     *       "Authorization": "Bearer 1eyJhbGciOiJIUzI1NiJ9....tzNK43MPVQWYYhDwihCAZa88zXzar7KLdgiBBDuUpBM",
     *     }
     */

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/query_unique 通过条件查询$!{table.comment}对象
     * @apiName 通过条件查询$!{table.comment}对象
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiUse ${entity}Resp
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": {
#foreach($field in ${table.fields})#if(${field.keyFlag})#set($keyPropertyName=${field.propertyName})#end
                  "${field.propertyName}": null,
#end
     *       },
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 通过条件查询$!{table.comment}对象
     * 仅查询第一条
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/query_unique")
    public ResponseData queryUnique(@RequestBody Map ${table.entityPath}Q) {
        return success(${table.entityPath}Service.queryUnique(${table.entityPath}Q));
    }

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/query_pages 通过条件分页查询$!{table.comment}列表
     * @apiName 通过条件分页查询$!{table.comment}列表
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiUse ${entity}Resp
     * @apiSuccess {Long} total 总数
     * @apiSuccess {Long} size 分页大小
     * @apiSuccess {Long} current 当前页
     * @apiSuccess {Long} orders 排序
     * @apiSuccess {Long} pages 总页数
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": {
     *       "records": [{
#foreach($field in ${table.fields})#if(${field.keyFlag})#set($keyPropertyName=${field.propertyName})#end
                "${field.propertyName}": null, #end
     *       }],
     *       "total": 1,
     *       "size": 10,
     *       "current": 1,
     *       "orders": [],
     *       "searchCount": true,
     *       "pages": 1
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 通过条件分页查询$!{table.comment}列表
     * 默认第一页 分页长度为10
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/query_pages")
    public ResponseData queryPages(@RequestBody Map ${table.entityPath}Q) {
        return success(${table.entityPath}Service.queryPage(${table.entityPath}Q));
    }

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/query_list 通过条件查询$!{table.comment}列表
     * @apiName 通过条件查询$!{table.comment}列表
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiUse ${entity}Resp
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": [{
        #foreach($field in ${table.fields})#if(${field.keyFlag})#set($keyPropertyName=${field.propertyName})#end
        "${field.propertyName}": null,
        #end
     *       }],
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 通过条件查询$!{table.comment}列表
     * 不分页直接返回list
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/query_list")
    public ResponseData queryList(@RequestBody Map ${table.entityPath}Q) {
        return success(${table.entityPath}Service.queryList(${table.entityPath}Q));
    }

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/remove/:id 通过id删除$!{table.comment}单个记录
     * @apiName 通过id删除$!{table.comment}单个记录
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiParam {PK} id 记录主键
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": true,
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 通过id删除$!{table.comment}单个记录
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/remove/{id}")
    public ResponseData remove(@PathVariable("id") Serializable id) {
        return success(${table.entityPath}Service.remove(id));
    }

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/modify 通过id更新$!{table.comment}单个记录
     * @apiName 通过id更新$!{table.comment}单个记录
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiParam {PK} id 记录主键
     * @apiUse ${entity}Req
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": true,
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 通过id更新$!{table.comment}单个记录
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/modify")
    public ResponseData modify(@RequestBody ${entity} ${table.entityPath}) {
        return success(${table.entityPath}Service.modify(${table.entityPath}));
    }

    /**
     *
     * @api {post} /#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end/create 新增$!{table.comment}
     * @apiName 新增$!{table.comment}
     * @apiGroup ${entity}
     *
     * @apiUse ${entity}Header
     * @apiUse ${entity}Req
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       "data": true,
     *       "code": "SUCCESS",
     *       "msg": "请求成功",
     *       "requestId": "163e2f67-5306-4b10-bcbe-a1579d589446"
     *     }
     *
     * @apiUse DefaultException
     *
     * @description : 新增$!{table.comment}
     * ---------------------------------
     * @author : ${author}
     * @since : Create in ${date}
     */
    @PostMapping(value = "/create")
    public ResponseData create(@RequestBody ${entity} ${table.entityPath}) {
        return success(${table.entityPath}Service.create(${table.entityPath}));
    }
}
