当前位置: 首页 > 文档资料 > 网聚宝开发指南 >

WEB 工程

优质
小牛编辑
130浏览
2023-12-01

WEB工程

本工程主要通过SpringMVC为前端提供RESTFul资源接口,负责调用DUBBO接口。

RESTFul资源标准化

直接上代码


package banniu.web.controller.salecrm;


import ...

/**
 * 标签管理RESTFul资源
 *
 * @author  蜜蜂
 * @version 1.0
 * @since   2017-03-08 10:58:28
 */
@RestController
@RequestMapping("/tag")
public class TagController {

    private final static Logger logger = LoggerFactory.getLogger(TagController.class);


    @Autowired
    private TagsAppService tagsAppService;

    /**
     * 查询单个标签
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET,produces="application/json")
    public String get(@PathVariable Long id) {
        return tagsAppService.getTagsById(id);
    }


    /**
     * 查询标签列表
     *
     * @param tag
     * @param session
     * @return
     */
    @RequestMapping(method = RequestMethod.PATCH)
    public String list(@RequestBody Map<String,String> tag, HttpSession session) {
        WorkUser userDo = (WorkUser) session.getAttribute(SalecrmConstant.SESSION_USER);
        tag.put("companyId",userDo.getCompanyId().toString());

        int num = StrUtils.isNotEmpty(tag.get("pageNum")) ? Integer.valueOf(tag.get("pageNum")) : 0;
        int size = StrUtils.isNotEmpty(tag.get("pageSize")) ? Integer.valueOf(tag.get("pageSize")) : 10;

        return tagsAppService.getPageListByTags(tag, num, size);
    }

    /**
     * 新增标签
     * @param tag
     * @param session
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,produces="application/json")
    public String create(@RequestBody Map<String,String> tag, HttpSession session) {
        WorkUser userDo = (WorkUser) session.getAttribute(SalecrmConstant.SESSION_USER);
        tag.put("companyId",userDo.getCompanyId().toString());
        tag.put("userId",userDo.getId().toString());
        tag.put("status","0");

        return tagsAppService.createTags(tag);
    }


    /**
     * 更新标签
     * @param tag
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public boolean update(@RequestBody Map<String,String> tag, @PathVariable Long id) {
        return tagsAppService.updateTags(tag);
    }

    /**
     * 删除标签
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable Long id) {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("result", "删除标签成功");
        return "";
    }

}