|
@ -1,16 +1,24 @@
|
|
package com.yihu.jw.base.service.advrtisement;
|
|
package com.yihu.jw.base.service.advrtisement;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.yihu.jw.base.dao.a2dao.MediicineDeviceDao;
|
|
import com.yihu.jw.base.dao.a2dao.MediicineDeviceDao;
|
|
import com.yihu.jw.base.dao.advertisement.AdvertisementLaunchDAO;
|
|
import com.yihu.jw.base.dao.advertisement.AdvertisementLaunchDAO;
|
|
import com.yihu.jw.base.dao.advertisement.AdvertisementPuttingAdminDAO;
|
|
import com.yihu.jw.base.dao.advertisement.AdvertisementPuttingAdminDAO;
|
|
|
|
import com.yihu.jw.base.util.ConstantUtils;
|
|
|
|
import com.yihu.jw.entity.a1entity.MediicineDeviceUser;
|
|
import com.yihu.jw.entity.a1entity.Mediicinedevice;
|
|
import com.yihu.jw.entity.a1entity.Mediicinedevice;
|
|
import com.yihu.jw.entity.adv.AdvertisementLaunchDO;
|
|
import com.yihu.jw.entity.adv.AdvertisementLaunchDO;
|
|
import com.yihu.jw.entity.adv.AdvertisementPuttingAdminDO;
|
|
import com.yihu.jw.entity.adv.AdvertisementPuttingAdminDO;
|
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaunchDO, AdvertisementLaunchDAO> {
|
|
public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaunchDO, AdvertisementLaunchDAO> {
|
|
@ -20,14 +28,19 @@ public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaun
|
|
MediicineDeviceDao deviceDao;
|
|
MediicineDeviceDao deviceDao;
|
|
@Autowired
|
|
@Autowired
|
|
AdvertisementPuttingAdminDAO adminDAO;
|
|
AdvertisementPuttingAdminDAO adminDAO;
|
|
|
|
@Autowired
|
|
|
|
HibenateUtils hibenateUtils;
|
|
|
|
|
|
public List<AdvertisementLaunchDO> one(String advId) {
|
|
public List<AdvertisementLaunchDO> one(String advId) {
|
|
return advertisementLaunchDAO.findByAdvId(advId);
|
|
return advertisementLaunchDAO.findByAdvId(advId);
|
|
}
|
|
}
|
|
|
|
|
|
public List<AdvertisementLaunchDO> solo(String machineCode) {
|
|
|
|
Mediicinedevice mediicinedevice =deviceDao.findByMachineCode(machineCode);
|
|
|
|
return advertisementLaunchDAO.findByDevId(mediicinedevice.getId());
|
|
|
|
|
|
public List<AdvertisementPuttingAdminDO> solo(String equNum) {
|
|
|
|
Mediicinedevice mediicinedevice =deviceDao.findByEquNum(equNum);
|
|
|
|
if (null==mediicinedevice){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return adminDAO.findByDevIdInfo(mediicinedevice.getId());
|
|
}
|
|
}
|
|
|
|
|
|
public List<AdvertisementPuttingAdminDO> info(String devId) {
|
|
public List<AdvertisementPuttingAdminDO> info(String devId) {
|
|
@ -37,4 +50,97 @@ public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaun
|
|
public List<Mediicinedevice> devInfo(String advId) {
|
|
public List<Mediicinedevice> devInfo(String advId) {
|
|
return deviceDao.findByAdvIdInfo(advId);
|
|
return deviceDao.findByAdvIdInfo(advId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public JSONObject allotDevice(String advIds, String devIds,Boolean isAll) {
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
if (StringUtils.isEmpty(advIds)) {
|
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
//绑定设备
|
|
|
|
for (String advId : advIds.split(",")) {
|
|
|
|
if (!StringUtils.isEmpty(advId)) {
|
|
|
|
//全部设备
|
|
|
|
if(isAll) {
|
|
|
|
Iterable<Mediicinedevice> lists = deviceDao.findAll();
|
|
|
|
Iterator iterator = lists.iterator();
|
|
|
|
while(iterator.hasNext()){
|
|
|
|
Mediicinedevice mediicinedevice = ((Mediicinedevice) iterator.next());
|
|
|
|
if (mediicinedevice != null) {
|
|
|
|
String countSql = " select " +
|
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
|
|
" from adv_launch t " +
|
|
|
|
" " +
|
|
|
|
" where " +
|
|
|
|
" 1=1 and t.dev_id = '" + mediicinedevice.getId() + "' AND t.adv_id = '" + advId + "'";
|
|
|
|
int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
|
if (count > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AdvertisementPuttingAdminDO adminDO=adminDAO.findAdvertisementPuttingAdminDOById(advId);
|
|
|
|
AdvertisementLaunchDO launchDO = new AdvertisementLaunchDO();
|
|
|
|
launchDO.setDevId(mediicinedevice.getId());
|
|
|
|
launchDO.setAdvId(advId);
|
|
|
|
advertisementLaunchDAO.save(launchDO);
|
|
|
|
adminDO.setDel(0);
|
|
|
|
adminDO.setForbidden(0);
|
|
|
|
adminDAO.save(adminDO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//删除移除设备
|
|
|
|
String sql = "SELECT\n" +
|
|
|
|
"\tt.id AS id,\n" +
|
|
|
|
"\tt.dev_id AS devId,\n" +
|
|
|
|
"\tt.adv_id AS advId,\n" +
|
|
|
|
"\tt.create_time AS createTime,\n" +
|
|
|
|
"\tt.create_user AS createUser,\n" +
|
|
|
|
"\tt.create_user_name AS createUserName,\n" +
|
|
|
|
"\tt.update_time AS updateTime,\n" +
|
|
|
|
"\tt.update_user AS updateUser,\n" +
|
|
|
|
"\tt.update_user_name AS updateUserName\n" +
|
|
|
|
"FROM\n" +
|
|
|
|
"\tadv_launch AS t\n" +
|
|
|
|
"WHERE\n" +
|
|
|
|
" t.adv_id = '" + advId + "'" +
|
|
|
|
"AND '," + devIds + ",' NOT LIKE CONCAT('%,',t.dev_id,',%')";
|
|
|
|
List<Map<String,Object>> list=null;
|
|
|
|
list = hibenateUtils.createSQLQuery(sql);
|
|
|
|
if (list != null && list.size() > 0) {
|
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
|
AdvertisementLaunchDO advertisementLaunchDO = advertisementLaunchDAO.findOne(stringObjectMap.get("id").toString());
|
|
|
|
advertisementLaunchDAO.delete(advertisementLaunchDO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String deviceId : devIds.split(",")) {
|
|
|
|
if (!StringUtils.isEmpty(deviceId)) {
|
|
|
|
String countSql = " select " +
|
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
|
|
" from " +
|
|
|
|
" adv_launch AS t " +
|
|
|
|
" where " +
|
|
|
|
" 1=1 AND t.dev_id = '" + deviceId + "' AND t.adv_id = '" + advId + "'";
|
|
|
|
int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
|
if (count > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AdvertisementLaunchDO advertisementLaunchDO = new AdvertisementLaunchDO();
|
|
|
|
advertisementLaunchDO.setDevId(deviceId);
|
|
|
|
advertisementLaunchDO.setAdvId(advId);
|
|
|
|
advertisementLaunchDAO.save(advertisementLaunchDO);
|
|
|
|
AdvertisementPuttingAdminDO adminDO=adminDAO.findAdvertisementPuttingAdminDOById(advId);
|
|
|
|
adminDO.setDel(0);
|
|
|
|
adminDO.setForbidden(0);
|
|
|
|
adminDAO.save(adminDO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
|
return result;
|
|
|
|
}
|
|
}
|
|
}
|