代码提交
parent
7b9ffea60b
commit
54a4c84eb8
@ -1,17 +1,43 @@
|
||||
package com.hive.bee.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hive.bee.entity.BeeHive;
|
||||
import com.hive.bee.entity.BeeHiveLog;
|
||||
import com.hive.bee.mapper.HiveMapper;
|
||||
import com.hive.bee.service.HiveLogService;
|
||||
import com.hive.bee.service.HiveService;
|
||||
import com.hive.bee.vo.BeeHiveVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.hive.util.ConverterUtil.copySameFields;
|
||||
|
||||
|
||||
/**
|
||||
* 蜂箱 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
public class HiveServiceImpl extends ServiceImpl<HiveMapper, BeeHive> implements HiveService {
|
||||
@Autowired
|
||||
private HiveLogService hiveLogService;
|
||||
|
||||
@Override
|
||||
public void addAndEdit(BeeHive beeHive) {
|
||||
this.updateById(beeHive);
|
||||
BeeHiveLog beeHiveLog = new BeeHiveLog();
|
||||
BeeHiveVo beeHiveVo = new BeeHiveVo();
|
||||
//用来去除不需要的字段
|
||||
copySameFields(beeHive, beeHiveVo);
|
||||
copySameFields(beeHiveVo, beeHiveLog);
|
||||
beeHiveLog.setBeeHiveId(beeHive.getId());
|
||||
hiveLogService.save(beeHiveLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeeHive getOneBeeHive(String deviceId) {
|
||||
QueryWrapper<BeeHive> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(BeeHive::isDeleted,true).eq(BeeHive::getDeviceId,deviceId);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.hive.util;
|
||||
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class SpringContextUtil {
|
||||
public static <T> T getBean(ServletContext request, String name, Class<T> clazz){
|
||||
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(request);
|
||||
// 或者
|
||||
// webApplicationContext1.getBean(name, clazz)
|
||||
T bean = webApplicationContext.getBean(name, clazz);
|
||||
return bean;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue