package com.lovenav.service.serviceImpl; import com.alibaba.fastjson.JSON; import com.lovenav.dao.NoticeDao; import com.lovenav.entity.Notice; import com.lovenav.service.NoticeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashMap; import java.util.List; @Service public class NoticeServiceImpl implements NoticeService { @Autowired private NoticeDao noticeDao; public String add(Notice notice){ HashMap hashMap = new HashMap<>(); Date date = new Date(System.currentTimeMillis()); notice.setCreatetime(date); int result = noticeDao.insert(notice); if(result>0){ hashMap.put("code",200); hashMap.put("msg","添加成功"); return JSON.toJSONString(hashMap); }else{ hashMap.put("code",500); hashMap.put("msg","添加成功"); return JSON.toJSONString(hashMap); } } public String delete(int id){ HashMap hashMap = new HashMap<>(); int result = noticeDao.deleteByPrimaryKey(id); if(result>0){ hashMap.put("code",200); hashMap.put("msg","删除成功"); return JSON.toJSONString(hashMap); }else{ hashMap.put("code",500); hashMap.put("msg","删除失败"); return JSON.toJSONString(hashMap); } } public String select(){ HashMap hashMap = new HashMap<>(); List result = noticeDao.selectAll(); if(result != null){ return JSON.toJSONString(result); }else{ hashMap.put("code",500); hashMap.put("msg","查找失败"); return JSON.toJSONString(hashMap); } } public String update(Notice notice){ HashMap hashMap = new HashMap<>(); int result = noticeDao.updateByPrimaryKeySelective(notice); if(result > 0){ hashMap.put("code",200); hashMap.put("msg","修改成功"); return JSON.toJSONString(hashMap); }else{ hashMap.put("code",500); hashMap.put("msg","修改失败"); return JSON.toJSONString(hashMap); } } }