Преглед на файлове

小时费率接口、mybatisplus自动生成代码组件

wangqiong преди 2 години
родител
ревизия
41480ba1c9

+ 15
- 0
qomo-kn-cost-manage/pom.xml Целия файл

@@ -23,6 +23,21 @@
23 23
             <artifactId>qomo-system-biz</artifactId>
24 24
             <version>2.0.1-SNAPSHOT</version>
25 25
         </dependency>
26
+        <dependency>
27
+            <groupId>org.springframework.boot</groupId>
28
+            <artifactId>spring-boot-test</artifactId>
29
+            <scope>test</scope>
30
+        </dependency>
31
+        <dependency>
32
+            <groupId>junit</groupId>
33
+            <artifactId>junit</artifactId>
34
+            <scope>test</scope>
35
+        </dependency>
36
+        <dependency>
37
+            <groupId>com.baomidou</groupId>
38
+            <artifactId>mybatis-plus-generator</artifactId>
39
+            <version>3.5.1</version>
40
+        </dependency>
26 41
     </dependencies>
27 42
 
28 43
 </project>

+ 162
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/HourRateController.java Целия файл

@@ -0,0 +1,162 @@
1
+package com.zzsmart.qomo.kn.cost.manage.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
7
+import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import lombok.extern.slf4j.Slf4j;
11
+import org.apache.shiro.authz.annotation.RequiresPermissions;
12
+import org.jeecg.common.api.vo.Result;
13
+import org.jeecg.common.aspect.annotation.AutoLog;
14
+import org.jeecg.common.system.base.controller.JeecgController;
15
+import org.jeecg.common.system.query.QueryGenerator;
16
+import org.springframework.beans.factory.annotation.Autowired;
17
+import org.springframework.web.bind.annotation.*;
18
+import org.springframework.web.servlet.ModelAndView;
19
+
20
+import javax.servlet.http.HttpServletRequest;
21
+import javax.servlet.http.HttpServletResponse;
22
+import java.util.Arrays;
23
+
24
+ /**
25
+ * @Description: hour_rate
26
+ * @Author: jeecg-boot
27
+ * @Date:   2024-06-06
28
+ * @Version: V1.0
29
+ */
30
+@Api(tags="hour_rate")
31
+@RestController
32
+@RequestMapping("//hourRate")
33
+@Slf4j
34
+public class HourRateController extends JeecgController<HourRate, IHourRateService> {
35
+	@Autowired
36
+	private IHourRateService hourRateService;
37
+	
38
+	/**
39
+	 * 分页列表查询
40
+	 *
41
+	 * @param hourRate
42
+	 * @param pageNo
43
+	 * @param pageSize
44
+	 * @param req
45
+	 * @return
46
+	 */
47
+	//@AutoLog(value = "hour_rate-分页列表查询")
48
+	@ApiOperation(value="hour_rate-分页列表查询", notes="hour_rate-分页列表查询")
49
+	@GetMapping(value = "/list")
50
+	public Result<IPage<HourRate>> queryPageList(HourRate hourRate,
51
+								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
52
+								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
53
+								   HttpServletRequest req) {
54
+		QueryWrapper<HourRate> queryWrapper = QueryGenerator.initQueryWrapper(hourRate, req.getParameterMap());
55
+		Page<HourRate> page = new Page<HourRate>(pageNo, pageSize);
56
+		IPage<HourRate> pageList = hourRateService.page(page, queryWrapper);
57
+		return Result.OK(pageList);
58
+	}
59
+	
60
+	/**
61
+	 *   添加
62
+	 *
63
+	 * @param hourRate
64
+	 * @return
65
+	 */
66
+	@AutoLog(value = "hour_rate-添加")
67
+	@ApiOperation(value="hour_rate-添加", notes="hour_rate-添加")
68
+	@RequiresPermissions(":hour_rate:add")
69
+	@PostMapping(value = "/add")
70
+	public Result<String> add(@RequestBody HourRate hourRate) {
71
+		hourRateService.save(hourRate);
72
+		return Result.OK("添加成功!");
73
+	}
74
+	
75
+	/**
76
+	 *  编辑
77
+	 *
78
+	 * @param hourRate
79
+	 * @return
80
+	 */
81
+	@AutoLog(value = "hour_rate-编辑")
82
+	@ApiOperation(value="hour_rate-编辑", notes="hour_rate-编辑")
83
+	@RequiresPermissions(":hour_rate:edit")
84
+	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
85
+	public Result<String> edit(@RequestBody HourRate hourRate) {
86
+		hourRateService.updateById(hourRate);
87
+		return Result.OK("编辑成功!");
88
+	}
89
+	
90
+	/**
91
+	 *   通过id删除
92
+	 *
93
+	 * @param id
94
+	 * @return
95
+	 */
96
+	@AutoLog(value = "hour_rate-通过id删除")
97
+	@ApiOperation(value="hour_rate-通过id删除", notes="hour_rate-通过id删除")
98
+	@RequiresPermissions(":hour_rate:delete")
99
+	@DeleteMapping(value = "/delete")
100
+	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
101
+		hourRateService.removeById(id);
102
+		return Result.OK("删除成功!");
103
+	}
104
+	
105
+	/**
106
+	 *  批量删除
107
+	 *
108
+	 * @param ids
109
+	 * @return
110
+	 */
111
+	@AutoLog(value = "hour_rate-批量删除")
112
+	@ApiOperation(value="hour_rate-批量删除", notes="hour_rate-批量删除")
113
+	@RequiresPermissions(":hour_rate:deleteBatch")
114
+	@DeleteMapping(value = "/deleteBatch")
115
+	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
116
+		this.hourRateService.removeByIds(Arrays.asList(ids.split(",")));
117
+		return Result.OK("批量删除成功!");
118
+	}
119
+	
120
+	/**
121
+	 * 通过id查询
122
+	 *
123
+	 * @param id
124
+	 * @return
125
+	 */
126
+	//@AutoLog(value = "hour_rate-通过id查询")
127
+	@ApiOperation(value="hour_rate-通过id查询", notes="hour_rate-通过id查询")
128
+	@GetMapping(value = "/queryById")
129
+	public Result<HourRate> queryById(@RequestParam(name="id",required=true) String id) {
130
+		HourRate hourRate = hourRateService.getById(id);
131
+		if(hourRate==null) {
132
+			return Result.error("未找到对应数据");
133
+		}
134
+		return Result.OK(hourRate);
135
+	}
136
+
137
+    /**
138
+    * 导出excel
139
+    *
140
+    * @param request
141
+    * @param hourRate
142
+    */
143
+    @RequiresPermissions(":hour_rate:exportXls")
144
+    @RequestMapping(value = "/exportXls")
145
+    public ModelAndView exportXls(HttpServletRequest request, HourRate hourRate) {
146
+        return super.exportXls(request, hourRate, HourRate.class, "hour_rate");
147
+    }
148
+
149
+    /**
150
+      * 通过excel导入数据
151
+    *
152
+    * @param request
153
+    * @param response
154
+    * @return
155
+    */
156
+    @RequiresPermissions(":hour_rate:importExcel")
157
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
158
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
159
+        return super.importExcel(request, response, HourRate.class);
160
+    }
161
+
162
+}

