ViolationCaseFileController.java 6.99 KB
package com.trash.casefile.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.trash.casefile.domain.ViolationWarningInformation;
import com.trash.casefile.domain.vo.ViolationCaseFileVo;
import com.trash.casefile.domain.vo.ViolationWarningInformationVo;
import com.trash.office.domain.UploadFile;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.trash.common.annotation.Log;
import com.trash.common.core.controller.BaseController;
import com.trash.common.core.domain.AjaxResult;
import com.trash.common.enums.BusinessType;
import com.trash.casefile.domain.ViolationCaseFile;
import com.trash.casefile.service.IViolationCaseFileService;
import com.trash.common.utils.DateUtils;
import com.trash.common.utils.SecurityUtils;
import com.trash.common.utils.poi.ExcelUtil;
import com.trash.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 平台违规案卷Controller
 * 
 * @author 2c
 * @date 2023-05-11
 */
@RestController
@RequestMapping("/casefile/violationCaseFile")
public class ViolationCaseFileController extends BaseController
{
    @Autowired
    private IViolationCaseFileService violationCaseFileService;

    /**
     * 查询平台违规案卷列表
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViolationCaseFile violationCaseFile)
    {
        startPage();
        List<ViolationCaseFile> list = violationCaseFileService.selectViolationCaseFileList(violationCaseFile);
        return getDataTable(list);
    }

    /**
     * 导出平台违规案卷列表
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:export')")
    @Log(title = "平台违规案卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ViolationCaseFile violationCaseFile)
    {
        List<ViolationCaseFile> list = violationCaseFileService.selectViolationCaseFileList(violationCaseFile);
        ExcelUtil<ViolationCaseFile> util = new ExcelUtil<ViolationCaseFile>(ViolationCaseFile.class);
        return util.exportExcel(list, "平台违规案卷数据");
    }

    /**
     * 获取平台违规案卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(violationCaseFileService.selectViolationCaseFileById(id));
    }

    /**
     * 新增平台违规案卷
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:add')")
    @Log(title = "平台违规案卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam(value = "fileList") MultipartFile[] files, ViolationCaseFile violationCaseFile) throws IOException
    {
        return toAjax(violationCaseFileService.insertViolationCaseFile(files,violationCaseFile));
    }

    /**
     * 修改平台违规案卷
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:edit')")
    @Log(title = "平台违规案卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestParam(value = "fileList") MultipartFile[] files, String violationCaseFile, String[] uploadFilesList) throws IOException
    {
        ViolationCaseFileVo violationCaseFileVo = new ViolationCaseFileVo();
        violationCaseFileVo.setViolationCaseFile(JSON.parseObject(violationCaseFile, ViolationCaseFile.class));
        List<UploadFile> uploadFileList = new ArrayList<>();
        for (String uploadFile : uploadFilesList) {
            UploadFile uploadFile1 = JSON.parseObject(uploadFile,UploadFile.class);
            if(uploadFile1!=null){
                if(uploadFile1.getId()!=null){
                    uploadFileList.add(uploadFile1);
                }
            }
        }
        violationCaseFileVo.setUploadFiles(uploadFileList);
        return toAjax(violationCaseFileService.updateViolationCaseFile(files,violationCaseFileVo));
    }
    
    @PutMapping(value="updateViolationCaseFileReader")
    public int updateViolationCaseFileReader(@RequestBody ViolationCaseFile violationCaseFile) throws IOException
    {	
    	try {

        	violationCaseFile.setReadBy(SecurityUtils.getUsername());
        	violationCaseFile.setReadTime(DateUtils.getNowDate());
        	violationCaseFileService.updateViolationCaseFile(violationCaseFile);
        	return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
    }
    
    
    String[] caseType = {"进入非专用车辆","无许可手续(工)","无许可手续(消)","黄土覆盖情况","出入口路面污染","出入口道路硬化","车辆冲洗是否到位",
    	"雾炮机是否正常开启","使用费专用车运输","监控点位未对准","未报开工作业","视频设备离线超时报警","三无车辆进入工地","未按时间作业",
    	"未报开工作业","视频设备离线超时报警","三无车辆进入消纳场","未到指定的消纳场作业","离线运输报警(工)","离线运输报警(消)","未激活车辆作业",
    		"未核准作业车辆作业","未按线路行驶","闯禁行驶","失信车辆作业","其他1","其他2","其他3","其他4","其他5"};

    @GetMapping(value = "/caseTable")
    public AjaxResult getTable(){
    	List<HashMap<String, String>> maps = new ArrayList<HashMap<String,String>>();
    	
    	
    	
    	List<ViolationCaseFile> list = violationCaseFileService.selectViolationCaseFileList(new ViolationCaseFile());
    	
    	for(String type:caseType){
    		
    		HashMap<String, String> map = new HashMap<>();
    		
    		map.put("type", type);
    		
    		int count = 0;
    		int repCount = 0;
    		
    		for(ViolationCaseFile file:list){
    			if(type.equals(file.getViolationType())){
    				count +=1;
    				if(file.getReadBy() != null && !file.getReadBy().isEmpty()){
    					repCount += 1;
    				}
    				
    			}
    			
    			
    		}
    		
    		map.put("count", count + "");
    		map.put("repCount", repCount + "");
    		
    		if(count == 0){
    			double pct = ((double)repCount)/((double)count);
        		map.put("repPct","0%");
        		maps.add(map);
    		}else{
    			double pct = ((double)repCount)/((double)count);
        		map.put("repPct",(pct*100) + "%");
        		maps.add(map);
    		}
    		
    		
    		
    	}
    	
    
    	
    	return AjaxResult.success(maps);
    }
    
    
    

    /**
     * 删除平台违规案卷
     */
    @PreAuthorize("@ss.hasPermi('casefile:violationCaseFile:remove')")
    @Log(title = "平台违规案卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)  throws IOException
    {
        return toAjax(violationCaseFileService.deleteViolationCaseFileByIds(ids));
    }
}