package com.ruoyi.web.controller.Ytj;

import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import static com.ruoyi.common.core.domain.AjaxResult.warn;
import static com.ruoyi.common.utils.ImgUtils.Base64ToImage;

/**
 * 待审核Controller
 *
 * @author xu
 * @date 2019-08-22
 */
@Controller
@RequestMapping("/Ytj/Printer")
public class PrinterController extends BaseController {
    private String prefix = "Ytj/Printer";


    @Autowired
    private IGtgsywService gtgsywService;
    @Autowired
    private GtgsywPrintListService gtgsywPrintListService;
    @Autowired
    private IGtgsYwUserService gtgsYwUserService;
    @Autowired
    private IGtgsBgService gtgsBgService;
    @Autowired
    private ISysConfigService sysConfigService;
    /**
     * 打开刷身份证页面
     *
     * @return
     */
    @GetMapping()
    public String printe() {
        return "Ytj/Index";
    }

    /**
     * @return 刷身份证页面
     */
    @GetMapping("/shua")
    public String printer(Model model) {
        model.addAttribute("city", Global.getCityName());
        return prefix + "/shuaPrint";

    }



    /**
     * @return 无信息页面
     */
    @GetMapping("/PrintHtml")
    public String PrintHtml(Model model) {
        model.addAttribute("city", Global.getCityName());
        return prefix + "/PrintHtml";
    }

    /**
     * @return 打印副本页面
     */
    @GetMapping("/fuben")
    public String printfu(@RequestParam("XinYongCode")String xycode, HttpServletResponse response) {
        response.setContentType("text/html;charset=utf-8");
        return "Ytj/PrintHtml/" + xycode + "PrintF";
        //    return prefix+"/PrintForm_FNew";
    }

    /**
     * @return 打印正本页面
     */
    @GetMapping(value = "zhengben")
    public String printzheng(@RequestParam("XinYongCode")String xycode, HttpServletResponse response) {

        response.setContentType("text/html;charset=utf-8");
        return "Ytj/PrintHtml/" + xycode + "PrintZ";
        //  return prefix+"/PrintFormZheng";
    }

    /**
     * 刷身份证
     *
     * @param jingyingcard
     * @return
     */
    @GetMapping("/ispass")
    @ResponseBody
    public AjaxResult isPass(@RequestParam("jyCord") String jingyingcard) {

        List<Gtgsyw> data = gtgsywService.selectByCard(jingyingcard);
        List<GtgsywPrintList> data1 = gtgsywPrintListService.selectByCard(jingyingcard);
        int i = data.size()+data1.size();
        System.err.println("i:"+data1+"data:"+data.size());
        return AjaxResult.success("操作成功", i);
    }

    /**
     * 读取到身份证信息
     *
     * @param jingyingcard
     * @param model
     * @return
     */
    @GetMapping("/successlist")
    public String successlist(@RequestParam("jyCord") String jingyingcard, @RequestParam("BSID") String bsid, Model model) {
        Gtgsyw result = gtgsywService.selectByBsid(bsid);
        model.addAttribute("jingyingren", result.getJingyingren());
        model.addAttribute("jyCard", jingyingcard);
        model.addAttribute("bsid", result.getBsid());
        model.addAttribute("flg", result.getFlg());
        model.addAttribute("isPrint", result.getIsprint());
        model.addAttribute("city", Global.getCityName());
        model.addAttribute("scity", Global.getSuperCity());
        return prefix + "/ChengNuoShu";
    }

    /**
     * 读取到身份证信息
     *
     * @param model
     * @return
     */
    @GetMapping("/success")
    public String success(@RequestParam("bsid") String id, Model model) {
        GtgsywPrintList result = gtgsywPrintListService.selectByPrimaryKey(id);

        model.addAttribute("jingyingren", result.getJingyingren());
        model.addAttribute("jyCard", result.getJingyingcard());
        model.addAttribute("bsid", result.getBsid());
        model.addAttribute("isPrint", result.getIsprint());
        model.addAttribute("city", Global.getCityName());
        model.addAttribute("scity", Global.getSuperCity());
        return prefix + "/ChengNuoShu";
    }