+ 99
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/HourRate.java Целия файл

@@ -0,0 +1,99 @@
1
+package com.zzsmart.qomo.kn.cost.manage.entity;
2
+
3
+import java.io.Serializable;
4
+import java.io.UnsupportedEncodingException;
5
+import java.util.Date;
6
+import java.math.BigDecimal;
7
+import com.baomidou.mybatisplus.annotation.IdType;
8
+import com.baomidou.mybatisplus.annotation.TableId;
9
+import com.baomidou.mybatisplus.annotation.TableName;
10
+import com.baomidou.mybatisplus.annotation.TableLogic;
11
+import lombok.Data;
12
+import com.fasterxml.jackson.annotation.JsonFormat;
13
+import org.springframework.format.annotation.DateTimeFormat;
14
+import org.jeecgframework.poi.excel.annotation.Excel;
15
+import org.jeecg.common.aspect.annotation.Dict;
16
+import io.swagger.annotations.ApiModel;
17
+import io.swagger.annotations.ApiModelProperty;
18
+import lombok.EqualsAndHashCode;
19
+import lombok.experimental.Accessors;
20
+
21
+/**
22
+ * @Description: hour_rate
23
+ * @Author: jeecg-boot
24
+ * @Date:   2024-06-06
25
+ * @Version: V1.0
26
+ */
27
+@Data
28
+@TableName("hour_rate")
29
+@Accessors(chain = true)
30
+@EqualsAndHashCode(callSuper = false)
31
+@ApiModel(value="hour_rate对象", description="hour_rate")
32
+public class HourRate implements Serializable {
33
+    private static final long serialVersionUID = 1L;
34
+
35
+	/**年度*/
36
+	@Excel(name = "年度", width = 15)
37
+    @ApiModelProperty(value = "年度")
38
+    private java.lang.String year;
39
+	/**成本中心代码*/
40
+	@Excel(name = "成本中心代码", width = 15)
41
+    @ApiModelProperty(value = "成本中心代码")
42
+    private java.lang.String costCenterCode;
43
+	/**工厂代码*/
44
+	@Excel(name = "工厂代码", width = 15)
45
+    @ApiModelProperty(value = "工厂代码")
46
+    private java.lang.String factory;
47
+	/**人工小时费率*/
48
+	@Excel(name = "人工小时费率", width = 15)
49
+    @ApiModelProperty(value = "人工小时费率")
50
+    private java.math.BigDecimal laborHourRate;
51
+	/**设备小时费率*/
52
+	@Excel(name = "设备小时费率", width = 15)
53
+    @ApiModelProperty(value = "设备小时费率")
54
+    private java.math.BigDecimal equipHourRate;
55
+	/**燃动小时费率*/
56
+	@Excel(name = "燃动小时费率", width = 15)
57
+    @ApiModelProperty(value = "燃动小时费率")
58
+    private java.math.BigDecimal fuelHourRate;
59
+	/**辅料小时费率*/
60
+	@Excel(name = "辅料小时费率", width = 15)
61
+    @ApiModelProperty(value = "辅料小时费率")
62
+    private java.math.BigDecimal auxiliaryHourRate;
63
+	/**其他小时费率*/
64
+	@Excel(name = "其他小时费率", width = 15)
65
+    @ApiModelProperty(value = "其他小时费率")
66
+    private java.math.BigDecimal otherHourRate;
67
+	/**生效日期*/
68
+	@Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd")
69
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
70
+    @DateTimeFormat(pattern="yyyy-MM-dd")
71
+    @ApiModelProperty(value = "生效日期")
72
+    private java.util.Date effectiveDate;
73
+	/**失效日期*/
74
+	@Excel(name = "失效日期", width = 15, format = "yyyy-MM-dd")
75
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
76
+    @DateTimeFormat(pattern="yyyy-MM-dd")
77
+    @ApiModelProperty(value = "失效日期")
78
+    private java.util.Date expirationDate;
79
+	/**维护人员*/
80
+	@Excel(name = "维护人员", width = 15)
81
+    @ApiModelProperty(value = "维护人员")
82
+    private java.lang.String guardian;
83
+	/**维护时间*/
84
+	@Excel(name = "维护时间", width = 15)
85
+    @ApiModelProperty(value = "维护时间")
86
+    private java.lang.String maintenanceTime;
87
+	/**预留字段1*/
88
+	@Excel(name = "预留字段1", width = 15)
89
+    @ApiModelProperty(value = "预留字段1")
90
+    private java.lang.String reserve1;
91
+	/**预留字段2*/
92
+	@Excel(name = "预留字段2", width = 15)
93
+    @ApiModelProperty(value = "预留字段2")
94
+    private java.math.BigDecimal reserve2;
95
+	/**主键*/
96
+	@TableId(type = IdType.ASSIGN_ID)
97
+    @ApiModelProperty(value = "主键")
98
+    private java.lang.String id;
99
+}

