package com.railway.business.catenary.controller; import com.railway.business.catenary.domain.BusJcbJcxc; import com.railway.business.catenary.domain.vo.JcebQueryVo; import com.railway.business.catenary.service.IBusJcbJcxcService; import com.railway.common.core.controller.BaseController; import com.railway.common.core.domain.AjaxResult; import com.railway.common.core.page.TableDataInfo; import com.railway.common.utils.LocalDateUtil; import com.railway.common.utils.StringUtils; import com.railway.common.utils.poi.WordUtils; import com.railway.system.service.ISysFileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author zhangcaifeng */ @Slf4j @Api(value = "rest/catenary/bus/jcb/jcxc", tags = "检查表 - 交叉线岔") @RestController @Validated @RequestMapping(value = "business/catenary/bus/jcb/jcxc") public class BusJcbJcxcController extends BaseController { @Value("${railway.template}") public String templatePath; private final IBusJcbJcxcService busJcbJcxcService; private final ISysFileService sysFileService; public BusJcbJcxcController(IBusJcbJcxcService busJcbJcxcService, ISysFileService sysFileService) { this.busJcbJcxcService = busJcbJcxcService; this.sysFileService = sysFileService; } @ApiOperation(value = "新增") @PostMapping("/add") public AjaxResult add(@Validated @RequestBody BusJcbJcxc busJcbJcxc) { return toAjax(busJcbJcxcService.create(busJcbJcxc)); } @ApiOperation(value = "删除") @DeleteMapping("/{ids}") public AjaxResult delete(@PathVariable(value = "ids") String[] ids) { return toAjax(busJcbJcxcService.delete(ids)); } @ApiOperation(value = "更新") @PutMapping("/update") public AjaxResult update(@RequestBody @Valid BusJcbJcxc busJcbJcxc) { log.info("交叉线岔检查表更新参数 - {}", busJcbJcxc.toString()); busJcbJcxcService.update(busJcbJcxc); return AjaxResult.success(); } @ApiOperation(value = "单个") @GetMapping(value = {"/", "/{id}"}) public AjaxResult getInfo(String id) { BusJcbJcxc info = busJcbJcxcService.getInfo(id); AjaxResult ajax = AjaxResult.success(); ajax.put("info", info); return ajax; } @ApiOperation(value = "列表") @GetMapping(value = "list") public TableDataInfo getList(BusJcbJcxc busJcbJcxc) { startPage(); List list = busJcbJcxcService.getList(busJcbJcxc); return getDataTable(list); } @ApiOperation(value = "获取上次检测值") @GetMapping(value = "/getLastOne") public AjaxResult getLastOne(BusJcbJcxc busJcbJcxc) { BusJcbJcxc info = busJcbJcxcService.getLastRecord(busJcbJcxc); AjaxResult ajax = AjaxResult.success(); ajax.put("info", info); return ajax; } @ApiOperation(value = "提交") @PutMapping("/submit") public AjaxResult submit(@RequestBody BusJcbJcxc busJcbJcxc) { return toAjax(busJcbJcxcService.submit(busJcbJcxc)); } @ApiOperation(value = "退回") @PutMapping("/reject") public AjaxResult reject(@RequestBody BusJcbJcxc busJcbJcxc) { return toAjax(busJcbJcxcService.reject(busJcbJcxc)); } @ApiOperation(value = "确认") @PutMapping("/confirm") public AjaxResult confirm(@RequestBody BusJcbJcxc busJcbJcxc) { return toAjax(busJcbJcxcService.confirm(busJcbJcxc)); } @ApiOperation(value = "中心领导确认") @PutMapping("/centerLeaderConfirm") public AjaxResult centerLeaderConfirm(@RequestBody BusJcbJcxc busJcbJcxc) { return toAjax(busJcbJcxcService.centerLeaderConfirm(busJcbJcxc)); } @ApiOperation(value = "导出") @GetMapping("/export/{id}") public AjaxResult export(@PathVariable(value = "id") String id) { BusJcbJcxc info = busJcbJcxcService.getInfo(id); WordUtils wordUtil = new WordUtils(); //填充变量 Map params = new HashMap<>(32); params.put("${xch}", info.getXch()); params.put("${qj}", info.getStationName()); params.put("${wendu}", info.getTemperature() == null ? "" : info.getTemperature()); params.put("${jcrq}", LocalDateUtil.convertLocalDateToShow(info.getCheckDate())); params.put("${gz1lcz}", StringUtils.bigDecimalToString(info.getGz1lcz())); params.put("${gz2lcz}", StringUtils.bigDecimalToString(info.getGz2lcz())); params.put("${zglcz}", StringUtils.bigDecimalToString(info.getZglcz())); params.put("${qglcz}", StringUtils.bigDecimalToString(info.getQglcz())); params.put("${ngj}", StringUtils.bigDecimalToString(info.getNgj())); params.put("${plz}", StringUtils.bigDecimalToString(info.getPlz())); params.put("${xcxzgazlg}", StringUtils.yesOrNo(info.getXcxzgazlg())); params.put("${hdjx}", StringUtils.yesOrNo(info.getHdjx())); params.put("${fhzzsq}", StringUtils.yesOrNo(info.getFhzzsq())); params.put("${dqssxx}", StringUtils.yesOrNo(info.getDqssxx())); params.put("${lswst}", StringUtils.yesOrNo(info.getLswst())); params.put("${xzgldydx}", StringUtils.yesOrNo(info.getXzgldydx())); params.put("${dxztlh}", StringUtils.yesOrNo(info.getDxztlh())); params.put("${czjj}", StringUtils.bigDecimalToString(info.getCzjj())); params.put("${lgzzgc}", StringUtils.bigDecimalToString(info.getLgzzgc())); params.put("${gzyfzgc}", StringUtils.bigDecimalToString(info.getGzyfzgc())); params.put("${wxj}", StringUtils.yesOrNo(info.getWxj())); params.put("${hddxxjzt}", StringUtils.yesOrNo(info.getHddxxjzt())); params.put("${jcdxzt}", StringUtils.yesOrNo(info.getJcdxzt())); params.put("${dljxzt}", StringUtils.yesOrNo(info.getDljxzt())); params.put("${jcr}", info.getCheckUser()); params.put("${sbzt}", StringUtils.YES_VALUE.equals(info.getSbzt()) ? "合格" : "不合格"); params.put("${qrr}", info.getConfirmUser() == null ? "" : info.getConfirmUser()); params.put("${czwt}", info.getCzwt() == null ? "" : info.getCzwt()); //生成word文件的文件名 String fileName = "交叉线岔高速手册.docx"; String template = templatePath + "/word/交叉线岔高速手册.docx"; String localFilePath = wordUtil.getWord(params, template, fileName); return sysFileService.uploadFile(localFilePath); } @ApiOperation(value = "导出excel") @GetMapping(value = "exportExcel") public AjaxResult exportExcel(JcebQueryVo query) { String localFilePath = busJcbJcxcService.exportExcel(query); return sysFileService.uploadFile(localFilePath); } }