|
@@ -0,0 +1,79 @@
|
|
|
|
+package com.hssx.ysofficial.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.ysofficial.entity.Recruitment;
|
|
|
|
+import com.hssx.ysofficial.mapper.RecruitmentMapper;
|
|
|
|
+import com.hssx.ysofficial.service.RecruitmentService;
|
|
|
|
+import com.hssx.ysofficial.utility.HttpRespMsg;
|
|
|
|
+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.time.LocalDate;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Reiskuchen
|
|
|
|
+ * @since 2020-02-14
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class RecruitmentServiceImpl extends ServiceImpl<RecruitmentMapper, Recruitment> implements RecruitmentService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private RecruitmentMapper recruitmentMapper;
|
|
|
|
+
|
|
|
|
+ @Value("${upload.path}")
|
|
|
|
+ private String uploadPath;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getRecruitmentList() {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ httpRespMsg.data = recruitmentMapper.selectList(new QueryWrapper<>());
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg deleteRecruitmentList(Integer id) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ httpRespMsg.data = recruitmentMapper.deleteById(id);
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg editRecruitmentList(Integer id, String title, String content, String date, MultipartFile multipartFile) {
|
|
|
|
+ Recruitment recruitment = new Recruitment()
|
|
|
|
+ .setId(id)
|
|
|
|
+ .setTitle(title)
|
|
|
|
+ .setContent(content)
|
|
|
|
+ .setPublishTime(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ recruitment.setPicUrl("/upload/" + storedFileName);
|
|
|
|
+ }
|
|
|
|
+ if (id != null) {
|
|
|
|
+ recruitmentMapper.updateById(recruitment);
|
|
|
|
+ } else {
|
|
|
|
+ recruitmentMapper.insert(recruitment);
|
|
|
|
+ }
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
|
|
+}
|