+ 14
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/mapper/HourRateMapper.java Целия файл

@@ -0,0 +1,14 @@
1
+package com.zzsmart.qomo.kn.cost.manage.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
5
+
6
+/**
7
+ * @Description: hour_rate
8
+ * @Author: jeecg-boot
9
+ * @Date:   2024-06-06
10
+ * @Version: V1.0
11
+ */
12
+public interface HourRateMapper extends BaseMapper<HourRate> {
13
+
14
+}

+ 5
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/mapper/xml/HourRateMapper.xml Целия файл

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.zzsmart.qomo.modules.demo..mapper.HourRateMapper">
4
+
5
+</mapper>

+ 15
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/service/IHourRateService.java Целия файл

@@ -0,0 +1,15 @@
1
+package com.zzsmart.qomo.kn.cost.manage.service;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
6
+
7
+/**
8
+ * @Description: hour_rate
9
+ * @Author: jeecg-boot
10
+ * @Date:   2024-06-06
11
+ * @Version: V1.0
12
+ */
13
+public interface IHourRateService extends IService<HourRate> {
14
+
15
+}

+ 19
- 0
qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/service/impl/HourRateServiceImpl.java Целия файл

@@ -0,0 +1,19 @@
1
+package com.zzsmart.qomo.kn.cost.manage.service.impl;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
6
+import com.zzsmart.qomo.kn.cost.manage.mapper.HourRateMapper;
7
+import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
8
+import org.springframework.stereotype.Service;
9
+
10
+/**
11
+ * @Description: hour_rate
12
+ * @Author: jeecg-boot
13
+ * @Date:   2024-06-06
14
+ * @Version: V1.0
15
+ */
16
+@Service
17
+public class HourRateServiceImpl extends ServiceImpl<HourRateMapper, HourRate> implements IHourRateService {
18
+
19
+}

