Forráskód Böngészése

广告投放接口

chenjiasheng 3 éve
szülő
commit
122bc3b257

+ 4 - 7
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/adv/AdvertisementPuttingAdminEndPoint.java

@ -68,14 +68,11 @@ public class AdvertisementPuttingAdminEndPoint extends EnvelopRestEndpoint {
                                          @RequestParam(value = "advIds",required = true) String advIds,
                                      @ApiParam(name = "devIds",value = "设备id,多个中间用,隔开,所有设备不传",required = false)
                                      @RequestParam(value = "devIds",required = false)String devIds){
        if (StringUtils.isBlank(advIds)){
            return failed("请确认该广告是否存在!");
        }
        String str=advrtisementService.updateLaunchStatus(advIds,devIds);
        if (str.contains("已删除")||str.contains(("不存在"))||str.contains("已禁用")){
            return failed(str);
        JSONObject result =launchService.allotDevice(advIds,devIds);
        if (StringUtils.isEmpty(result.getString("该广告状态错误"))){
            return success(result.get("response"));
        }
        return success(str);
        return success(result.get("response")+","+result.get("该广告状态错误"));
    }
    @GetMapping(value = "/unlaunch")
    @ApiOperation(value = "取消投放广告")

+ 101 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/advrtisement/AdvertisementLaunchService.java

@ -1,16 +1,23 @@
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.advertisement.AdvertisementLaunchDAO;
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.adv.AdvertisementLaunchDO;
import com.yihu.jw.entity.adv.AdvertisementPuttingAdminDO;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Service
public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaunchDO, AdvertisementLaunchDAO> {
@ -20,6 +27,8 @@ public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaun
    MediicineDeviceDao deviceDao;
    @Autowired
    AdvertisementPuttingAdminDAO adminDAO;
    @Autowired
    HibenateUtils hibenateUtils;
    public List<AdvertisementLaunchDO> one(String advId) {
        return advertisementLaunchDAO.findByAdvId(advId);
@ -40,4 +49,96 @@ public class AdvertisementLaunchService extends BaseJpaService<AdvertisementLaun
    public List<Mediicinedevice> devInfo(String advId) {
        return deviceDao.findByAdvIdInfo(advId);
    }
    public JSONObject allotDevice(String advIds, String devIds) {
        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(StringUtils.isEmpty(devIds)) {
                    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;
    }
}