| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package lingtao.net.controller;
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.IOException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.management.RuntimeErrorException;
- import javax.servlet.http.HttpSession;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.io.FilenameUtils;
- import org.apache.http.client.utils.DateUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import lingtao.net.bean.CustomerTrainContent;
- import lingtao.net.bean.CustomerTrainKindLabel;
- import lingtao.net.bean.CustomerTrainProType;
- import lingtao.net.bean.Msg;
- import lingtao.net.service.CustomerTrainService;
- @RestController
- public class CustomerTrainController {
- @Autowired
- private CustomerTrainService customerTrainService;
- private String localPrefix = "abc\\train";
- private String localPath = "C:\\lingtao\\upload";
- private String localDomain = "http://47.114.150.226:80/erp";
- // 图片上传及新增
- @RequestMapping("/imgUpload")
- public Object upload(@RequestParam("file") MultipartFile file) throws Exception {
- if (file.isEmpty()) {
- return Msg.fail("文件不能为空");
- }
- // 获取文件名后缀
- String extension = FilenameUtils.getExtension(file.getOriginalFilename());
- // 获取path
- String path = getPath(extension, FilenameUtils.getBaseName(file.getOriginalFilename()));
- // 保存文件信息
- File newFile = new File(localPath + File.separator + path);
- try {
- FileUtils.copyInputStreamToFile(new ByteArrayInputStream(file.getBytes()), newFile);
- } catch (IOException e) {
- throw new RuntimeErrorException(null, "");
- }
- String serverPath = localDomain + "/" + path;
- Map<String, Object> map = new HashMap<String, Object>();
- Map<String, Object> map2 = new HashMap<String, Object>();
- map.put("code", 0); // 0表示上传成功
- map.put("msg", "上传成功"); // 提示消息
- // src返回图片上传成功后的下载路径,这里直接给绝对路径
- map2.put("src", serverPath);
- map.put("data", map2);
- return map;
- }
- /**
- *
- * @param prefixSelf 根据上传的接口存入自己的文件夹
- * @param suffix 文件的后缀
- * @param fileName 文件名
- * @return
- */
- public String getPath(String suffix, String fileName) {
- // 生成uuid
- // String uuid = UUID.randomUUID().toString().replaceAll("-", "");
- String path = null;
- // 文件路径
- path = DateUtils.formatDate(new Date(), "yyyyMMdd") + File.separator + fileName;
- path = localPrefix + File.separator + File.separator + path;
- return path + "." + suffix;
- }
- /* =============产品知识内容================ */
- /**
- * 查询
- *
- * @param page
- * @param limit
- * @param customerTrainContent
- * @return
- */
- @RequestMapping("/getCustomerTrainContents")
- public PageInfo<CustomerTrainContent> getCustomerTrainContents(
- @RequestParam(value = "page", defaultValue = "1") Integer page,
- @RequestParam(value = "limit", defaultValue = "10") Integer limit,
- CustomerTrainContent customerTrainContent) {
- PageHelper.startPage(page, limit);
- List<CustomerTrainContent> customerTrainContentList = customerTrainService
- .getCustomerTrainContents(customerTrainContent);
- PageInfo<CustomerTrainContent> pageInfo = new PageInfo<CustomerTrainContent>(customerTrainContentList);
- return pageInfo;
- }
- /**
- * 添加
- *
- */
- @RequestMapping("/addCustomerTrainContent")
- public Msg addCustomerTrainContent(CustomerTrainContent customerTrainContent, HttpSession session) {
- return customerTrainService.addCustomerTrainContent(customerTrainContent, session);
- }
- /**
- * 修改
- */
- @RequestMapping("/updateCustomerTrainContent")
- public Msg updateCustomerTrainContent(CustomerTrainContent customerTrainContent, HttpSession session) {
- return customerTrainService.updateCustomerTrainContentById(customerTrainContent, session);
- }
- /**
- * 修改
- */
- @RequestMapping("/updateCustomerTrainContentSort")
- public Msg updateById(@RequestParam(value = "id") int id, @RequestParam(value = "value") String value) {
- return customerTrainService.updateCustomerTrainContentSort(id, value);
- }
- /**
- * 删除
- */
- @RequestMapping("/deleteCustomerTrainContent")
- public Msg deleteCustomerTrainContent(@RequestParam("id") Integer id) {
- return customerTrainService.deleteCustomerTrainContentById(id);
- }
- /* =============产品种类================ */
- /**
- * 查询
- *
- * @param page
- * @param limit
- * @param customerTrainProType
- * @return
- */
- @RequestMapping("/getCustomerTrainProTypes")
- public PageInfo<CustomerTrainProType> getCustomerTrainProTypes(
- @RequestParam(value = "page", defaultValue = "1") Integer page,
- @RequestParam(value = "limit", defaultValue = "10") Integer limit,
- CustomerTrainProType customerTrainProType) {
- PageHelper.startPage(page, limit);
- List<CustomerTrainProType> customerTrainProTypeList = customerTrainService
- .getCustomerTrainProTypes(customerTrainProType);
- PageInfo<CustomerTrainProType> pageInfo = new PageInfo<CustomerTrainProType>(customerTrainProTypeList);
- return pageInfo;
- }
- /**
- * 添加
- *
- */
- @RequestMapping("/addCustomerTrainProType")
- public Msg addCustomerTrainProType(CustomerTrainProType customerTrainProType, HttpSession session) {
- return customerTrainService.addCustomerTrainProType(customerTrainProType, session);
- }
- /**
- * 修改
- */
- @RequestMapping("/updateCustomerTrainProType")
- public Msg updateCustomerTrainProType(CustomerTrainProType customerTrainProType, HttpSession session) {
- return customerTrainService.updateCustomerTrainProTypeById(customerTrainProType, session);
- }
- /**
- * 删除
- */
- @RequestMapping("/deleteCustomerTrainProType")
- public Msg deleteCustomerTrainProType(@RequestParam("id") Integer id) {
- return customerTrainService.deleteCustomerTrainProTypeById(id);
- }
- /* =============产品类型================ */
- /**
- * 查询
- *
- * @param page
- * @param limit
- * @param customerTrainKindLabel
- * @return
- */
- @RequestMapping("/getCustomerTrainKindLabelsByProType")
- public PageInfo<CustomerTrainKindLabel> getCustomerTrainKindLabelsByProType(
- @RequestParam(value = "page", defaultValue = "1") Integer page,
- @RequestParam(value = "limit", defaultValue = "10") Integer limit,
- @RequestParam(value = "needPage") String needPage, CustomerTrainKindLabel customerTrainKindLabel) {
- // 0:不要分页 1:要分页
- if ("1".equals(needPage))
- PageHelper.startPage(page, limit);
- List<CustomerTrainKindLabel> customerTrainKindLabelList = customerTrainService
- .getCustomerTrainKindLabelsByProType(customerTrainKindLabel);
- PageInfo<CustomerTrainKindLabel> pageInfo = new PageInfo<CustomerTrainKindLabel>(customerTrainKindLabelList);
- return pageInfo;
- }
- /**
- * 添加
- *
- */
- @RequestMapping("/addCustomerTrainKindLabel")
- public Msg addCustomerTrainKindLabel(CustomerTrainKindLabel customerTrainKindLabel, HttpSession session) {
- return customerTrainService.addCustomerTrainKindLabel(customerTrainKindLabel, session);
- }
- /**
- * 修改
- */
- @RequestMapping("/updateCustomerTrainKindLabel")
- public Msg updateCustomerTrainKindLabel(CustomerTrainKindLabel customerTrainKindLabel, HttpSession session) {
- return customerTrainService.updateCustomerTrainKindLabelById(customerTrainKindLabel, session);
- }
- /**
- * 删除
- */
- @RequestMapping("/deleteCustomerTrainKindLabel")
- public Msg deleteCustomerTrainKindLabel(@RequestParam("id") Integer id) {
- return customerTrainService.deleteCustomerTrainKindLabelById(id);
- }
- }
|