package com.sooka.sponest.data.generalbusiness.controller; import com.alibaba.fastjson.JSON; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.system.api.domain.SysUser; import com.sooka.sponest.data.generalbusiness.domain.CenterdataTKeyProjects; import com.sooka.sponest.data.generalbusiness.domain.CenterdataTKeyProjectsBo; import com.sooka.sponest.data.generalbusiness.service.ICenterdataTKeyProjectsService; import com.sooka.sponest.data.utils.ExcelUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * 重点工程Controller * * @author ruoyi * @date 2023-04-23 */ @Api(tags = "数据中心重点工程控制器") @RestController @RequestMapping("/projects") public class CenterdataTKeyProjectsController extends BaseController { @Autowired private ICenterdataTKeyProjectsService centerdataTKeyProjectsService; /** * 查询重点工程列表 */ @ApiImplicitParams(value = { @ApiImplicitParam(name = "id", value = "主键id", dataType = "String", required = false), @ApiImplicitParam(name = "projectName", value = "工程名称", dataType = "String", required = false), @ApiImplicitParam(name = "projectTarget", value = "工程目标", dataType = "String", required = false), @ApiImplicitParam(name = "projectType", value = "工程类型", dataType = "String", required = false), @ApiImplicitParam(name = "projectLevel", value = "工程级别", dataType = "String", required = false), @ApiImplicitParam(name = "constructionUnit", value = "建设单位", dataType = "String", required = false), @ApiImplicitParam(name = "principal", value = "负责人", dataType = "String", required = false), @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "String", required = false), @ApiImplicitParam(name = "constructionSite", value = "建设地点", dataType = "String", required = false), @ApiImplicitParam(name = "constructionArea", value = "建筑面积", dataType = "String", required = false), @ApiImplicitParam(name = "longitude", value = "经度", dataType = "String", required = false), @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "String", required = false), @ApiImplicitParam(name = "cameraSystem", value = "所属分类", dataType = "String", required = false), @ApiImplicitParam(name = "introduction", value = "工程简介", dataType = "String", required = false), @ApiImplicitParam(name = "photoId", value = "附件", dataType = "String", required = false), }) @ApiOperation(value = "数据中心查询重点工程列表", notes = "数据中心查询重点工程列表") @RequiresPermissions("forest:keyProjects:list") @GetMapping("/list") public TableDataInfo list(CenterdataTKeyProjects centerdataTKeyProjects) { startPage(); List list = centerdataTKeyProjectsService.selectCenterdataTKeyProjectsList(centerdataTKeyProjects); return getDataTable(list); } /** * 导出重点工程列表 */ @ApiImplicitParams(value = { @ApiImplicitParam(name = "id", value = "主键id", dataType = "String", required = false), @ApiImplicitParam(name = "projectName", value = "工程名称", dataType = "String", required = false), @ApiImplicitParam(name = "projectTarget", value = "工程目标", dataType = "String", required = false), @ApiImplicitParam(name = "projectType", value = "工程类型", dataType = "String", required = false), @ApiImplicitParam(name = "projectLevel", value = "工程级别", dataType = "String", required = false), @ApiImplicitParam(name = "constructionUnit", value = "建设单位", dataType = "String", required = false), @ApiImplicitParam(name = "principal", value = "负责人", dataType = "String", required = false), @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "String", required = false), @ApiImplicitParam(name = "constructionSite", value = "建设地点", dataType = "String", required = false), @ApiImplicitParam(name = "constructionArea", value = "建筑面积", dataType = "String", required = false), @ApiImplicitParam(name = "longitude", value = "经度", dataType = "String", required = false), @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "String", required = false), @ApiImplicitParam(name = "cameraSystem", value = "所属分类", dataType = "String", required = false), @ApiImplicitParam(name = "introduction", value = "工程简介", dataType = "String", required = false), @ApiImplicitParam(name = "photoId", value = "附件", dataType = "String", required = false), }) @ApiOperation(value = "数据中心导出重点工程列表", notes = "数据中心导出重点工程列表") @RequiresPermissions("forest:keyProjects:export") @Log(title = "重点工程", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, CenterdataTKeyProjects centerdataTKeyProjects) { List list = centerdataTKeyProjectsService.selectCenterdataTKeyProjectsList(centerdataTKeyProjects); ExcelUtil util = new ExcelUtil<>(CenterdataTKeyProjects.class); util.exportExcel(response, list, "重点工程数据"); } /** * 获取重点工程详细信息 */ @ApiImplicitParams(value = { @ApiImplicitParam(name = "id", value = "主键id", dataType = "String", required = true) }) @ApiOperation(value = "数据中心获取重点工程详细信息", notes = "数据中心获取重点工程详细信息") @RequiresPermissions("forest:keyProjects:query") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") String id) { return AjaxResult.success(centerdataTKeyProjectsService.selectCenterdataTKeyProjectsById(id)); } /** * 新增重点工程 */ @ApiOperation(value = "数据中心新增重点工程", notes = "数据中心新增重点工程") @RequiresPermissions("forest:keyProjects:add") @Log(title = "重点工程", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody CenterdataTKeyProjects centerdataTKeyProjects) { if (centerdataTKeyProjects.getEndTime()!=null&¢erdataTKeyProjects.getStartTime()!=null){ if (centerdataTKeyProjects.getEndTime().compareTo(centerdataTKeyProjects.getStartTime())<0){ return AjaxResult.error("计划竣工时间不能小于开复工时间"); } } return toAjax(centerdataTKeyProjectsService.insertCenterdataTKeyProjects(centerdataTKeyProjects)); } /** * 修改重点工程 */ @ApiOperation(value = "数据中心修改重点工程", notes = "数据中心修改重点工程") @RequiresPermissions("forest:keyProjects:edit") @Log(title = "重点工程", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@Validated @RequestBody CenterdataTKeyProjects centerdataTKeyProjects) { if (centerdataTKeyProjects.getEndTime()!=null&¢erdataTKeyProjects.getStartTime()!=null){ if (centerdataTKeyProjects.getEndTime().compareTo(centerdataTKeyProjects.getStartTime())<0){ return AjaxResult.error("计划竣工时间不能小于开复工时间"); } } return toAjax(centerdataTKeyProjectsService.updateCenterdataTKeyProjects(centerdataTKeyProjects)); } /** * 删除重点工程 */ @ApiImplicitParams(value = { @ApiImplicitParam(name = "ids", value = "主键id", dataType = "String[]", required = true) }) @ApiOperation(value = "数据中心删除重点工程", notes = "数据中心删除重点工程") @RequiresPermissions("forest:keyProjects:remove") @Log(title = "重点工程", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable String[] ids) { return toAjax(centerdataTKeyProjectsService.deleteCenterdataTKeyProjectsByIds(ids)); } /** * 接受报文 */ @ApiOperation(value = "接受报文", notes = "接受报文") @Log(title = "接受报文", businessType = BusinessType.INSERT) @PostMapping("/receivedMessage") public AjaxResult receivedMessage(@RequestBody Map map) { List list = JSON.parseArray(JSON.toJSONString(map.get("list"))); List centerdataTKeyProjectsList=new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); list.forEach(item->{ CenterdataTKeyProjects centerdataTKeyProjects= new CenterdataTKeyProjects(); CenterdataTKeyProjectsBo centerdataTKeyProjectsBo= JSON.parseObject(JSON.toJSONString(item), CenterdataTKeyProjectsBo.class); BeanUtils.copyProperties(centerdataTKeyProjectsBo,centerdataTKeyProjects); try { centerdataTKeyProjects.setEndTime(sdf.parse(centerdataTKeyProjectsBo.getEndTime())); centerdataTKeyProjects.setRealityCompletedTime(sdf.parse(centerdataTKeyProjectsBo.getRealityCompletedTime())); centerdataTKeyProjects.setStartTime(sdf.parse(centerdataTKeyProjectsBo.getStartTime())); centerdataTKeyProjects.setContinuationProjectStartTime(sdf.parse(centerdataTKeyProjectsBo.getContinuationProjectStartTime())); } catch (ParseException e) { e.printStackTrace(); } centerdataTKeyProjectsList.add(centerdataTKeyProjects); }); for (CenterdataTKeyProjects projects : centerdataTKeyProjectsList ){ if (StringUtils.isEmpty(projects.getProjectId())||StringUtils.isEmpty(projects.getProjectName())||StringUtils.isEmpty(projects.getLongitude())|| StringUtils.isEmpty(projects.getLatitude())||StringUtils.isEmpty(projects.getTerritoriality())||StringUtils.isEmpty(projects.getPrincipal())|| StringUtils.isEmpty(projects.getPhone())||StringUtils.isEmpty(projects.getConstructionSite())||StringUtils.isEmpty(projects.getNature())|| StringUtils.isEmpty(projects.getIntroduction())){ return AjaxResult.error(5002, "缺少必要参数"); } if (projects.getEndTime()!=null&&projects.getStartTime()!=null){ if (projects.getEndTime().compareTo(projects.getStartTime())<0){ return AjaxResult.error(5003,"计划竣工时间不能小于开复工时间"); } } } int result = 0; try {Object userInfoObject = map.get("userInfo"); if (userInfoObject instanceof Map) { Map userInfoMap = (Map) userInfoObject; SysUser sysUser = new SysUser(); // 创建SysUser实体类对象 // 将userInfoMap中的属性值赋值给sysUser对象的对应属性 sysUser.setDeptId(Long.valueOf(userInfoMap.get("deptId").toString())); sysUser.setDeptNames(userInfoMap.get("deptNames").toString()); sysUser.setUserId(Long.valueOf(userInfoMap.get("userId").toString())); sysUser.setNickName(userInfoMap.get("nickName").toString()); result = centerdataTKeyProjectsService.receivedMessage(centerdataTKeyProjectsList,sysUser); } }catch (Exception e){ logger.error(e.getMessage()); return AjaxResult.error("数据格式错误"); } return toAjax(result); } /* * 推送报文 * * @author 韩福成 * @date 2024/1/18 14:58 */ @ApiOperation(value = "推送报文", notes = "推送报文") @GetMapping("/receivedMessage/{ids}") public R pushMessage(@PathVariable String[] ids) { return centerdataTKeyProjectsService.pushMessage(ids); } }