package com.bsd.cases.controller; import com.alibaba.fastjson.JSONObject; import com.bsd.cases.model.CaseCompany; import com.bsd.cases.service.CaseCompanyService; import com.bsd.cases.util.AjaxResult; import com.bsd.cases.util.PageAjax; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @Api("公司API") @RestController @RequestMapping("/company") public class CaseCompanyController { @Resource private CaseCompanyService caseCompanyService; @ApiOperation(value = "公司列表,不需要传参,返回所有公司信息", notes = "公司列表") @PostMapping("list") public AjaxResult list(@RequestBody JSONObject jsonObject) { AjaxResult ajaxResult = new AjaxResult(); try { ajaxResult.setData(caseCompanyService.list(jsonObject)); ajaxResult.setRetcode(AjaxResult.SUCCESS); ajaxResult.setRetmsg("获取公司列表成功"); } catch (Exception e) { e.printStackTrace(); ajaxResult.setRetmsg("获取公司列表失败:" + e.getMessage()); ajaxResult.setRetcode(AjaxResult.FAILED); } return ajaxResult; } @ApiOperation(value = "公司列表PC", notes = "公司列表PC") @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "起始页码"), @ApiImplicitParam(name = "key", value = "公司名称"), @ApiImplicitParam(name = "areaId", value = "区域id"), @ApiImplicitParam(name = "state", value = "1:正常,0:删除") }) @PostMapping("listbypage") @RequiresAuthentication public AjaxResult listByPage(@RequestBody JSONObject jsonObject) { AjaxResult ajaxResult = new AjaxResult(); try { PageAjax pageAjax = caseCompanyService.listByPage(jsonObject); ajaxResult.setRetmsg("操作成功"); ajaxResult.setData(pageAjax); ajaxResult.setRetcode(AjaxResult.SUCCESS); } catch (Exception e) { e.printStackTrace(); ajaxResult.setRetmsg("操作失败:" + e.getMessage()); ajaxResult.setRetcode(AjaxResult.FAILED); } return ajaxResult; } @ApiOperation(value = "公司详情PC", notes = "公司详情PC") @ApiImplicitParams({ @ApiImplicitParam(name = "companyId", value = "公司id") }) @PostMapping("detail") @RequiresAuthentication public AjaxResult detail(@RequestBody JSONObject jsonObject) { AjaxResult ajaxResult = new AjaxResult(); try { CaseCompany caseCompany = caseCompanyService.detail(jsonObject); ajaxResult.setRetmsg("操作成功"); ajaxResult.setData(caseCompany); ajaxResult.setRetcode(AjaxResult.SUCCESS); } catch (Exception e) { e.printStackTrace(); ajaxResult.setRetmsg("操作失败:" + e.getMessage()); ajaxResult.setRetcode(AjaxResult.FAILED); } return ajaxResult; } @ApiOperation(value = "增加/编辑公司", notes = "增加/编辑公司") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "公司id"), @ApiImplicitParam(name = "companyId", value = "公司编号"), @ApiImplicitParam(name = "companyName", value = "公司名称"), @ApiImplicitParam(name = "areaId", value = "区域id") }) @PostMapping("add") @RequiresAuthentication public AjaxResult add(@RequestBody JSONObject jsonObject) { AjaxResult ajaxResult = new AjaxResult(); try { caseCompanyService.add(jsonObject); ajaxResult.setRetmsg("操作成功"); ajaxResult.setRetcode(AjaxResult.SUCCESS); } catch (Exception e) { e.printStackTrace(); ajaxResult.setRetmsg("操作失败:" + e.getMessage()); ajaxResult.setRetcode(AjaxResult.FAILED); } return ajaxResult; } @ApiOperation(value = "删除", notes = "增加公司") @ApiImplicitParams({ @ApiImplicitParam(name = "companyId", value = "公司id") }) @PostMapping("delete") @RequiresAuthentication public AjaxResult delete(@RequestBody JSONObject jsonObject) { AjaxResult ajaxResult = new AjaxResult(); try { caseCompanyService.delete(jsonObject); ajaxResult.setRetmsg("操作成功"); ajaxResult.setRetcode(AjaxResult.SUCCESS); } catch (Exception e) { e.printStackTrace(); ajaxResult.setRetmsg("操作失败:" + e.getMessage()); ajaxResult.setRetcode(AjaxResult.FAILED); } return ajaxResult; } }