package com.goafanti.business.controller; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.goafanti.business.service.JtBusinessService; import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper; import com.goafanti.common.bo.Result; import com.goafanti.common.constant.ErrorConstants; import com.goafanti.common.controller.CertifyApiController; import com.goafanti.common.model.JtBusinessCategory; import okhttp3.Request; @RestController @RequestMapping(value = "/api/admin/jtBusiness") public class AdminJtBusinessController extends CertifyApiController{ @Resource private JtBusinessService jtBusinessService; @Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper; /* * 删除品类 * * */ @RequestMapping(value="/category/delete",method=RequestMethod.POST) private Result deleteCetegoryById(String id) { Result result=new Result(); if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id")); return result;} result.setData(jtBusinessService.deleteCategoryById(id)); return result; } /* * * 品类详情 * */ @RequestMapping(value="/category/detail",method=RequestMethod.GET) private Result getCategoryDetailById(String id) { Result result=new Result(); if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id")); return result;} result.setData(jtBusinessService.getCategoryById(id)); return result; } /* * * 新增品類 * * */ @RequestMapping(value="/category/apply",method=RequestMethod.POST) private Result insertCategory(JtBusinessCategory jtBusinessCategory) { Result result=new Result(); disposeCateParam(result, jtBusinessCategory); if(result.getError().size()>0)return result; int rc=jtBusinessService.insertCategory(jtBusinessCategory); if(rc==-1)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","每层品类不可超过99个,")); if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,")); return result; } /* * 修改 * */ @RequestMapping(value="/category/update",method=RequestMethod.POST) private Result updateCategory(JtBusinessCategory jtBusinessCategory) { Result result=new Result(); //只允许修改3种字段 JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory(); jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl()); jtBusinessCategory2.setName(jtBusinessCategory.getName()); jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary()); result.setData(jtBusinessService.updateCategory(jtBusinessCategory2)); return result; } /* * 查询品类 * * */ @RequestMapping(value="/category/list",method=RequestMethod.GET) private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) { Result result=new Result(); result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize)); return result; } private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) { if(jtBusinessCategory.getName() == null) { result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称")); return ; } if(jtBusinessCategory.getLayer() == null) { result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级")); return ; } if(jtBusinessCategory.getLayer()>1 && jtBusinessCategory.getSuperId()==null) { result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类")); return ; } return ; } }