12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.imooc.demo.service.impl;
- import java.util.Date;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.imooc.demo.dao.AreaDao;
- import com.imooc.demo.entity.Area;
- import com.imooc.demo.service.AreaService;
- @Service
- public class AreaServiceImpl implements AreaService {
-
- @Autowired
- private AreaDao areaDao;
- @Override
- public List<Area> getAreaList() {
-
- return areaDao.queryArea();
- }
- @Override
- public Area getAreaById(int areaId) {
-
- return areaDao.queryAreaById(areaId);
- }
- @Transactional
- @Override
- public boolean addArea(Area area) {
-
- if(area.getAreaName()!=null && !"".equals(area.getAreaName())) {
- area.setCreateTime(new Date());
- area.setLastEditTime(new Date());
- try {
- int insertArea = areaDao.insertArea(area);
- if(insertArea>0) {
- return true;
- }else {
- throw new RuntimeException("插入区域信息失败!");
- }
- }catch (Exception e) {
- throw new RuntimeException("插入区域信息失败:"+e.getMessage());
- }
- }else {
- throw new RuntimeException("区域信息不能为空!");
- }
- }
- @Override
- public Boolean modifyArea(Area area) {
-
- if(area.getAreaId()!=null && area.getAreaId()>0) {
- area.setLastEditTime(new Date());
- try {
- int updateArea = areaDao.updateArea(area);
- if(updateArea>0) {
- return true;
- }else {
- throw new RuntimeException("插入区域信息失败!");
- }
- }catch (Exception e) {
- throw new RuntimeException("插入区域信息失败:"+e.getMessage());
- }
- }else {
- throw new RuntimeException("区域信息不能为空!");
- }
- }
- @Override
- public Boolean deleteArea(int areaId) {
-
- if(areaId>0) {
-
- try {
- int deleteArea = areaDao.deleteArea(areaId);
- if(deleteArea>0) {
- return true;
- }else {
- throw new RuntimeException("插入区域信息失败!");
- }
- }catch (Exception e) {
- throw new RuntimeException("插入区域信息失败:"+e.getMessage());
- }
- }else {
- throw new RuntimeException("区域信息不能为空!");
- }
- }
- }
|