ReportRegisterController.java 3.73 KB
package com.bsth.controller.realcontrol;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.data.report_register.ReportRegisterService;
import com.bsth.data.report_register.entity.ReportRegister;
import com.bsth.util.HttpClientUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 报备登记
 * Created by yrf on 2019/12/04.
 */
@RestController
@RequestMapping("reportRegister")
public class ReportRegisterController extends BaseController<ReportRegister, Long>{

    Logger log = LoggerFactory.getLogger(this.getClass());

    final static String url = "http://114.80.178.13/complaint/TsReport/input.do";
//    final static String url = "http://192.168.168.228:8080/complaint/TsReport/input.do";

    @Autowired
    ReportRegisterService reportRegisterService;

    @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request) {
        //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    }


    @RequestMapping(value = "/findList", method = RequestMethod.GET)
    public Map<String, Object> findList(@RequestParam Map<String, String> map) {
        return reportRegisterService.findList(map);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ReportRegister findById(@PathVariable("id") Long id) {
        ReportRegister reportRegister = reportRegisterService.findById(id);
        return reportRegister;
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Map<String, Object> deleteInfo(ReportRegister t) {
        Map<String, Object> map = new HashMap<>();
        try{
//            map = baseService.delete(id);
            reportRegisterService.deleteInfo(t);
            String data = "{ID:'"+t.getID()+"', STATUS:'2'}";
            StringBuilder sb = HttpClientUtils.post(url,data);
            JSONObject obj = JSON.parseObject(sb.toString());
            map.put("status2", obj);
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return map;
    }


    @RequestMapping(method = RequestMethod.POST)
    public Map<String, Object> save(ReportRegister t) {
        Map<String, Object> map = new HashMap<>();
        try{
            reportRegisterService.save(t);
            map.put("status", ResponseCode.SUCCESS);
            map.put("t", t);
            StringBuilder sb = HttpClientUtils.post(url,t.toString());
            JSONObject obj = JSON.parseObject(sb.toString());
            map.put("status2", obj);
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return map;
    }
}