package com.dian.service;

import com.dian.domain.Gudingche;
import com.dian.mapper.GudingcheMapper;
import com.dian.util.DateUtil;
import com.dian.vo.Tongji;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 固定车服务类
 */
@Service
public class GudingcheService {

    @Resource
    private GudingcheMapper gudingcheMapper;

    public boolean deleteByPrimaryKey(Integer id) {
        return gudingcheMapper.deleteByPrimaryKey(id) == 1;
    }

    public boolean insert(Gudingche entify) {
        return gudingcheMapper.insert(entify) == 1;
    }

    public boolean insertSelective(Gudingche entify) {
        return gudingcheMapper.insertSelective(entify) == 1;
    }

    public Gudingche selectByPrimaryKey(Integer id) {
        return gudingcheMapper.selectByPrimaryKey(id);
    }

    public boolean updateByPrimaryKeySelective(Gudingche entify) {
        return gudingcheMapper.updateByPrimaryKeySelective(entify) == 1;
    }

    public boolean updateByPrimaryKey(Gudingche entify) {
        return gudingcheMapper.updateByPrimaryKey(entify) == 1;
    }

    public Page<Gudingche> selectByPage(Integer startId, Integer pageIndex, Integer pageSize) {
        Page<Gudingche> pageVenderList = PageHelper.startPage(pageIndex, pageSize);
        gudingcheMapper.query(pageIndex, pageSize);
        return pageVenderList;
    }

    public Tongji getTongjiByMonth(Integer months) {
        Tongji tongji = new Tongji();
        List<Map<String, Double>> jilus = gudingcheMapper.queryByMonth(months);
        if(null != jilus && jilus.size() > 0){
            String[] x = new String[jilus.size()];
            String[] y = new String[jilus.size()];
            for(int i =0;i<jilus.size();i++){
                Map<String, Double> map = jilus.get(i);
                try {
                    x[i] = DateUtil.formatWeb(map.get('riqi')+"",DateUtil.MONTH_WEB_FORMAT);
                    y[i] = map.get('danjia')+"";
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            tongji.setY(y);
            tongji.setX(x);
        }
        return tongji;
    }
}

代码解释:

这段代码是一个服务类GudingcheService,用于对固定车实体进行增删改查操作,并提供了分页查询和统计功能。其中,使用了注解@Service标记为服务类,使用了@Resource注解注入了GudingcheMapper对象,用于与数据库进行交互。该类提供了以下方法:

  • deleteByPrimaryKey(Integer id):根据主键id删除固定车实体。
  • insert(Gudingche entify):插入一条固定车实体数据。
  • insertSelective(Gudingche entify):插入一条固定车实体数据(可选择性插入)。
  • selectByPrimaryKey(Integer id):根据主键id查询固定车实体。
  • updateByPrimaryKeySelective(Gudingche entify):根据主键id更新固定车实体数据(可选择性更新)。
  • updateByPrimaryKey(Gudingche entify):根据主键id更新固定车实体数据。
  • selectByPage(Integer startId, Integer pageIndex, Integer pageSize):分页查询固定车实体数据。
  • getTongjiByMonth(Integer months):根据月份统计固定车实体数据,并返回统计结果。

使用方法:

该类可以通过Spring框架进行依赖注入,然后调用其方法来进行相关操作。例如,可以通过以下代码获取固定车信息:

GudingcheService gudingcheService = (GudingcheService) SpringContextUtils.getBean('gudingcheService');
Gudingche gudingche = gudingcheService.selectByPrimaryKey(1);

注意事项:

  • 该类依赖于GudingcheMapper接口,需要确保GudingcheMapper接口已正确实现。
  • getTongjiByMonth方法使用了DateUtil类,需要确保DateUtil类已正确配置。
  • 该类使用了PageHelper插件进行分页查询,需要确保PageHelper插件已正确配置。

总结:

该服务类提供了一套完整的固定车实体管理功能,包括增删改查、分页查询和统计功能,可以方便地进行固定车实体的操作。

固定车服务类 - 增删改查、分页查询和统计功能

原文地址: https://www.cveoy.top/t/topic/kLR0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录