停车记录管理系统 - 停车记录控制器
package com.dian.controller;
import com.dian.domain.Chewei;
import com.dian.domain.Feiyong;
import com.dian.domain.Jilu;
import com.dian.service.JiluService;
import com.dian.type.ResponseType;
import com.dian.util.FastjsonUtils;
import com.dian.util.StringUtils;
import com.dian.vo.ResponseVo;
import com.dian.vo.Tongji;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
* 用于处理与停车记录相关的HTTP请求。
* 该类使用了Spring框架提供的注解功能,指定了请求的路径和请求方法,处理HTTP请求后返回相应的视图或数据。
*/
//使用@Controller注解标识该类为控制器类。
// 使用@RequestMapping注解指定请求路径和返回数据的格式。
//使用PageHelper插件实现分页查询,查询结果存储在Page对象中。
//使用getModelMap()方法获取ModelMap对象,用于存储返回的数据。
@Controller
@RequestMapping(value = "/jilu", produces = {"application/json;charset=UTF-8"})
public class JiluController extends BaseController {
// 使用@Resource注解注入依赖的JiluService对象。
@Resource
private JiluService jiluService;
// 使用@RequestMapping注解指定处理查询请求的方法query,并使用@RequestParam注解指定请求参数。
@RequestMapping(value = "/page/add")
public String addPage(ModelMap modelMap) {
List<Chewei> cheweis = cheweiService.query();
modelMap.put('cheweiList',cheweis);
return "/jilu/jilu_add";
}
@RequestMapping(value = "/query")
public String query(HttpServletRequest request, @RequestParam(required = false, defaultValue = "1") int startId,
@RequestParam(required = false, defaultValue = "1") int pageIndex,
@RequestParam(required = false, defaultValue = "10") int pageSize,
@RequestParam(required = false) String searchKey,ModelMap modelMap) {
if(StringUtils.isNotEmpty(searchKey)){
pageSize = 100;
}
Page<Jilu> result = jiluService.selectByPage(startId, pageIndex, pageSize, searchKey);
modelMap.put('jiluList', result.getResult());
if(StringUtils.isEmpty(searchKey)){
modelMap.put('page', getPageInfo(result).getHtml());
}
List<Chewei> cheweis = cheweiService.query();
modelMap.put('cheweiList',cheweis);
return "/jilu/jilu_list";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public String editTiku(HttpServletRequest request, Jilu jilu, ModelMap modelMap) {
if (jilu.getId() == null) {
modelMap.put('result', new ResponseVo(jiluService.insertSelective(jilu) ? ResponseType.ADD_SUCCESS : ResponseType.ADD_FAIL));
Chewei chewei = cheweiService.selectByPrimaryKey(jilu.getCheweiid());
chewei.setState(0);
cheweiService.updateByPrimaryKey(chewei);
}
return FastjsonUtils.serialize(modelMap);
}
@RequestMapping(value = "/del/{id}")
@ResponseBody
public String del(@PathVariable Integer id, ModelMap modelMap) {
Jilu jiluS = jiluService.selectByPrimaryKey(id);
Chewei chewei = cheweiService.selectByPrimaryKey(jiluS.getCheweiid());
chewei.setState(1);
cheweiService.updateByPrimaryKey(chewei);
Jilu jilu = new Jilu();
jilu.setId(id);
//直接删除
boolean result = jiluService.deleteByPrimaryKey(id);
//更新删除
modelMap.put('result', new ResponseVo(result ? ResponseType.DEL_SUCCESS : ResponseType.DEL_FAIL));
return FastjsonUtils.serialize(modelMap);
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ResponseBody
public String edit(HttpServletRequest request, Jilu jilu, ModelMap modelMap) {
long zongjia = 0;
long shichang = (long) Math.ceil(((jilu.getChushijian().getTime() - jilu.getRushijian().getTime())/(1000*60*60.0)));
Chewei chewei = cheweiService.selectByPrimaryKey(jilu.getCheweiid());
Feiyong feiyong = feiyongService.selectByLeixing(chewei.getLeixing());
zongjia = (long) (feiyong.getJiage() * shichang);
jilu.setDanjia((double) zongjia);
modelMap.put('result', new ResponseVo(jiluService.updateByPrimaryKeySelective(jilu) ? ResponseType.EDIT_SUCCESS : ResponseType.EDIT_FAIL));
chewei.setState(1);
cheweiService.updateByPrimaryKey(chewei);
return FastjsonUtils.serialize(modelMap);
}
@RequestMapping(value = "/jiaofei/{id}", method = RequestMethod.POST)
@ResponseBody
public String jiaofei(@PathVariable Integer id, ModelMap modelMap) {
Jilu jilu = jiluService.selectByPrimaryKey(id);
jilu.setChushijian(new Date());
long zongjia = 0;
long shichang = (long) Math.ceil(((jilu.getChushijian().getTime() - jilu.getRushijian().getTime())/(1000*60*60.0)));
Chewei chewei = cheweiService.selectByPrimaryKey(jilu.getCheweiid());
Feiyong feiyong = feiyongService.selectByLeixing(chewei.getLeixing());
zongjia = (long) (feiyong.getJiage() * shichang);
jilu.setDanjia((double) zongjia);
modelMap.put('result', new ResponseVo(jiluService.updateByPrimaryKeySelective(jilu) ? ResponseType.JIAOFEI_SUCCESS : ResponseType.JIAOFEI_FAIL));
chewei.setState(1);
cheweiService.updateByPrimaryKey(chewei);
return FastjsonUtils.serialize(modelMap);
}
@RequestMapping(value = "/page/edit/{id}")
public String editTiku(@PathVariable Integer id, ModelMap modelMap) {
Jilu result = jiluService.selectByPrimaryKey(id);
List<Chewei> cheweis = cheweiService.query();
modelMap.put('cheweiList',cheweis);
modelMap.put('result', result);
return "/jilu/jilu_edit";
}
@RequestMapping(value = "/page/lintongji")
public String lintongji() {
return "/tongji/lintongji_list";
}
@RequestMapping(value = "/tj/day")
@ResponseBody
public String getTongjiByDay(Integer days, ModelMap modelMap){
Tongji tongji = jiluService.getTongjiByDay(days);
modelMap.put('tongji', tongji);
return FastjsonUtils.serialize(modelMap);
}
}}```
原文地址: https://www.cveoy.top/t/topic/kLyu 著作权归作者所有。请勿转载和采集!