    /**
     * 查询到多条或1条没通过时
     *
     * @param jingyingcard
     * @param model
     * @return
     */
    @GetMapping("/defeatlist")
    public String defeatlist(@RequestParam("jyCord") String jingyingcard, Model model) {
        List<Gtgsyw> result = gtgsywService.selectByCard(jingyingcard);
        List<GtgsywPrintList> data1 = gtgsywPrintListService.selectByCard(jingyingcard);
//        for (Gtgsyw res : result) {
//            model.addAttribute("id", res.getId());
//            model.addAttribute("bsid", res.getBsid());
//            model.addAttribute("card", res.getJingyingcard());
//        }
        model.addAttribute("gtgsywList", result);
        model.addAttribute("GtgsywPrintList", data1);
        model.addAttribute("city", Global.getCityName());
        return prefix + "/IndexPrint";
    }

    /**
     * 检测人脸,
     *
     * @param bsid
     * @param jingyingcard
     * @param model
     * @return
     */
    @GetMapping("/CheckRen")
    public String checkRen(@RequestParam("BSID") String bsid, @RequestParam("jyCord") String jingyingcard, Model model) {
       /* Gtgsyw result = gtgsywService.selectByCB(jingyingcard, bsid);
        model.addAttribute("gtgsyw", result);*/
        model.addAttribute("city", Global.getCityName());
        model.addAttribute("rzdbsocre", Global.getConfig("ruoyi.rzdbsocre"));
        return prefix + "/CheckRen";
    }

    /**
     * 通用下载请求
     *
     * @param fileName 文件名称
     * @param delete   是否删除
     */
    @GetMapping("zhengben/download")
    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
        try {
            if (!FileUtils.isValidFilename(fileName)) {
                throw new Exception(StringUtils.format("文件名称({})非法，不允许下载。 ", fileName));
            }
            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
            String filePath = Global.getDownloadPath() + fileName;

            response.setCharacterEncoding("utf-8");
            response.setContentType("multipart/form-data");
            response.setHeader("Content-Disposition",
                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
            FileUtils.writeBytes(filePath, response.getOutputStream());
            if (delete) {
                FileUtils.deleteFile(filePath);
            }
        } catch (Exception e) {
            System.out.println("下载文件失败");
        }
    }

    /**
     * 承诺书页面js调取
     *
     * @param bsid
     * @param model
     * @return
     */

    @GetMapping("/chengNuo")
    public AjaxResult chengNuo(@RequestParam("BSID") String bsid, Model model) {
        Gtgsyw result = gtgsywService.selectByBsid(bsid);
        return AjaxResult.success("操作成功", result);
    }


    @GetMapping("/CreateHtmls")
    @ResponseBody
    public AjaxResult CreateHtmls(@RequestParam("BSID") String bsid, @RequestParam("jyCord") String jingyingcard,HttpServletResponse response) throws Exception {
        Gtgsyw result = gtgsywService.selectByCB(jingyingcard, bsid);
        Integer i;
        try {
            if (result == null) {
               i= CreateHtml1(bsid, jingyingcard, response);
            }  else {
               i= CreateHtml(result, response);
            }
        }catch (Exception e){
            return AjaxResult.warn("生成打印页面失败！");
        }
        System.out.println("222");
        return toAjax(i);
    }

    /**
     * 承诺书页面js调取
     *
     * @param bsid
     * @param model
     * @return
     */
    @GetMapping("/PrintIndex")
    public String PrintIndex(@RequestParam("BSID") String bsid, @RequestParam("jyCord") String jingyingcard, Model model, HttpServletResponse response) throws Exception {
        Gtgsyw result = gtgsywService.selectByCB(jingyingcard,bsid);
        if (result == null) {
            GtgsywPrintList result1 = gtgsywPrintListService.selectByCB(jingyingcard, bsid);
     /*       result.setXinyongcode(result1.getXinyongcode());
            result.setJingyingren(result1.getJingyingren());
            result.setZwzh(result1.getZwzh());
            result.setSczttype(result1.getSczttype());
            result.setJingyingchangsuo(result1.getJingyingchangsuo());
            result.setShenqingdate(DateUtils.parseDate(result1.getShenqingdate()));
            result.setJingyingfanwei(result1.getJingyingfanwei());
            result.setErweimabase64(result1.getErweimabase64());*/

            model.addAttribute("data", result1);
            CreateHtml1(bsid, jingyingcard, response);
        } else {
            model.addAttribute("data", result);
            CreateHtml(result, response);
        }
        response.setCharacterEncoding("UTF-8");
        model.addAttribute("city", Global.getCityName());

        return prefix + "/PrintLr";
    }


