|
@@ -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.Characteristic;
|
|
|
|
+import com.hssx.ysofficial.mapper.CharacteristicMapper;
|
|
|
|
+import com.hssx.ysofficial.service.CharacteristicService;
|
|
|
|
+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.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 显示在首页的特点 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Reiskuchen
|
|
|
|
+ * @since 2020-02-06
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class CharacteristicServiceImpl extends ServiceImpl<CharacteristicMapper, Characteristic> implements CharacteristicService {
|
|
|
|
+
|
|
|
|
+ @Value("${upload.path}")
|
|
|
|
+ private String uploadPath;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private CharacteristicMapper characteristicMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getCharacteristicList() {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ httpRespMsg.data = characteristicMapper.selectList(new QueryWrapper<Characteristic>().orderByAsc("id"));
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg insertOrUpdateCharacteristic(Characteristic characteristic, MultipartFile multipartFile) {
|
|
|
|
+ HttpRespMsg httpRespMsg = 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();
|
|
|
|
+ }
|
|
|
|
+ characteristic.setImageUrl("/upload/" + storedFileName);
|
|
|
|
+ }
|
|
|
|
+ if (characteristic.getId() == null) {
|
|
|
|
+ if (characteristicMapper.insert(characteristic) == 0) {
|
|
|
|
+ httpRespMsg.setError("新增失败");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (characteristicMapper.updateById(characteristic) == 0) {
|
|
|
|
+ httpRespMsg.setError("修改失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg deleteCharacteristic(Integer id) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ if (characteristicMapper.deleteById(id) == 0) {
|
|
|
|
+ httpRespMsg.setError("删除失败");
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+}
|