| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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 com.goafanti.common.model.JtBusinessProject;
- 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.STATUS_ERROR,"","id"));
- return result;}
- int rc=jtBusinessService.deleteCategoryById(id);
- result.setData(rc);
- if(rc==-1) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","请先删除子项目及子分类,"));
- }
- 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 ;
- }
-
- /*
- *
- * 新增项目
- *
- * */
- @RequestMapping(value="/project/apply",method=RequestMethod.POST)
- private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
- Result result=new Result();
- disposeProjectParam(result, jtBusinessProject);
- if(result.getError().size()<=0) {
- result.setData(jtBusinessService.insertProject(jtBusinessProject));
- }
- return result;
-
- }
- private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
- if(jtBusinessProject.getName() == null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
- return ;
- }
- if(jtBusinessProject.getCategoryId() == null) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
- return ;
- }
- //todo 判断品类是否存在
- JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
- if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类找到"));
- return ;
- }
-
- if(jtBusinessProject.getProvince()==null)
- {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
- return ;
- }
-
- if(jtBusinessProject.getCity()==null)
- {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
- return ;
- }
- if(jtBusinessProject.getPrice()==null)
- {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
- return ;
- }
- return ;
- }
-
- /*
- * 项目详情
- *
- * */
- @RequestMapping(value="/project/detail",method=RequestMethod.GET)
- private Result getProjectDetail(String id) {
- Result result=new Result();
- if(id == null) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
- return result;
- }
- result.setData(jtBusinessService.getBusinessProjectDetail(id));
- return result;
- }
-
- /*
- * 删除项目
- * */
- @RequestMapping(value="/project/delete",method=RequestMethod.GET)
- private Result deleteProjecById(String id) {
- Result result=new Result();
- if(id == null) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
- return result;
- }
- result.setData(jtBusinessService.deleteProjectById(id));
- return result;
- }
-
- }
|