123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package com.bosshand.virgo.controller;
- import com.bosshand.virgo.core.config.OperationControllerLog;
- import com.bosshand.virgo.core.model.MgrClient;
- import com.bosshand.virgo.core.response.Response;
- import com.bosshand.virgo.core.utils.ContextUtils;
- import com.bosshand.virgo.core.utils.ExcelUtils;
- import com.bosshand.virgo.exception.BadRequestException;
- import com.bosshand.virgo.exception.Constant;
- import com.bosshand.virgo.service.ClientService;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.URLEncoder;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("client")
- public class ClientController {
- @Autowired
- ClientService clientService;
- @OperationControllerLog(module = "CRM", operation = "客户管理-客户列表查询")
- @ApiOperation("获取")
- @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
- public Response list(@RequestBody MgrClient mgrClient, @PathVariable int currPage, @PathVariable int pageSize) {
- long id = ContextUtils.getCurrentUser().getId();
- mgrClient.setUserId(id);
- int totalCount = clientService.getTotalCount(mgrClient);
- List<MgrClient> dataList = clientService.getLimit(mgrClient, currPage, pageSize);
- Map<String, Object> result = new HashMap<>();
- result.put("dataList", dataList);
- result.put("totalCount", totalCount);
- return Response.ok(result);
- }
- @OperationControllerLog(module = "CRM", operation = "客户管理-新增客户")
- @ApiOperation("保存")
- @RequestMapping(value = "", method = RequestMethod.POST)
- public Response insert(@RequestBody MgrClient mgrClient) {
- long id = ContextUtils.getCurrentUser().getId();
- mgrClient.setUserId(id);
- clientService.insert(mgrClient);
- return Response.ok();
- }
- @OperationControllerLog(module = "CRM", operation = "客户管理-标准模板下载")
- @ApiOperation("标准模板下载")
- @RequestMapping(value = "/downloadModel", method = RequestMethod.GET)
- public Response getModel(final HttpServletResponse response) throws Exception {
- byte[] data = null;
- OutputStream outputStream = null;
- try {
- data = clientService.getModel();
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/x-msdownload");
- response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("标准模版.xlsx", "UTF-8"));
- OutputStream outputSream = response.getOutputStream();
- outputSream.write(data);
- outputSream.flush();
- } catch (IOException e) {
- throw new BadRequestException("Fail to write stream", Constant.RET_DOCUMENT_ERROR, e);
- } finally {
- if (outputStream != null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- }
- }
- }
- return Response.ok();
- }
- @OperationControllerLog(module = "CRM", operation = "客户管理-批量导入")
- @ApiOperation("批量导入")
- @RequestMapping(value = "/import/{organizationId}", method = RequestMethod.POST)
- public Response insert(@ApiParam(name = "uploadFile", required = true) MultipartFile uploadFile, @PathVariable long organizationId) {
- long userId = ContextUtils.getCurrentUser().getId();
- InputStream inputStream = null;
- try {
- inputStream = uploadFile.getInputStream();
- List<MgrClient> list = ExcelUtils.dispose(inputStream, 1, 1, 0, 1000, MgrClient.class);
- for (MgrClient mc : list) {
- mc.setUserId(userId);
- mc.setOrganizationId(organizationId);
- }
- clientService.batchInsert(list);
- return Response.ok();
- } catch (IOException e) {
- return Response.fail(Constant.CODE_BAD_REQUEST, Constant.RET_INPUT_ERROR);
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- }
- }
- }
- }
- @ApiOperation("更新")
- @RequestMapping(value = "/update", method = RequestMethod.PUT)
- public Response update(@RequestBody MgrClient mgrClient) {
- clientService.update(mgrClient);
- return Response.ok();
- }
- @ApiOperation("删除")
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
- public Response delete(@PathVariable long id) {
- clientService.delete(id);
- return Response.ok();
- }
- @ApiOperation("详情")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public Response get(@PathVariable long id) {
- return Response.ok(clientService.get(id));
- }
- @ApiOperation("按类型统计数量")
- @RequestMapping(value = "/typeCount", method = RequestMethod.POST)
- public Response typeCount(@RequestBody MgrClient mgrClient) {
- return Response.ok(clientService.typeCount(mgrClient));
- }
- }
|