| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package cn.com.goldenwater.dcproj.controller.rsfco;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.constValue.CommonLabel;
- import cn.com.goldenwater.dcproj.dto.BisInspRgstrDto;
- import cn.com.goldenwater.dcproj.model.BisInspRsfcoRgstr;
- import cn.com.goldenwater.dcproj.param.BisInspRsfcoRgstrParam;
- import cn.com.goldenwater.dcproj.param.FileParam;
- import cn.com.goldenwater.dcproj.param.TypeParam;
- import cn.com.goldenwater.dcproj.service.BisInspRsfcoRgstrService;
- import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
- import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
- import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel;
- import cn.com.goldenwater.dcproj.utils.impexcel.format.RsfcoFieldFromatImp;
- import cn.com.goldenwater.id.util.UuidUtil;
- import com.github.pagehelper.PageInfo;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import static cn.com.goldenwater.dcproj.utils.impexcel.ImpUtil.getDateFormatPath;
- /**
- * @author lune
- * @date 2020-4-21
- */
- @Api(value = "BIS 水库防洪调度督查登记表管理", tags = "BIS 水库防洪调度督查登记表管理")
- @RestController
- @RequestMapping("/bis/insp/rsfco/rgstr")
- public class BisInspRsfcoRgstrController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private BisInspRsfcoRgstrService bisInspRsfcoRgstrService;
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- @Autowired
- private RedisTemplate redisTemplate;
- @Value("${export.templatePath}")
- private String templatePath;
- @Value("${impExcel.basePath}")
- private String impExcelPath;
- @ApiOperation(value = "添加/修改水库防洪调度督查登记表")
- @RequestMapping(value = "", method = RequestMethod.POST)
- public BaseResponse<BisInspRsfcoRgstr> insert(@ApiParam(name = "bisInspRsfcoRgstr", value = "BisInspRsfcoRgstr", required = true) @RequestBody BisInspRsfcoRgstr bisInspRsfcoRgstr) {
- if (StringUtils.isNotBlank(bisInspRsfcoRgstr.getRgstrId()) && StringUtils.isBlank(bisInspRsfcoRgstr.getId())) {
- bisInspRsfcoRgstr.setId(bisInspRsfcoRgstr.getRgstrId());
- }
- if (StringUtils.isBlank(bisInspRsfcoRgstr.getId())) {
- bisInspRsfcoRgstr.setId(UuidUtil.uuid());
- bisInspRsfcoRgstrService.insert(bisInspRsfcoRgstr);
- } else {
- bisInspRsfcoRgstr.setUptm(new Date());
- bisInspRsfcoRgstrService.update(bisInspRsfcoRgstr);
- }
- return buildSuccessResponse(bisInspRsfcoRgstr);
- }
- @ApiOperation(value = "根据ID删除水库防洪调度督查登记表")
- @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
- public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- int ret = bisInspRsfcoRgstrService.delete(id);
- return buildSuccessResponse();
- }
- @ApiOperation(value = "根据ID获取水库防洪调度督查登记表(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<BisInspRsfcoRgstr> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- BisInspRsfcoRgstr bisInspRsfcoRgstr = bisInspRsfcoRgstrService.get(id);
- return buildSuccessResponse(bisInspRsfcoRgstr);
- }
- @ApiOperation(value = "获取水库防洪调度督查登记表(列表所有)")
- @RequestMapping(value = "/list", method = RequestMethod.POST)
- public BaseResponse<List<BisInspRsfcoRgstr>> list(@ApiParam(name = "bisInspRsfcoRgstrParam", value = "bisInspRsfcoRgstrParam", required = true) @RequestBody BisInspRsfcoRgstrParam bisInspRsfcoRgstrParam) {
- List<BisInspRsfcoRgstr> bisInspRsfcoRgstrList = bisInspRsfcoRgstrService.findList(bisInspRsfcoRgstrParam);
- return buildSuccessResponse(bisInspRsfcoRgstrList);
- }
- @ApiOperation(value = "获取水库防洪调度督查登记表(列表--分页)")
- @RequestMapping(value = "/page", method = RequestMethod.POST)
- public BaseResponse<PageInfo<BisInspRsfcoRgstr>> page(@ApiParam(name = "bisInspRsfcoRgstrParam", value = "bisInspRsfcoRgstrParam", required = true) @RequestBody BisInspRsfcoRgstrParam bisInspRsfcoRgstrParam) {
- PageInfo<BisInspRsfcoRgstr> bisInspRsfcoRgstrList = bisInspRsfcoRgstrService.findPageInfo(bisInspRsfcoRgstrParam);
- return buildSuccessResponse(bisInspRsfcoRgstrList);
- }
- @ApiOperation(value = "获取督查对象")
- @RequestMapping(value = "/findRsfcoPage", method = RequestMethod.POST)
- public BaseResponse<PageInfo<BisInspRgstrDto>> findSvwtWuntPage(@RequestBody TypeParam param, HttpServletResponse response) {
- param.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
- if (StringUtils.isBlank(param.getTabType())) {
- param.setTabType(CommonLabel.TAB_TYPE);
- }
- String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
- param.setNowTime(nowTime);
- PageInfo<BisInspRgstrDto> pageInfo = bisInspRsfcoRgstrService.findRsfcoPage(param, response);
- return buildSuccessResponse(pageInfo);
- }
- @ApiOperation(value = "下载模板")
- @RequestMapping(value = "/downTemplate", method = {RequestMethod.GET, RequestMethod.POST})
- public BaseResponse downTemplate(HttpServletResponse response, TypeParam param) {
- try {
- bisInspRsfcoRgstrService.downloadTemplate(response, param);
- } catch (Exception e) {
- return buildFailResponse(e);
- }
- return buildSuccessResponse();
- }
- @ApiOperation(value = "上传模板")
- @RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST)
- public BaseResponse uploadTemplate(MultipartFile file) {
- String filaPath = "";
- try {
- filaPath = ExpAndImpUtil.upload(file, getDateFormatPath(impExcelPath));
- } catch (Exception e) {
- return buildFailResponse(e);
- }
- return buildSuccessResponse(filaPath);
- }
- @ApiOperation(value = "解析文件上传数据")
- @RequestMapping(value = "/parseUpload", method = RequestMethod.POST)
- public BaseResponse<Map<String, Object>> parseUpload(FileParam param) {
- Map<String, Object> map = new LinkedHashMap<>();
- try {
- List<LinkedHashMap<String, Object>> list = ExpAndImpUtil.parseData(param.getPath(), param.getStartRow(), BisInspRgstrDto.class);
- if (list.size() > 0) {
- String uuid = UuidUtil.uuid();
- redisTemplate.opsForList().rightPushAll(uuid, list);
- map.put("dataId", uuid);
- }
- map.put("list", list);
- } catch (IOException e) {
- buildFailResponse(e.getMessage());
- }
- return buildSuccessResponse(map);
- }
- @ApiOperation(value = "文件数据入库")
- @RequestMapping(value = "/insertIntoData", method = RequestMethod.POST)
- public BaseResponse insertIntoData(FileParam param) {
- if (StringUtils.isBlank(param.getDataId())) {
- return buildFailResponse();
- }
- List<LinkedHashMap<String, Object>> list = redisTemplate.opsForList().range(param.getDataId(), 0, -1);
- redisTemplate.delete(param.getDataId());
- try {
- List<LinkedHashMap<String, Object>> showDataList = ImportExcel.getShowData(list, RsfcoFieldFromatImp.class);
- bisInspRsfcoRgstrService.insertIntoData(showDataList, param);
- } catch (Exception e) {
- return buildFailResponse();
- }
- return buildSuccessResponse();
- }
- }
|