wuheng 2 years ago
parent
commit
adc78ca679

+ 65 - 0
travel/admin/src/main/java/com/lc/admin/controller/SetmealController.java

@@ -0,0 +1,65 @@
+package com.lc.admin.controller;
+
+import com.aliyun.oss.ClientException;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.OSSException;
+import com.aliyun.oss.model.PutObjectRequest;
+import com.aliyun.oss.model.PutObjectResult;
+import com.lc.common.pojo.TravelParams;
+import com.lc.common.utils.Result;
+import com.lc.service.SetmealService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+
+@RequestMapping("/setmeal")
+@RestController
+public class SetmealController {
+
+    @Value("${setmeal.upload.alioss.endpoint}")
+    private String endpoint;
+    @Value("${setmeal.upload.alioss.accessKeyId}")
+    private String accessKeyId;
+    @Value("${setmeal.upload.alioss.accessKeySecret}")
+    private String accessKeySecret;
+    @Value("${setmeal.upload.alioss.bucketName}")
+    private String bucketName;
+
+    @Resource
+    SetmealService setmealService;
+
+    @PostMapping("/findPage.do")
+    public Result findPage( @RequestBody TravelParams travelParams ){
+        return Result.data( setmealService.findPage( travelParams ) );
+    }
+
+    @PostMapping("/upload.do")
+    public Result upload(MultipartFile imgFile){
+        String originalFilename = imgFile.getOriginalFilename();
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        try {
+            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,
+                    originalFilename, imgFile.getInputStream() );
+            PutObjectResult result = ossClient.putObject(putObjectRequest);
+            //System.out.println( result );
+        } catch (OSSException oe) {
+            System.out.println( oe.getMessage() );
+        } catch (ClientException ce) {
+            System.out.println( ce.getMessage() );
+        } catch (IOException e) {
+            System.out.println( e.getMessage() );
+        } finally {
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+        return Result.data(originalFilename);
+    }
+
+}

+ 5 - 0
travel/admin/src/main/java/com/lc/admin/controller/StaticController.java

@@ -21,4 +21,9 @@ public class StaticController {
         return "travelitem";
     }
 
+    @RequestMapping("/setmeal.html")
+    public String setmeal(){
+        return "setmeal";
+    }
+
 }

+ 11 - 4
travel/admin/src/main/resources/application.properties

@@ -1,9 +1,16 @@
 server.port=9092
-#?????????
+#??????
 spring.mvc.view.prefix=/templates/
-#?????????
+#????
 spring.mvc.view.suffix=.html
-#???????????
+#?????
 spring.mvc.static-path-pattern=/static/**
+#??????
+spring.main.allow-circular-references=true
+#??????
+spring.servlet.multipart.max-file-size=10MB
 
-spring.main.allow-circular-references=true
+setmeal.upload.alioss.endpoint=https://oss-cn-beijing.aliyuncs.com
+setmeal.upload.alioss.accessKeyId=Z75YxVNFPfXK48zg
+setmeal.upload.alioss.accessKeySecret=DC5nkj1XSWwzqmuHQ8SIQByrgUm13q
+setmeal.upload.alioss.bucketName=80boys-beijing

+ 9 - 6
travel/admin/src/main/resources/templates/setmeal.html

@@ -1,4 +1,4 @@
-;;;;;;;vb[<!DOCTYPE html>
+<!DOCTYPE html>
 <html>
     <head>
         <!-- 页面meta -->
@@ -77,7 +77,7 @@
             <div class="app-container">
                 <div class="box">
                     <div class="filter-container">
-                        <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
+                        <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString.name" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                         <el-button @click="findPage()" class="dalfBut">查询</el-button>
                         <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                     </div>
@@ -238,7 +238,9 @@
                     currentPage: 1,
                     pageSize:10,
                     total:100,
-                    queryString:null,
+                    queryString:{
+                        name:""
+                    },
                 },
                 dataList: [],//列表数据
                 formData: {},//表单数据
@@ -253,7 +255,8 @@
                 //文件上传成功后的钩子,response为服务端返回的值,file为当前上传的文件封装成的js对象
                 handleAvatarSuccess(response, file) {
 									//对imageUrl 赋值 在文件框中显示
-									this.imageUrl = `http://ra5vj2ycp.hn-bkt.clouddn.com/${response.data}`
+									//this.imageUrl = `http://ra5vj2ycp.hn-bkt.clouddn.com/${response.data}`
+									this.imageUrl = `https://80boys-beijing.oss-cn-beijing.aliyuncs.com/${response.data}`
 									this.$message({
 										message : response.message,
 										type : response.flag ? 'success' : 'error'
@@ -298,8 +301,8 @@
 											//赋值
 											console.log(res)
 											
-											this.dataList = res.data.rows;
-											this.pagination.total = res.data.total;
+											this.dataList = res.data.data.rows;
+											this.pagination.total = res.data.data.total;
 									})
                 },
                 // 重置表单

+ 8 - 0
travel/pom.xml

@@ -31,11 +31,19 @@
 
     <properties>
         <java.version>1.8</java.version>
+        <oss.version>3.8.0</oss.version>
         <mybatis.version>2.2.0</mybatis.version>
         <mybatis-genertator.version>1.4.0</mybatis-genertator.version>
     </properties>
 
     <dependencies>
+
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>${oss.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-thymeleaf</artifactId>

+ 11 - 0
travel/service/src/main/java/com/lc/service/SetmealService.java

@@ -0,0 +1,11 @@
+package com.lc.service;
+
+import com.lc.common.pojo.TravelParams;
+
+import java.util.HashMap;
+
+public interface SetmealService {
+
+    HashMap<String, Object> findPage(TravelParams travelParams);
+
+}

+ 39 - 0
travel/service/src/main/java/com/lc/service/impl/SetmealServiceImpl.java

@@ -0,0 +1,39 @@
+package com.lc.service.impl;
+
+import com.cl.mbg.mapper.TSetmealMapper;
+import com.cl.mbg.model.TSetmeal;
+import com.cl.mbg.model.TSetmealExample;
+import com.github.pagehelper.PageHelper;
+import com.lc.common.pojo.TravelParams;
+import com.lc.service.SetmealService;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+
+@Service
+public class SetmealServiceImpl implements SetmealService {
+
+    @Resource
+    TSetmealMapper setmealMapper;
+
+    @Override
+    public HashMap<String, Object> findPage(TravelParams travelParams) {
+        PageHelper.startPage( travelParams.getCurrentPage(), travelParams.getPageSize() );
+        TSetmealExample tSetmealExample = new TSetmealExample();
+        TSetmealExample.Criteria criteria = tSetmealExample.createCriteria();
+        String name = travelParams.getQueryString().getName();
+        if (StringUtils.hasText(name)) {
+            criteria.andNameLike( "%" + name + "%" );
+        }
+        List<TSetmeal> tSetmeals = setmealMapper.selectByExample(tSetmealExample);
+        long count = setmealMapper.countByExample(tSetmealExample);
+
+        HashMap<String, Object> ret = new HashMap<>();
+        ret.put("rows", tSetmeals);
+        ret.put("total", count);
+        return ret;
+    }
+}