地质所 沉降监测网建设项目
zmk
2024-07-03 5606efe6f2778ad09d8b35280d6360cfe8f34d91
javaweb-plus/javaweb-admin/src/main/java/com/javaweb/web/controller/system/SysIndexController.java
@@ -5,18 +5,20 @@
import java.util.List;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.javaweb.cms.util.CmsConstants;
import com.javaweb.common.core.domain.AjaxResult;
import com.javaweb.common.utils.Arith;
import com.javaweb.common.utils.StringUtils;
import com.javaweb.geo.domain.Hole;
import com.javaweb.geo.domain.HoleMedia;
import com.javaweb.geo.domain.Project;
import com.javaweb.geo.domain.*;
import com.javaweb.geo.enums.RecordType;
import com.javaweb.geo.mapper.HoleMapper;
import com.javaweb.geo.service.IHoleMediaService;
import com.javaweb.geo.service.IHoleService;
import com.javaweb.geo.service.IProjectService;
import com.javaweb.geo.mapper.ProjectCameraMapper;
import com.javaweb.geo.mapper.TubLogMapper;
import com.javaweb.geo.service.*;
import com.javaweb.geo.vo.DrillDateVo;
import com.javaweb.geo.vo.IndexVo;
import com.javaweb.geo.vo.ProjectProcessVO;
import com.javaweb.system.service.ISysConfigService;
@@ -24,7 +26,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.*;
import com.javaweb.common.config.Global;
import com.javaweb.common.core.controller.BaseController;
import com.javaweb.framework.util.ShiroUtils;
@@ -32,10 +34,6 @@
import com.javaweb.system.domain.SysUser;
import com.javaweb.system.service.ISysMenuService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
@@ -46,6 +44,14 @@
 */
