package com.newfiber.api.pc.controller.River; import com.github.pagehelper.PageInfo; import com.newfiber.api.config.FileVisitProperty; import com.newfiber.api.core.annotation.SysLog; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.core.support.HttpCode; import com.newfiber.api.core.utils.Constant; import com.newfiber.api.pc.model.River.*; import com.newfiber.api.pc.service.PatrolManageBaseService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.util.*; /** * patrolManageBase控制层 * * @author luzhan * @since 2021-07-15 */ @RestController @RequestMapping("/patrolManageBase") @Api(value = "API - PatrolManageBaseController", description = "巡查基础表(1 河道巡查 2官网巡查)") @Slf4j public class PatrolManageBaseController { @Autowired public PatrolManageBaseService patrolManageBaseService; /** 节点文件保存路径 */ @Value("${xnFile.pic}") private String xnFilePath; @Autowired private FileVisitProperty fileVisitProperty; /** * 获取主处理人 * @param params * @return */ @PostMapping("getProjectId") @ApiOperation(value = "获取patrol_manage_user_type列表",notes="") @SysLog(value="获取主处理人",actionType="4") public RespBodyObj<PatrolManageBase> getProjectId(@RequestBody ReqBodyObj<Map<String, Object>> params) { Long projectId = StringUtils.isEmpty(params.getData().get("projectId").toString())?null:Long.valueOf(params.getData().get("projectId").toString()); Integer patrolType = StringUtils.isEmpty(params.getData().get("patrolType").toString())?null:Integer.valueOf(params.getData().get("patrolType").toString()); PatrolManageBase list = patrolManageBaseService.getProjectId(projectId,patrolType); return RespBodyObj.ok(list); } @PostMapping("getProjectByUserType") @ApiOperation(value = "获取patrol_manage_base列表",notes="") @SysLog(value="获取patrol_manage_base列表",actionType="4") public RespBodyObj<PatrolManageUserDto> getProjectByUserType(@RequestBody ReqBodyObj<Map<String, Object>> params, HttpServletRequest request) { Integer patrolType = StringUtils.isEmpty(params.getData().get("patrolType").toString())?null:Integer.valueOf(params.getData().get("patrolType").toString()); String userNo = request.getHeader("userNo"); PatrolManageUserDto patrolManageBase =patrolManageBaseService.getProjectByUserType(patrolType,userNo); return RespBodyObj.ok(patrolManageBase); } @PostMapping("selectProjectList") @ApiOperation(value = "获取patrol_manage_base列表",notes="") @SysLog(value="获取patrol_manage_base列表",actionType="4") public RespBodyObj<List<PatrolManageProjectDto>> selectProjectList(@RequestBody ReqBodyObj<Map<String, Object>> params, HttpServletRequest request) { Integer projectParentId = StringUtils.isEmpty(params.getData().get("projectParentId").toString())?null:Integer.valueOf(params.getData().get("projectParentId").toString()); Integer patrolType = StringUtils.isEmpty(params.getData().get("patrolType").toString())?null:Integer.valueOf(params.getData().get("patrolType").toString()); String projectName = StringUtils.isEmpty(params.getData().get("projectName").toString())?null:String.valueOf(params.getData().get("projectName")); String userNo = request.getHeader("userNo"); List<PatrolManageProjectDto> patrolManageBase =patrolManageBaseService.selectProjectList(projectParentId,patrolType,projectName); return RespBodyObj.ok(patrolManageBase); } @PostMapping("getProject") @ApiOperation(value = "获取patrol_manage_base列表",notes="") @SysLog(value="获取patrol_manage_base列表",actionType="4") public RespBodyObj<List<PatrolManageBase>> getProject(@RequestBody ReqBodyObj<Map<String, Object>> params,HttpServletRequest request) { String patrolType = String.valueOf(params.getData().get("patrolType")); String userNo = request.getHeader("userNo"); String highest = request.getHeader("highest"); List<PatrolManageBase> patrolManageBase =patrolManageBaseService.listByUser(patrolType,userNo,highest); return RespBodyObj.ok(patrolManageBase); } @PostMapping("getProjectList") @ApiOperation(value = "获取patrol_manage_base列表",notes="") @SysLog(value="获取patrol_manage_base列表",actionType="4") public RespBodyObj getProjectList(@RequestBody ReqBodyObj<Map<String, Object>> params,HttpServletRequest request) { String patrolType = String.valueOf(params.getData().get("patrolType")); String userNo = request.getHeader("userNo"); String highest = request.getHeader("highest"); Map<String,Object> patrolManageBase =patrolManageBaseService.getProject(patrolType,userNo,highest); return RespBodyObj.ok(patrolManageBase); } /** * 获取patrolManageBase信息(分页) * @param params * @return */ @PostMapping("list") @ApiOperation(value = "获取patrol_manage_base列表",notes="") @SysLog(value="获取patrolManageBase信息(分页)",actionType="4") public RespBodyObj<PageInfo<PatrolManageBaseDto>> list(@RequestBody ReqBodyObj<Map<String, Object>> params) { Integer pageNo = params.getCurrent(); Integer pageSize = params.getSize(); String patrolType = String.valueOf(params.getData().get("patrolType")); String projectName = String.valueOf(params.getData().get("projectName")); PageInfo<PatrolManageBaseDto> patrolManageBase =patrolManageBaseService.listForPage(patrolType,projectName, pageNo, pageSize); return RespBodyObj.ok(patrolManageBase); } /** * 获取patrolManageBase信息(分页) * @param params * @return */ @PostMapping("baseList") @ApiOperation(value = "获取baseList列表",notes="") @SysLog(value="获取baseList(分页)",actionType="4") public RespBodyObj<PageInfo<PatrolManageBase>> baseList(@RequestBody ReqBodyObj<Map<String, Object>> params) { Integer pageNo = params.getCurrent(); Integer pageSize = params.getSize(); String patrolType = String.valueOf(params.getData().get("patrolType")); String areaCode = String.valueOf(params.getData().get("areaCode")); String projectName = String.valueOf(params.getData().get("projectName")); String projectParentId = String.valueOf(params.getData().get("projectParentId")); PageInfo<PatrolManageBase> patrolManageBase =patrolManageBaseService.selectBase(patrolType,areaCode,projectName,projectParentId, pageNo, pageSize); return RespBodyObj.ok(patrolManageBase); } /** * patrolManageBase添加或编辑 * @param param * @return */ @PostMapping("saveOrupdate") @ApiOperation(value = "新增或编辑patrol_manage_base",notes="根据实体修改patrol_manage_base") @SysLog(value="新增或编辑patrol_manage_base",actionType="1") public RespBodyObj saveOrupdate(@RequestBody ReqBodyObj<PatrolManageBase> param) { try { boolean b = patrolManageBaseService.insertOrUpdate(param.getData()); return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED); } catch (Exception e) { log.error("/patrolManageBase/saveOrupdate", e); return RespBodyObj.error(Constant.ERROR); } } /** * patrolManageBase批量移除 * * @param params * @return */ @PostMapping("removeBatch") @ApiOperation(value = "批量删除辑patrol_manage_base",notes="根据id批量删除patrol_manage_base") @SysLog(value="批量删除辑patrol_manage_base",actionType="2") public RespBodyObj removeBatch(@RequestBody ReqBodyObj<Map<String, Object>> params) { try { List<Long> list = (List<Long>) params.getData().get("ids"); boolean b = patrolManageBaseService.deleteBatchIds(list); return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED); } catch (Exception e) { log.error("/patrolManageBase/removeBatch", e); return RespBodyObj.error(Constant.ERROR); } } /** * patrolManageBase查询单个 * * @param params * @return */ @PostMapping("selectOne") @ApiOperation(value = "查询patrol_manage_base",notes="根据主键查询patrol_manage_base") @SysLog(value="查询patrol_manage_base",actionType="4") public RespBodyObj<PatrolManageBase> selectOne(@RequestBody ReqBodyObj<Map<String, Object>> params) { if (params.getData() == null) { return RespBodyObj.error(HttpCode.BAD_REQUEST); } if (StringUtils.isEmpty(params.getData().get("id" ).toString())) { return RespBodyObj.error(HttpCode.BAD_REQUEST); } String id = params.getData().get("id" ).toString(); PatrolManageBase patrolManageBase = patrolManageBaseService.selectById(id); return RespBodyObj.ok(patrolManageBase); } /** * 上传图片接口 * @param file * @param request * @return * @throws Exception */ @ApiOperation(value = "上传图片") @ResponseBody @PostMapping("/uploadBatch") @SysLog(value="上传图片",actionType="1") public RespBodyObj upload(@RequestParam("file") MultipartFile[] file,Integer patrolType,String fromType, HttpServletRequest request) throws Exception { StringBuilder strBD = new StringBuilder(); strBD.append("|upload"); String userNo = request.getHeader("userNo"); List<String> imagePath = new ArrayList<>(); List<PartolManagePic> result = new ArrayList<>(); if (file != null) { for (int i = 0; i < file.length; i++) { String path = ""; MultipartFile file1 = file[i]; try { String filename = file1.getOriginalFilename(); String suffix = filename.substring(filename.lastIndexOf(".")); Calendar instance = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(instance.get(Calendar.YEAR)) .append(File.separator) .append(instance.get(Calendar.MARCH) + 1). append(File.separator) .append(System.currentTimeMillis()).append(suffix); File fileName = new File(xnFilePath , sb.toString()); path = sb.toString(); if(!fileName.getParentFile().exists()){ fileName.mkdirs(); } file1.transferTo(fileName); } catch (Exception e) { RespBodyObj.error(); } imagePath.add(path); } result = batchInsertImg(userNo,patrolType,fromType, imagePath); } return RespBodyObj.ok(result); } /** * 组装图片 * @param userNo * @param imagePath * @return */ @ApiOperation(value = "图片组装") @ResponseBody private List<PartolManagePic> batchInsertImg(String userNo,Integer patrolType,String fromType, List<String> imagePath) { List<PartolManagePic> result = new ArrayList<>(); try { if(!imagePath.isEmpty()){ for (String e : imagePath) { PartolManagePic riverPics = new PartolManagePic(); riverPics.setCreateUserNo(userNo); riverPics.setPicName(e); riverPics.setPicAddress(e); riverPics.setType(patrolType.byteValue()); if(!StringUtils.isEmpty(fromType) && "app".equalsIgnoreCase(fromType)){ riverPics.setRealPath(fileVisitProperty.getAppPic()+e); }else{ riverPics.setRealPath(fileVisitProperty.getWebPic()+e); } riverPics.setCreateTime(new Date()); result.add(riverPics); } } }catch (Exception e){ log.info("/patrol/uploadBatch",e); } return result; } /** * patrolManageBase添加或编辑 * @param param * @return */ @PostMapping("saveOrUpdateUser") @ApiOperation(value = "新增或编辑patrol_manage_base",notes="根据实体修改patrol_manage_base") @SysLog(value="新增或编辑patrol_manage_base",actionType="1") public RespBodyObj saveOrUpdateUser(@RequestBody ReqBodyObj<PatrolManageBaseVo> param) { try { return patrolManageBaseService.saveOrUpdateUser(param.getData()); } catch (Exception e) { log.error("/patrolManageBase/saveOrupdate", e); return RespBodyObj.error(Constant.ERROR); } } }