package com.flow.controller; import com.flow.pojo.Card; import com.flow.pojo.TbFuwuqi; import com.flow.service.CompanyService; import com.flow.service.TbFuwuqiService; import com.flow.util.result; import com.flow.util.resultutil; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @RestController @RequestMapping({"/hxzk"}) public class TbFuwuqiController { @Autowired TbFuwuqiService tbFuwuqiService; @Autowired CompanyService companyService; @GetMapping({"findTbFuwuqi"}) result> findBangZhu(Integer page, Integer limit) throws ParseException { PageInfo cz = this.tbFuwuqiService.FindTbFuwuqi(page, limit); for(int i = 0; i < cz.getSize(); ++i) { if (((TbFuwuqi)cz.getList().get(i)).getCompany() != null) { SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间 Long starTime = date.getTime(); Long endTime = endDay.getTime(); Long num11 = endTime - starTime;//时间戳 if ((num11/24/60/60/1000)<0){ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays("0天"); }else{ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays(+num11/24/60/60/1000+"天"); } if (!((TbFuwuqi)cz.getList().get(i)).getRemainingdays().equals("0天") || !((TbFuwuqi)cz.getList().get(i)).getRemainingdays().equals(+num11/24/60/60/1000+"天") ){ this.tbFuwuqiService.UpdateTbFuwuqi((TbFuwuqi)cz.getList().get(i)); } // } } return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @GetMapping({"findTbFuwuqiZi"}) result> findTbFuwuqiZi(String Zong, Integer page, Integer limit) throws ParseException { PageInfo cz = this.tbFuwuqiService.findTbFuwuqiZi(Zong, page, limit); for(int i = 0; i < cz.getSize(); ++i) { if (((TbFuwuqi)cz.getList().get(i)).getCompany() != null) { SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间 Long starTime = date.getTime(); Long endTime = endDay.getTime(); Long num11 = endTime - starTime;//时间戳 if ((num11/24/60/60/1000)<0){ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays("0天"); }else{ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays(+num11/24/60/60/1000+"天"); } if (!((TbFuwuqi)cz.getList().get(i)).getRemainingdays().equals("0天") || !((TbFuwuqi)cz.getList().get(i)).getRemainingdays().equals(+num11/24/60/60/1000+"天") ){ this.tbFuwuqiService.UpdateTbFuwuqi((TbFuwuqi)cz.getList().get(i)); } } } return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @PostMapping({"addTbFuwuqi"}) public ModelAndView addBang(TbFuwuqi tbFuwuqi) throws Exception { ModelAndView modelAndView = new ModelAndView(); tbFuwuqi.setId(null); this.tbFuwuqiService.addTbFuwuqi(tbFuwuqi); modelAndView.addObject("suoshu", this.companyService.findSuoShu()); modelAndView.setViewName("/page/Fuwuqi.jsp"); return modelAndView; } @PostMapping({"UpdateTbFuwuqi"}) public ModelAndView UpdateCard(TbFuwuqi tbFuwuqi) { this.tbFuwuqiService.UpdateTbFuwuqi(tbFuwuqi); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/page/Fuwuqi.jsp"); return modelAndView; } @PostMapping({"DeleteTbFuwuqi"}) public int DeleteCard(String num) { return this.tbFuwuqiService.DeleteTbFuwuqi(num); } @PostMapping({"tbFuwuqiSearch"}) public result> tableSearch(TbFuwuqi tbFuwuqi, int page, int limit) throws Exception { PageInfo cz = this.tbFuwuqiService.tableSearch(tbFuwuqi, page, limit); for(int i = 0; i < cz.getSize(); ++i) { if (((TbFuwuqi)cz.getList().get(i)).getCompany() != null) { SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间 Long starTime = date.getTime(); Long endTime = endDay.getTime(); Long num11 = endTime - starTime;//时间戳 if ((num11/24/60/60/1000)<0){ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays("0天"); }else{ ((TbFuwuqi)cz.getList().get(i)).setRemainingdays(+num11/24/60/60/1000+"天"); } // this.cardService.UpdateCard((Card)cz.getList().get(i)); // this.cardService.UpdateCard((Card)cz.getList().get(i)); } } return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @PostMapping({"ifFuwuqi"}) public TbFuwuqi ifFuwuqi(TbFuwuqi tbFuwuqi) { return this.tbFuwuqiService.ifFuwuqi(tbFuwuqi); } }