小时费率接口、mybatisplus自动生成代码组件
This commit is contained in:
+162
@@ -0,0 +1,162 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
|
||||
import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Description: hour_rate
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-06-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Api(tags="hour_rate")
|
||||
@RestController
|
||||
@RequestMapping("//hourRate")
|
||||
@Slf4j
|
||||
public class HourRateController extends JeecgController<HourRate, IHourRateService> {
|
||||
@Autowired
|
||||
private IHourRateService hourRateService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param hourRate
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "hour_rate-分页列表查询")
|
||||
@ApiOperation(value="hour_rate-分页列表查询", notes="hour_rate-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<HourRate>> queryPageList(HourRate hourRate,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<HourRate> queryWrapper = QueryGenerator.initQueryWrapper(hourRate, req.getParameterMap());
|
||||
Page<HourRate> page = new Page<HourRate>(pageNo, pageSize);
|
||||
IPage<HourRate> pageList = hourRateService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param hourRate
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "hour_rate-添加")
|
||||
@ApiOperation(value="hour_rate-添加", notes="hour_rate-添加")
|
||||
@RequiresPermissions(":hour_rate:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody HourRate hourRate) {
|
||||
hourRateService.save(hourRate);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param hourRate
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "hour_rate-编辑")
|
||||
@ApiOperation(value="hour_rate-编辑", notes="hour_rate-编辑")
|
||||
@RequiresPermissions(":hour_rate:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody HourRate hourRate) {
|
||||
hourRateService.updateById(hourRate);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "hour_rate-通过id删除")
|
||||
@ApiOperation(value="hour_rate-通过id删除", notes="hour_rate-通过id删除")
|
||||
@RequiresPermissions(":hour_rate:delete")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
||||
hourRateService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "hour_rate-批量删除")
|
||||
@ApiOperation(value="hour_rate-批量删除", notes="hour_rate-批量删除")
|
||||
@RequiresPermissions(":hour_rate:deleteBatch")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
this.hourRateService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "hour_rate-通过id查询")
|
||||
@ApiOperation(value="hour_rate-通过id查询", notes="hour_rate-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<HourRate> queryById(@RequestParam(name="id",required=true) String id) {
|
||||
HourRate hourRate = hourRateService.getById(id);
|
||||
if(hourRate==null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(hourRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param hourRate
|
||||
*/
|
||||
@RequiresPermissions(":hour_rate:exportXls")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HourRate hourRate) {
|
||||
return super.exportXls(request, hourRate, HourRate.class, "hour_rate");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions(":hour_rate:importExcel")
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, HourRate.class);
|
||||
}
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: hour_rate
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-06-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("hour_rate")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="hour_rate对象", description="hour_rate")
|
||||
public class HourRate implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**年度*/
|
||||
@Excel(name = "年度", width = 15)
|
||||
@ApiModelProperty(value = "年度")
|
||||
private java.lang.String year;
|
||||
/**成本中心代码*/
|
||||
@Excel(name = "成本中心代码", width = 15)
|
||||
@ApiModelProperty(value = "成本中心代码")
|
||||
private java.lang.String costCenterCode;
|
||||
/**工厂代码*/
|
||||
@Excel(name = "工厂代码", width = 15)
|
||||
@ApiModelProperty(value = "工厂代码")
|
||||
private java.lang.String factory;
|
||||
/**人工小时费率*/
|
||||
@Excel(name = "人工小时费率", width = 15)
|
||||
@ApiModelProperty(value = "人工小时费率")
|
||||
private java.math.BigDecimal laborHourRate;
|
||||
/**设备小时费率*/
|
||||
@Excel(name = "设备小时费率", width = 15)
|
||||
@ApiModelProperty(value = "设备小时费率")
|
||||
private java.math.BigDecimal equipHourRate;
|
||||
/**燃动小时费率*/
|
||||
@Excel(name = "燃动小时费率", width = 15)
|
||||
@ApiModelProperty(value = "燃动小时费率")
|
||||
private java.math.BigDecimal fuelHourRate;
|
||||
/**辅料小时费率*/
|
||||
@Excel(name = "辅料小时费率", width = 15)
|
||||
@ApiModelProperty(value = "辅料小时费率")
|
||||
private java.math.BigDecimal auxiliaryHourRate;
|
||||
/**其他小时费率*/
|
||||
@Excel(name = "其他小时费率", width = 15)
|
||||
@ApiModelProperty(value = "其他小时费率")
|
||||
private java.math.BigDecimal otherHourRate;
|
||||
/**生效日期*/
|
||||
@Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd")
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@ApiModelProperty(value = "生效日期")
|
||||
private java.util.Date effectiveDate;
|
||||
/**失效日期*/
|
||||
@Excel(name = "失效日期", width = 15, format = "yyyy-MM-dd")
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@ApiModelProperty(value = "失效日期")
|
||||
private java.util.Date expirationDate;
|
||||
/**维护人员*/
|
||||
@Excel(name = "维护人员", width = 15)
|
||||
@ApiModelProperty(value = "维护人员")
|
||||
private java.lang.String guardian;
|
||||
/**维护时间*/
|
||||
@Excel(name = "维护时间", width = 15)
|
||||
@ApiModelProperty(value = "维护时间")
|
||||
private java.lang.String maintenanceTime;
|
||||
/**预留字段1*/
|
||||
@Excel(name = "预留字段1", width = 15)
|
||||
@ApiModelProperty(value = "预留字段1")
|
||||
private java.lang.String reserve1;
|
||||
/**预留字段2*/
|
||||
@Excel(name = "预留字段2", width = 15)
|
||||
@ApiModelProperty(value = "预留字段2")
|
||||
private java.math.BigDecimal reserve2;
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private java.lang.String id;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
|
||||
|
||||
/**
|
||||
* @Description: hour_rate
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-06-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface HourRateMapper extends BaseMapper<HourRate> {
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zzsmart.qomo.modules.demo..mapper.HourRateMapper">
|
||||
|
||||
</mapper>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
|
||||
|
||||
/**
|
||||
* @Description: hour_rate
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-06-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface IHourRateService extends IService<HourRate> {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
|
||||
import com.zzsmart.qomo.kn.cost.manage.mapper.HourRateMapper;
|
||||
import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: hour_rate
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-06-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class HourRateServiceImpl extends ServiceImpl<HourRateMapper, HourRate> implements IHourRateService {
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.zzsmart.qomo.kn.cost.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import java.sql.Types;
|
||||
import java.util.Collections;
|
||||
|
||||
@SpringBootTest
|
||||
public class ApplicationTests {
|
||||
|
||||
/**
|
||||
* 根据表名生成相应结构代码
|
||||
* @param databaseName 数据库名
|
||||
* @param tableName 表名
|
||||
*/
|
||||
@Test
|
||||
public static void Generation(String databaseName,String... tableName){
|
||||
FastAutoGenerator.create("jdbc:mysql://localhost:3306/"+databaseName+"?&useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai","root","wsndqd857857")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("罗添煦")
|
||||
//启用swagger
|
||||
//.enableSwagger()
|
||||
//指定输出目录
|
||||
.outputDir(System.getProperty("user.dir")+"/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.entity("entity")//实体类包名
|
||||
.parent("com.ltx.mpcode")//父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
||||
.controller("controller")//控制层包名
|
||||
.mapper("dao")//mapper层包名
|
||||
//.other("dto")//生成dto目录 可不用
|
||||
.service("service")//service层包名
|
||||
.serviceImpl("service.impl")//service实现类包名
|
||||
//自定义mapper.xml文件输出目录
|
||||
.pathInfo(Collections.singletonMap(OutputFile.mapperXml,System.getProperty("user.dir")+"/src/main/resources/mapper"));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
//设置要生成的表名
|
||||
builder.addInclude(tableName)
|
||||
.addInclude("cp_order_history")// 设置需要生成的表名
|
||||
//.addTablePrefix("sys_")//设置表前缀过滤
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableChainModel()
|
||||
.naming(NamingStrategy.underline_to_camel)//数据表映射实体命名策略:默认下划线转驼峰underline_to_camel
|
||||
.columnNaming(NamingStrategy.underline_to_camel)//表字段映射实体属性命名规则:默认null,不指定按照naming执行
|
||||
.idType(IdType.AUTO)//添加全局主键类型
|
||||
.formatFileName("%s")//格式化实体名称,%s取消首字母I,
|
||||
.mapperBuilder()
|
||||
.enableMapperAnnotation()//开启mapper注解
|
||||
.enableBaseResultMap()//启用xml文件中的BaseResultMap 生成
|
||||
.enableBaseColumnList()//启用xml文件中的BaseColumnList
|
||||
.formatMapperFileName("%sMapper")//格式化Dao类名称
|
||||
.formatXmlFileName("%sMapper")//格式化xml文件名称
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")//格式化 service 接口文件名称
|
||||
.formatServiceImplFileName("%sServiceImpl")//格式化 service 接口文件名称
|
||||
.controllerBuilder()
|
||||
.enableRestStyle();
|
||||
})
|
||||
// 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user