@Controller
public class SysIndexController extends BaseController {
    private String prefix = "system/camera_tub";
    private String appkey = "af786eacc71d43ef9393c028cf4face7";
    private String secret = "9ad87671f63d2258af6fd9b2e5fa6005";
    private String postUrl ="https://open.ys7.com/api/lapp/token/get";
    @Autowired
    private ISysMenuService menuService;
@@ -61,6 +67,19 @@
    @Autowired
    private IHoleMediaService holeMediaService;
    @Autowired
    private TubLogMapper tubLogMapper;
    @Autowired
    private ProjectCameraMapper projectCameraMapper;
    @Autowired
    private IProjectCameraService cameraService;
    @Autowired
    private IHoleLogService holeLogService;
    private String getAdminIndex() {
        return configService.selectConfigByKey(CmsConstants.KEY_ADMIN_INDEX);
    }
@@ -68,6 +87,16 @@
    @RequestMapping("/admin")
    public String admin() {
        return "forward:/index";
    }
    @RequestMapping("/system/camera")
    public String cameraList() {
        return prefix + "/camera_list";
    }
    @RequestMapping("/system/tub")
    public String tubList() {
        return prefix + "/tub_list";
    }
    // 系统首页
@@ -113,12 +142,14 @@
    public String main(ModelMap mmap) {
        mmap.put("version", Global.getVersion());
        String loginname =  ShiroUtils.getLoginName();
        mmap.put("loginuser",loginname);
        return "main";
    }
    // 系统介绍
    @ResponseBody
    @GetMapping("/system/project")
    @GetMapping("/system/stat/project")
    public AjaxResult project() {
        AjaxResult ajaxResult = AjaxResult.success();
        List<Project> projects = projectService.selectProjectList(new Project());
@@ -131,7 +162,7 @@
     * @return
     */
    @ResponseBody
    @GetMapping("/system/totalProcess")
    @GetMapping("/system/stat/totalProcess")
    public AjaxResult totalProcess() {
        AjaxResult ajaxResult = AjaxResult.success();
        Hole hole = holeService.selectHoleTotalProcess();
@@ -145,14 +176,17 @@
     * @return
     */
    @ResponseBody
    @GetMapping("/system/projectProcess")
    @GetMapping("/system/stat/projectProcess")
    public AjaxResult projectProcess() {
        AjaxResult ajaxResult = AjaxResult.success();
        List<Hole> holes = holeService.selectHoleProjectProcess();
        Map<String, Double> holeMap = new HashMap<>();
        for (Hole hole : holes) {
            Double val = Arith.div(hole.getFootageCpl(), hole.getFootage(), 2);
            val = Arith.round(val * 100, 2);
            Double val =0.0d;
            if(ObjectUtil.isNotEmpty(hole.getFootageCpl()) && ObjectUtil.isNotEmpty(hole.getFootage())) {
                val = Arith.div(hole.getFootageCpl(), hole.getFootage(), 2);
                val = Arith.round(val * 100, 2);
            }
            holeMap.put(hole.getProjectId(), val);
        }
@@ -164,13 +198,29 @@
                String ids = projects.get(i).getIds();
                Double val = holeMap.get(ids);
                vo = new ProjectProcessVO();
                vo.setIds(projects.get(i).getIds());
                vo.setRanking(i + 1);
                vo.setStation(projects.get(i).getCode());
                vo.setStation(projects.get(i).getFullName());
                vo.setValue(val);
                vo.setLng(projects.get(i).getLng());
                vo.setLat(projects.get(i).getLat());
                if (val == null) {
                    vo.setValue(0.0d);
                }
                vo.setStatus(projects.get(i).getStatus());
                String []statusName ={"协调中","待开工","进行中"};
                String status = projects.get(i).getStatus();
                if(status.equals("0")){
                    vo.setStatus(statusName[0]);
                }else if(status.equals("1")){
                    vo.setStatus(statusName[1]);
                }else if(status.equals("2")){
                    vo.setStatus(statusName[2]);
                }else{
                    vo.setStatus("未知");
                }
                vos.add(vo);
            }
        }
@@ -185,10 +235,9 @@
     * @return
     */
    @ResponseBody
    @GetMapping("/system/indexVo")
    public AjaxResult projectProcess2() {
    @GetMapping("/system/stat/indexDataCount")
    public AjaxResult indexDataCount() {
        IndexVo result = new IndexVo();
        //=============================查询场地数量===============================
        List<Project> projectList = projectService.selectProjectCountByStatus();
        if (!ObjectUtils.isEmpty(projectList)) {
@@ -197,23 +246,22 @@
                    result.setProjectStatus0(item.getStatusNumber());
                }
                if (RecordType.projectStatus1.getId().equals(item.getStatus())) {
                    result.setProjectStatus0(item.getStatusNumber());
                    result.setProjectStatus1(item.getStatusNumber());
                }
                if (RecordType.projectStatus2.getId().equals(item.getStatus())) {
                    result.setProjectStatus0(item.getStatusNumber());
                    result.setProjectStatus2(item.getStatusNumber());
                }
            }
        }
        if (ObjectUtils.isEmpty(result.getProjectStatus0())) {
            result.setProjectStatus0(0);
        }
        if (ObjectUtils.isEmpty(result.getProjectStatus1())) {
            result.setProjectStatus0(0);
            result.setProjectStatus1(0);
        }
        if (ObjectUtils.isEmpty(result.getProjectStatus2())) {
            result.setProjectStatus0(0);
            result.setProjectStatus2(0);
        }
        if (ObjectUtils.isEmpty(result.getProjectStatus2())) {
            result.setProjectStatus0(0);
        }
        //=============================查询进尺===============================
        Hole hole = holeService.selectHoleTotalProcess();
        result.setFootageCplCount(hole.getFootageCpl());
@@ -223,8 +271,125 @@
        HoleMedia holeMedia = holeMediaService.selectHoleMediaNumber();
        result.setFileCount(holeMedia.getNumber());
        Integer cameraCount = projectCameraMapper.count();
        result.setCameraCount(cameraCount);
        return AjaxResult.success("查询成功",result);
    }
    /**
     * 统计材料的消耗
     * @return
     */
    @ResponseBody
    @GetMapping("/system/stat/tubLogData")
    public AjaxResult tubLogData() {
        AjaxResult ajaxResult = new AjaxResult();
        List<TubLog> tubLogs = tubLogMapper.countTubLogDate(null);
        ajaxResult.put("tubLogs",tubLogs);
        return  ajaxResult;
    }
    /**
     * 获取在线摄像头的信息
     * @return
     */
    @ResponseBody
    @GetMapping("/system/stat/cameraData")
    public AjaxResult cameraData() {
        AjaxResult ajaxResult = new AjaxResult();
        List<ProjectCamera> cameraDataList = cameraService.selectCameraDataOnLine();
        ajaxResult.put("cameraData",cameraDataList);
        return ajaxResult;
    }
    /**
     * 根据projectId获取在线摄像头的信息
     * @return
     */
    @ResponseBody
    @GetMapping("/system/stat/cameraData/{projectId}")
    public AjaxResult cameraData2(@PathVariable("projectId") String projectId) {
        AjaxResult ajaxResult = new AjaxResult();
        ProjectCamera param = new ProjectCamera();
        param.setProjectId(projectId);
        List<ProjectCamera> cameraDataList = cameraService.selectProjectCameraList(param);
        if (!ObjectUtils.isEmpty(cameraDataList)){
            for (ProjectCamera item : cameraDataList) {
                String url = item.getIp();
                Map<String, Object> paramMap = new HashMap<>();
                paramMap.put("appKey", appkey);
                paramMap.put("appSecret", secret);
                HttpResponse response = HttpRequest.post(postUrl) .form(paramMap).execute();
                String body = response.body();
                JSONObject jsonObject = JSONUtil.parseObj(body);
                String code = jsonObject.getStr("code");
                StringBuffer buffer = new StringBuffer();
                if(code.equals("200")){
                    JSONObject data  = (JSONObject) jsonObject.get("data");
                    String token = data.getStr("accessToken");
                    buffer.append("https://open.ys7.com/console/jssdk/pc.html?accessToken=");
                    buffer.append(token);
                    buffer.append("&url=");
                    buffer.append(url);
                }
                logger.debug(buffer.toString());
                item.setUrl(buffer.toString());
            }
        }
        ajaxResult.put("cameraDataList",cameraDataList);
        return ajaxResult;
    }
    /**
     * 根据projectId获取在线摄像头的信息
     * @return
     */
    @GetMapping("/player")
    public String player(String projectId,ModelMap mmap) {
        ProjectCamera param = new ProjectCamera();
        param.setProjectId(projectId);
        List<ProjectCamera> cameraDataList = cameraService.selectProjectCameraList(param);
        if (!ObjectUtils.isEmpty(cameraDataList)){
            for (ProjectCamera item : cameraDataList) {
                String url = item.getIp();
                Map<String, Object> paramMap = new HashMap<>();
                paramMap.put("appKey", appkey);
                paramMap.put("appSecret", secret);
                HttpResponse response = HttpRequest.post(postUrl) .form(paramMap).execute();
                String body = response.body();
                JSONObject jsonObject = JSONUtil.parseObj(body);
                String code = jsonObject.getStr("code");
                StringBuffer buffer = new StringBuffer();
                if(code.equals("200")){
                    JSONObject data  = (JSONObject) jsonObject.get("data");
                    String token = data.getStr("accessToken");
                    buffer.append("https://open.ys7.com/console/jssdk/pc.html?accessToken=");
                    buffer.append(token);
                    buffer.append("&url=");
                    buffer.append(url);
                }
                item.setUrl(buffer.toString());
            }
        }
        mmap.put("cameraDataList",cameraDataList);
        return prefix + "/player2";
    }
    /**
     * 统计最近10天进尺量
     * @return
     */
    @ResponseBody
    @GetMapping("/system/stat/sumHoleLog")
    public AjaxResult sumHoleLog() {
        AjaxResult ajaxResult =  AjaxResult.success();
        List<DrillDateVo> drillDateList = holeLogService.SUMHoleLog();
        ajaxResult.put("drillDateList",drillDateList);
        return ajaxResult;
    }
}