    public Integer  CreateHtml1(String bisd, String card, HttpServletResponse response) throws Exception {
        //查询个体数据
        GtgsywPrintList gt = gtgsywPrintListService.selectByCB(card, bisd);
        response.setCharacterEncoding("GBK");
        //①创建配置对象
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);//注意:这里需要传递一个版本
        String path = null;
        String path1 = null;
        if (System.getProperty("user.dir").indexOf("bin") != -1) {
            String[] t = System.getProperty("user.dir").split("bin");
            path = t[0] + "/webapps/ROOT/WEB-INF/classes/templates/";
            path1 = "";
        } else {
            path1 = "";
            path = System.getProperty("user.dir") + "/ruoyi-admin/src/main/resources/templates/";
        }
        System.err.println(path);
        File f = new File(path);
        File f1 = new File(path);
        //②读取模板文件夹
        cfg.setDirectoryForTemplateLoading(f);//设置要加载的模板文件的路径
        cfg.setDirectoryForTemplateLoading(f1);//设置要加载的模板文件的路径
        //③设置模板的编码格式
        cfg.setDefaultEncoding("UTF-8");
        //④获取模板对象
        Template template = cfg.getTemplate("gtPrintZ.ftl");//hello.ftl是模板名称
        Template template1 = cfg.getTemplate("gtPrintF.ftl");//hello.ftl是模板名称
        //⑤创建数据模型(这里使用map类型)  --[数据模型可以是List、Map对象 注意:Map类型的key必须是String类型]
        HashMap<String, Object> map = new HashMap<>();
        map.put("xinyongcode", gt.getXinyongcode());
        map.put("jyrname", gt.getJingyingren());
        map.put("jycs", gt.getJingyingchangsuo());
        String stt = null;
        if (!gt.getZwzh().equals("***")) {
            stt = gt.getZwzh();
        } else {
            stt = ("***");
        }
        String yue = null;
        String Pdate = dateToStr(gt.getShenhedate());
        if (Integer.valueOf(Pdate.substring(5, 7)) < 10) {
            yue = Pdate.substring(6, 7);
        } else {
            yue = Pdate.substring(5, 7);
        }
        String ri = null;
        if (Integer.valueOf(Pdate.substring(8, 10)) < 10) {
            ri = Pdate.substring(9, 10);
        } else {
            ri = Pdate.substring(8, 10);
        }
        map.put("ri", ri);
        map.put("gtname", stt);
        map.put("zcxs", gt.getZuchengxingshi());
        map.put("lx", gt.getSczttype());
        map.put("zcdate", dateToStr(gt.getZhucetime()));
        map.put("jyfw", gt.getJingyingfanwei());
        String ewm = gt.getErweimabase64();
        map.put("ewm", ewm);
        map.put("nian", Pdate.substring(0, 4));
        map.put("yue", yue);
        //⑥将模板和数据模型合并 --> 输出模板,生成文件
        PrintWriter pw = new PrintWriter(new File(f, path1 + "Ytj/PrintHtml/" + gt.getXinyongcode() + "PrintZ.html"));
        PrintWriter pw1 = new PrintWriter(new File(f1, path1 + "Ytj/PrintHtml/" + gt.getXinyongcode() + "PrintF.html"));
        template.process(map, pw);//合并  map:数据模型  pw:输出流对象
        template1.process(map, pw1);//合并  map:数据模型  pw:输出流对象
        pw.close();//关闭流
        pw1.close();//关闭流
        System.out.println("123");
        return 1;
    }


    public Integer CreateHtml( Gtgsyw gt, HttpServletResponse response) throws Exception {
        //查询个体数据
        response.setCharacterEncoding("GBK");
        //①创建配置对象
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);//注意:这里需要传递一个版本
        String path = null;
        String path1 = null;
        if (System.getProperty("user.dir").indexOf("bin") != -1) {
            String[] t = System.getProperty("user.dir").split("bin");
            path = t[0] + "/webapps/ROOT/WEB-INF/classes/templates/";
            path1 = "";
        } else {
            path1 = "";
            path = System.getProperty("user.dir")+"/ruoyi-admin/src/main/resources/templates/";
        }
        System.err.println(path);
        File f = new File(path);
        File f1 = new File(path);
        //②读取模板文件夹
        cfg.setDirectoryForTemplateLoading(f);//设置要加载的模板文件的路径
        cfg.setDirectoryForTemplateLoading(f1);//设置要加载的模板文件的路径
        //③设置模板的编码格式
        cfg.setDefaultEncoding("UTF-8");
        //④获取模板对象
        Template template = cfg.getTemplate("gtPrintZ.ftl");//hello.ftl是模板名称
        Template template1 = cfg.getTemplate("gtPrintF.ftl");//hello.ftl是模板名称
        //⑤创建数据模型(这里使用map类型)  --[数据模型可以是List、Map对象 注意:Map类型的key必须是String类型]
        HashMap<String, Object> map = new HashMap<>();
        map.put("xinyongcode", gt.getXinyongcode());
        map.put("jyrname", gt.getJingyingren());
        map.put("jycs", gt.getJingyingchangsuo());
        String stt = null;
        if (!gt.getZwzh().equals("***")) {
            stt = gt.getNsxzq() + gt.getZwzh() + gt.getMingchenghangye() + gt.getZuzhixingshi();
        } else {
            stt = ("***");
        }
        String yue = null;

        String Pdate = dateToStr(gt.getShenhedate());
        if (Integer.valueOf(Pdate.substring(5, 7)) < 10) {
            yue = Pdate.substring(6, 7);
        } else {
            yue = Pdate.substring(5, 7);
        }
        String ri = null;
        if (Integer.valueOf(Pdate.substring(8, 10)) < 10) {
            ri = Pdate.substring(9, 10);
        } else {
            ri = Pdate.substring(8, 10);
        }
        map.put("ri", ri);
        map.put("gtname", stt);
        map.put("zcxs", gt.getZuchengxingshi());
        map.put("lx", gt.getSczttype());
        map.put("zcdate", dateToStr(gt.getZhucetime()));
        map.put("jyfw", gt.getJingyingfanwei());
        String ewm = gt.getErweimabase64();
        map.put("ewm", ewm);
        map.put("nian", Pdate.substring(0, 4));
        map.put("yue", yue);

        //⑥将模板和数据模型合并 --> 输出模板,生成文件
        PrintWriter pw = new PrintWriter(new File(f, path1 + "Ytj/PrintHtml/" + gt.getXinyongcode() + "PrintZ.html"));
        PrintWriter pw1 = new PrintWriter(new File(f1, path1 + "Ytj/PrintHtml/" + gt.getXinyongcode() + "PrintF.html"));
        template.process(map, pw);//合并  map:数据模型  pw:输出流对象
        template1.process(map, pw1);//合并  map:数据模型  pw:输出流对象
        pw.close();//关闭流
        pw1.close();//关闭流
        System.out.println("111");
        return 1;
    }


    /**
     * 将短时间格式时间转换为字符串 yyyy-MM-dd
     *
     * @param dateDate
     * @return
     */
    public static String dateToStr(Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
        String dateString = formatter.format(dateDate);
        return dateString;
    }


    /**
     * 打印页js调取
     *
     * @param bsid
     * @param model
     * @return
     */
    @GetMapping("/Printing")
    @ResponseBody
    public AjaxResult Print(@RequestParam("BSID") String bsid, @RequestParam("jyCord") String jingyingcard, @RequestParam("bs") Integer bs, Model model) {
        Gtgsyw data = gtgsywService.selectByCB(jingyingcard,bsid);
        Long print = 1L;
        // 当前登录用户

        GtgsYwUser gtgsYwUser=gtgsYwUserService.selectGtgsYwUserByRemark(Global.getConfig("ruoyi.gtgsuser"));
        String userDetail="";
        if(gtgsYwUser!=null) {
            userDetail = "&loginName=" + gtgsYwUser.getUsername() + "&password=" + gtgsYwUser.getPassword() + "&authId=" +
                    gtgsYwUser.getAuthid() + "&loginDeptId=" + gtgsYwUser.getDetpid() + "&loginUserId=" + gtgsYwUser.getUserid();
        }
        if (data != null) {
            if (bs == 1 && data.getIsprint() == 0) {
                data.setIsprint(print);
                Date date = new Date();
                data.setPrinttime(date);
                System.err.println("打印时间===" + data.getPrinttime());
                if (gtgsywService.updateGtgsyw(data)==1){
                    SysConfig sysConfig=new SysConfig();
                    sysConfig.setConfigKey("zbzz");
                    List<SysConfig> sysConfigs=sysConfigService.selectConfigList(sysConfig);
                    sysConfig= sysConfigs.get(0);
                    sysConfig.setConfigValue(String.valueOf(Integer.parseInt(sysConfig.getConfigValue())-1));
                    sysConfigService.updateConfig(sysConfig);
                }
                if(data.getIsprintF().equals(print)){
//                    HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/setPrint","xinyongcode="+data.getXinyongcode()+userDetail);
                }
                return AjaxResult.success("操作成功");
            } else if (bs == 0 && data.getIsprintF() == 0) {
                data.setIsprintF(print);
                Date date = new Date();
                data.setPrinttimeF(date);
                System.err.println("打印时间===" + data.getPrinttime());

                if (gtgsywService.updateGtgsyw(data)==1){
                    SysConfig sysConfig=new SysConfig();
                    sysConfig.setConfigKey("fbzz");
                    List<SysConfig> sysConfigs=sysConfigService.selectConfigList(sysConfig);
                    sysConfig= sysConfigs.get(0);
                    sysConfig.setConfigValue(String.valueOf(Integer.parseInt(sysConfig.getConfigValue())-1));
                    sysConfigService.updateConfig(sysConfig);
                }
                if(data.getIsprint().equals(print)){
//                    HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/setPrint","xinyongcode="+data.getXinyongcode()+userDetail);
                }
                return AjaxResult.success("操作成功");
            }else {
                return AjaxResult.warn("您已打印该文件,请勿重复操作", data);
            }
        } else {
            GtgsywPrintList result1 = gtgsywPrintListService.selectByPrimaryKey(bsid);
            if (bs == 1 && result1.getIsprint() == 0) {
                result1.setIsprint(1);
                Date date = new Date();
                result1.setPrinttime(date);
                System.err.println("打印时间===" + result1.getPrinttime());
                if(result1.getType()!=null){
                    GtgsBg gtgsBg=new GtgsBg();
                    gtgsBg.setPrintFlg("1");
                    gtgsBg.setPrintTime(date);
                    gtgsBg.setId(result1.getBsid());
                    if (gtgsBgService.updateGtgsBg(gtgsBg)==1){
                        SysConfig sysConfig=new SysConfig();
                        sysConfig.setConfigKey("zbzz");
                        List<SysConfig> sysConfigs=sysConfigService.selectConfigList(sysConfig);
                        sysConfig= sysConfigs.get(0);
                        sysConfig.setConfigValue(String.valueOf(Integer.parseInt(sysConfig.getConfigValue())-1));
                        sysConfigService.updateConfig(sysConfig);
                    }
                }else {
                    gtgsywPrintListService.updateByPrimaryKeySelective(result1);
                }
                if(result1.getIsprintF()==1){
//                    HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/setPrint","xinyongcode="+result1.getXinyongcode()+userDetail);
                }
                return AjaxResult.success("操作成功");
            } else if (bs == 0 && result1.getIsprintF() == 0) {
                result1.setIsprintF(1);
                Date date = new Date();
                result1.setPrinttimeF(date);
                System.err.println("打印时间===" + result1.getPrinttime());
                if(result1.getType()!=null){
                    GtgsBg gtgsBg=new GtgsBg();
                    gtgsBg.setPrintCopyFlg("1");
                    gtgsBg.setPrintCopyTime(date);
                    gtgsBg.setId(result1.getBsid());
                    if (gtgsBgService.updateGtgsBg(gtgsBg)==1){
                        SysConfig sysConfig=new SysConfig();
                        sysConfig.setConfigKey("fbzz");
                        List<SysConfig> sysConfigs=sysConfigService.selectConfigList(sysConfig);
                        sysConfig= sysConfigs.get(0);
                        sysConfig.setConfigValue(String.valueOf(Integer.parseInt(sysConfig.getConfigValue())-1));
                        sysConfigService.updateConfig(sysConfig);
                    }
                }else {
                    gtgsywPrintListService.updateByPrimaryKeySelective(result1);
                }
                if(result1.getIsprint()==1){
//                    HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/setPrint","xinyongcode="+result1.getXinyongcode()+userDetail);
                }
                return AjaxResult.success("操作成功");
            }else {
                return AjaxResult.warn("您已打印该文件,请勿重复操作", result1);
            }
        }
    }

    /**
     * 保存领取人信息
     *
     * @param gtgsyw
     * @return
     */
    @PostMapping("/saveImage")
    @ResponseBody
    public AjaxResult saveImages(Gtgsyw gtgsyw, Model model) {
        Gtgsyw sel = gtgsywService.selectByBsid(gtgsyw.getBsid());
        int result = 0;
        if (sel == null) {
            GtgsywPrintList result1 = gtgsywPrintListService.selectByPrimaryKey(gtgsyw.getBsid());
            String lqrPath= "/sqImg/"+ DateUtils.datePaths()+"/" + UUID.randomUUID().toString().replaceAll("-","").toLowerCase()+".jpg";
            if(Base64ToImage(gtgsyw.getLqrpaizhao(),Global.getProfile()+lqrPath)){
                result1.setLqrpaizhao("/profile"+lqrPath);//手写签名
            }
            String qmPath= "/sqImg/"+ DateUtils.datePaths()+"/" + UUID.randomUUID().toString().replaceAll("-","").toLowerCase()+".jpg";
            if(Base64ToImage(gtgsyw.getLqrqianming(),Global.getProfile()+qmPath)){
                result1.setLqrqianming("/profile"+qmPath);//手写签名
            }
            result = gtgsywPrintListService.updateByPrimaryKeySelective(result1);
        } else {
            String lqrPath= "/sqImg/"+ DateUtils.datePaths()+"/" + UUID.randomUUID().toString().replaceAll("-","").toLowerCase()+".jpg";
            if(Base64ToImage(gtgsyw.getLqrpaizhao(),Global.getProfile()+lqrPath)){
                sel.setLqrpaizhao("/profile"+lqrPath);//手写签名
            }
            String qmPath= "/sqImg/"+ DateUtils.datePaths()+"/" + UUID.randomUUID().toString().replaceAll("-","").toLowerCase()+".jpg";
            if(Base64ToImage(gtgsyw.getLqrqianming(),Global.getProfile()+qmPath)){
                sel.setLqrqianming("/profile"+qmPath);//手写签名
            }
            result = gtgsywService.updateGtgsyw(sel);
        }

        if (result == 1) {
            model.addAttribute("selData", sel);
            return AjaxResult.success("操作成功", result);
        } else {
            return warn("错误的返回", null);
        }
    }

    /**
     * 根据id查询退回信息
     *
     * @param tid 退回信息的id
     * @return
     */
    @GetMapping("/selback")
    @ResponseBody
    public AjaxResult selectbackByid(@Param("tid") Long tid, Model model) {
        Gtgsyw result = gtgsywService.selBack(tid);
        if (result == null) {
            return AjaxResult.warn("未找到退回信息");
        } else {
            return AjaxResult.success("操作成功", result);
        }
    }



}
