|
@@ -0,0 +1,71 @@
|
|
|
|
+package com.hssx.ysofficial.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.hssx.ysofficial.entity.CompanyProducts;
|
|
|
|
+import com.hssx.ysofficial.entity.OnlineApplication;
|
|
|
|
+import com.hssx.ysofficial.mapper.CompanyProductsMapper;
|
|
|
|
+import com.hssx.ysofficial.service.CompanyProductsService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.ysofficial.utility.HttpRespMsg;
|
|
|
|
+import com.hssx.ysofficial.utility.PageUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 第一个数据是公司优势 其他是案例 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Reiskuchen
|
|
|
|
+ * @since 2019-11-21
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class CompanyProductsServiceImpl extends ServiceImpl<CompanyProductsMapper, CompanyProducts> implements CompanyProductsService {
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyProductsMapper companyProductsMapper;
|
|
|
|
+ @Value("${upload.path}")
|
|
|
|
+ private String uploadPath;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg addAndUpdate(CompanyProducts companyProducts, MultipartFile multipartFile) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ if(multipartFile != null){
|
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
|
+ File direction = new File(uploadPath);
|
|
|
|
+ String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ String storedFileName = rand + suffix;
|
|
|
|
+ try {
|
|
|
|
+ File savedFile = new File(direction, storedFileName);
|
|
|
|
+ savedFile.createNewFile();
|
|
|
|
+ multipartFile.transferTo(savedFile);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ companyProducts.setImageUrl("/upload/" + storedFileName);
|
|
|
|
+ }
|
|
|
|
+ if (companyProducts.getId() != null) {
|
|
|
|
+ companyProductsMapper.insert(companyProducts);
|
|
|
|
+ }else {
|
|
|
|
+ companyProductsMapper.updateById(companyProducts);
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg companyProductsList(PageUtil page) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ Page<CompanyProducts> pages = new Page<>(page.getPageNum(),page.getPageSize());
|
|
|
|
+// onlineApplicationMapper.selectList(new QueryWrapper<OnlineApplication>());
|
|
|
|
+ IPage<CompanyProducts> pageInfo = companyProductsMapper.selectPage(pages,new QueryWrapper<CompanyProducts>().orderByDesc("id"));
|
|
|
|
+ msg.data = pageInfo;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+}
|