+ 72
- 0
qomo-kn-cost-manage/src/test/java/com/zzsmart/qomo/kn/cost/manage/ApplicationTests.java Целия файл

@@ -0,0 +1,72 @@
1
+package com.zzsmart.qomo.kn.cost.manage;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.generator.config.OutputFile;
5
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
6
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
7
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
8
+import org.junit.Test;
9
+import org.springframework.boot.test.context.SpringBootTest;
10
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
11
+import java.sql.Types;
12
+import java.util.Collections;
13
+
14
+@SpringBootTest
15
+public class ApplicationTests {
16
+
17
+    /**
18
+     * 根据表名生成相应结构代码
19
+     * @param databaseName 数据库名
20
+     * @param tableName 表名
21
+     */
22
+    @Test
23
+    public static void Generation(String databaseName,String... tableName){
24
+        FastAutoGenerator.create("jdbc:mysql://localhost:3306/"+databaseName+"?&useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai","root","wsndqd857857")
25
+                .globalConfig(builder -> {
26
+                    builder.author("罗添煦")
27
+                            //启用swagger
28
+                            //.enableSwagger()
29
+                            //指定输出目录
30
+                            .outputDir(System.getProperty("user.dir")+"/src/main/java");
31
+                })
32
+                .packageConfig(builder -> {
33
+                    builder.entity("entity")//实体类包名
34
+                            .parent("com.ltx.mpcode")//父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
35
+                            .controller("controller")//控制层包名
36
+                            .mapper("dao")//mapper层包名
37
+                            //.other("dto")//生成dto目录 可不用
38
+                            .service("service")//service层包名
39
+                            .serviceImpl("service.impl")//service实现类包名
40
+                            //自定义mapper.xml文件输出目录
41
+                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml,System.getProperty("user.dir")+"/src/main/resources/mapper"));
42
+                })
43
+                .strategyConfig(builder -> {
44
+                    //设置要生成的表名
45
+                    builder.addInclude(tableName)
46
+                            .addInclude("cp_order_history")// 设置需要生成的表名
47
+                            //.addTablePrefix("sys_")//设置表前缀过滤
48
+                            .entityBuilder()
49
+                            .enableLombok()
50
+                            .enableChainModel()
51
+                            .naming(NamingStrategy.underline_to_camel)//数据表映射实体命名策略:默认下划线转驼峰underline_to_camel
52
+                            .columnNaming(NamingStrategy.underline_to_camel)//表字段映射实体属性命名规则:默认null,不指定按照naming执行
53
+                            .idType(IdType.AUTO)//添加全局主键类型
54
+                            .formatFileName("%s")//格式化实体名称,%s取消首字母I,
55
+                            .mapperBuilder()
56
+                            .enableMapperAnnotation()//开启mapper注解
57
+                            .enableBaseResultMap()//启用xml文件中的BaseResultMap 生成
58
+                            .enableBaseColumnList()//启用xml文件中的BaseColumnList
59
+                            .formatMapperFileName("%sMapper")//格式化Dao类名称
60
+                            .formatXmlFileName("%sMapper")//格式化xml文件名称
61
+                            .serviceBuilder()
62
+                            .formatServiceFileName("%sService")//格式化 service 接口文件名称
63
+                            .formatServiceImplFileName("%sServiceImpl")//格式化 service 接口文件名称
64
+                            .controllerBuilder()
65
+                            .enableRestStyle();
66
+                })
67
+                // 使用Freemarker引擎模板,默认的是Velocity引擎模板
68
+                .templateEngine(new FreemarkerTemplateEngine())
69
+                .execute();
70
+
71
+    }
72
+}