package ${globalConfig.parentPack}.controller.gen;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import ${globalConfig.parentPack}.common.base.BaseController;
import ${globalConfig.parentPack}.common.domain.AjaxResult;
import ${globalConfig.parentPack}.model.auto.${TsysTables.tableModel};
import ${globalConfig.parentPack}.model.custom.TableSplitResult;
import ${globalConfig.parentPack}.model.custom.Tablepar;
import ${globalConfig.parentPack}.model.custom.TitleVo;
import ${globalConfig.parentPack}.service.${TsysTables.tableModel}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "${TsysTables.tableComment}")
@Controller
@RequestMapping("/${TsysTables.tableModel}Controller")
public class ${TsysTables.tableModel}Controller extends BaseController{
	
	private String prefix = "gen/${TsysTables.tableModel_a}";
	@Resource
	private ${TsysTables.tableModel}Service ${TsysTables.tableModel_a}Service;
	
	/**
	 * 分页跳转
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:${TsysTables.tableModel_a}:view")
    public String view(ModelMap model)
    {	
		String str="${TsysTables.tableComment}";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }
	
	/**
	 * 分页查询
	 */
	//@Log(title = "${TsysTables.tableComment}集合查询", action = "111")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping("/list")
	@RequiresPermissions("gen:${TsysTables.tableModel_a}:list")
	@ResponseBody
	public Object list(Tablepar tablepar,${TsysTables.tableModel} record){
		PageInfo<${TsysTables.tableModel}> page=${TsysTables.tableModel_a}Service.list(tablepar,record) ; 
		TableSplitResult<${TsysTables.tableModel}> result=new TableSplitResult<${TsysTables.tableModel}>(page.getPageNum(), page.getTotal(), page.getList()); 
		return  result;
	}
	
	/**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
	/**
     * 新增
     */
	//@Log(title = "${TsysTables.tableComment}新增", action = "111")
   	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@RequiresPermissions("gen:${TsysTables.tableModel_a}:add")
	@ResponseBody
	public AjaxResult add(${TsysTables.tableModel} ${TsysTables.tableModel_a}){
		int b=${TsysTables.tableModel_a}Service.insertSelective(${TsysTables.tableModel_a});
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "${TsysTables.tableComment}删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@PostMapping("/remove")
	@RequiresPermissions("gen:${TsysTables.tableModel_a}:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=${TsysTables.tableModel_a}Service.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 检查Name
	 * @param tsysUser
	 * @return
	 */
	@ApiOperation(value = "检查Name唯一", notes = "检查Name唯一")
	@PostMapping("/checkNameUnique")
	@ResponseBody
	public int checkNameUnique(${TsysTables.tableModel} ${TsysTables.tableModel_a}){
		int b=${TsysTables.tableModel_a}Service.checkNameUnique(${TsysTables.tableModel_a});
		if(b>0){
			return 1;
		}else{
			return 0;
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("${TsysTables.tableModel}", ${TsysTables.tableModel_a}Service.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "${TsysTables.tableComment}修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:${TsysTables.tableModel_a}:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(${TsysTables.tableModel} record)
    {
        return toAjax(${TsysTables.tableModel_a}Service.updateByPrimaryKeySelective(record));
    }

    
    /**
   	 * 根据主键查询
   	 * 
   	 * @param id
   	 * @param mmap
   	 * @return
   	 */
   	@ApiOperation(value = "根据id查询唯一", notes = "根据id查询唯一")
   	@PostMapping("/get/{id}")
   	public ${TsysTables.tableModel} edit(@PathVariable("id") String id) {
   		return ${TsysTables.tableModel_a}Service.selectByPrimaryKey(id);
   	}
    

	
}
