栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis-Plus 实现联表查询

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis-Plus 实现联表查询

Mybatis-Plus 实现联表查询

mapper
package com.sf.map.entity.mysql.stat;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_stat_field_collect")
@ApiModel(value="StatFieldCollect对象", description="外业采集量统计报表")
public class StatFieldCollect implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "统计日期")
    private String statDate;

    @ApiModelProperty(value = "所属采集项目ID")
    private Integer planProjectId;

    @ApiModelProperty(value = "所属采集计划ID")
    private Integer planCollectId;

    @ApiModelProperty(value = "采集员")
    private String workUser;

    @ApiModelProperty(value = "7_8点采集提交量")
    private Integer c_7_8;

    @ApiModelProperty(value = "8_9点采集提交量")
    private Integer c_8_9;

    @ApiModelProperty(value = "9_10点采集提交量")
    private Integer c_9_10;

    @ApiModelProperty(value = "10_11点采集提交量")
    private Integer c_10_11;

    @ApiModelProperty(value = "11_12点采集提交量")
    private Integer c_11_12;

    @ApiModelProperty(value = "12_13点采集提交量")
    private Integer c_12_13;

    @ApiModelProperty(value = "13_14点采集提交量")
    private Integer c_13_14;

    @ApiModelProperty(value = "14_15点采集提交量")
    private Integer c_14_15;

    @ApiModelProperty(value = "15_16点采集提交量")
    private Integer c_15_16;

    @ApiModelProperty(value = "16_17点采集提交量")
    private Integer c_16_17;

    @ApiModelProperty(value = "17_18点采集提交量")
    private Integer c_17_18;

    @ApiModelProperty(value = "18_19点采集提交量")
    private Integer c_18_19;

    @ApiModelProperty(value = "19_20点采集提交量")
    private Integer c_19_20;

    @ApiModelProperty(value = "其他时间段采集提交量")
    private Integer cOther;

    @ApiModelProperty(value = "采集提交总量")
    private Integer cSum;

    @ApiModelProperty(value = "采集返工提交总量")
    private Integer cSumRework;

    @ApiModelProperty(value = "出勤时长,分钟")
    private Integer workTime;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "真实姓名")
    private String realname;


    public static final String STAT_DATE = "stat_date";
    public static final String PLAN_PROJECT_ID = "plan_project_id";
    public static final String PLAN_COLLECT_ID = "plan_collect_id";
    public static final String WORK_USER = "work_user";
    public static final String C_7_8 = "c_7_8";
    public static final String C_8_9 = "c_8_9";
    public static final String C_9_10 = "c_9_10";
    public static final String C_10_11 = "c_10_11";
    public static final String C_11_12 = "c_11_12";
    public static final String C_12_13 = "c_12_13";
    public static final String C_13_14 = "c_13_14";
    public static final String C_14_15 = "c_14_15";
    public static final String C_15_16 = "c_15_16";
    public static final String C_16_17 = "c_16_17";
    public static final String C_17_18 = "c_17_18";
    public static final String C_18_19 = "c_18_19";
    public static final String C_19_20 = "c_19_20";
    public static final String C_OTHER = "c_other";
    public static final String C_SUM = "c_sum";
    public static final String C_SUM_REWORK = "c_sum_rework";
    public static final String WORK_TIME = "work_time";
    public static final String CREATE_TIME = "create_time";
    public static final String UPDATE_TIME = "update_time";
    public static final String REALNAME = "realname";
}

XML



    
	
	

service interface
package com.sf.map.service.stat;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sf.map.entity.mysql.plan.PlanProject;
import com.sf.map.entity.mysql.stat.StatFieldCollect;
import org.springframework.data.domain.PageRequest;

import java.util.List;
import java.util.Map;


public interface FieldStatCollectService extends IService {
    void statFieldCollectInfoByProc(Map map);

    Page selectStatListPage(int pageIndex, int step, StatFieldCollect statFieldCollect);
}
impl
package com.sf.map.service.stat.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.map.entity.mysql.stat.StatFieldCollect;
import com.sf.map.exception.MyException;
import com.sf.map.mapper.mysql.stat.StatFieldCollectMapper;
import com.sf.map.service.stat.FieldStatCollectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class FieldDailyStatServiceImpl extends ServiceImpl implements FieldStatCollectService {

    @Autowired(required = false)
    private StatFieldCollectMapper statFieldCollectMapper;

    @Override
    public void statFieldCollectInfoByProc(Map map){
        try {
            statFieldCollectMapper.statFieldCollectInfo(map);
        }catch(Exception e) {
            throw new MyException("外业采集量统计失败!msg=" + e.getMessage());
        }
    }

    @Override
    public Page selectStatListPage(int pageIndex, int step, StatFieldCollect statFieldCollect) {
        Page page = new Page(pageIndex, step);

        return page.setRecords(statFieldCollectMapper.selectStatListPage(page, statFieldCollect));
    }
}
Controller
package com.sf.map.controller.stat;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sf.map.entity.mysql.stat.StatFieldCollect;
import com.sf.map.service.stat.FieldStatCollectService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Objects;

@RestController
@RequestMapping("/Stat/FieldCollect")
@Api(tags = "外业采集量统计表")
public class StatFieldCollectController {
    @Autowired
    private FieldStatCollectService fieldStatCollectService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Page findListByPage(@RequestParam(name = "pageNum", defaultValue = "1") int pageIndex,
                               @RequestParam(name = "pageSize", defaultValue = "20") int step){

        StatFieldCollect statFieldCollect = new StatFieldCollect();
        return fieldStatCollectService.selectStatListPage(pageIndex, step, statFieldCollect);

    }

	private void statFieldCollectByOpFlag(Long projectId, int opFlag){
        log.info("开始外业统计项目opflag-{},id-{}", opFlag, projectId);

        try {
            Date date = new Date();
            String nowDate = DateUtil.formatDate(date, "yyyy-MM-dd");
            // 当前日期减去2个月
            String startDate = DateUtil.formatDate(DateUtil.dateDiffer(date, "M",-2), "yyyy-MM-dd");

            Map map = new HashMap();
            map.put("i_op_flag", opFlag);
            map.put("i_plan_project_id", projectId);
            map.put("i_stat_date", nowDate);
            map.put("o_err_no", 0);
            map.put("o_err_msg", "");
            try {
                fieldStatCollectService.statFieldCollectInfoByProc(map);

                BigDecimal bigDecimal= (BigDecimal)map.get("o_err_no");
                Integer errNo = bigDecimal.intValue();
                if ( !errNo.equals(0) ){
                    String errMsg = (String)map.get("o_err_msg");
                    log.error("外业统计项目["+opFlag+"-"+projectId+"]异常["+errNo.toString()+"]"+errMsg);
                }
            } catch (Exception e) {
                log.error("外业统计项目["+opFlag+"-"+projectId+"]异常", e);
            }
            log.info("结束外业统计项目opflag-{},id-{}", opFlag, projectId);
        } catch (Exception e) {
            log.error("结束外业统计项目["+opFlag+"-"+projectId+"]异常", e);
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/605757.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号