Browse Source

后端框架第二版接口

Houduan1
huangqizhen 6 months ago
parent
commit
398c44843d
  1. 2
      demo/audit/pom.xml
  2. 2
      demo/audit/src/main/java/com/example/audit/AuditApplication.java
  3. 9
      demo/audit/src/main/java/com/example/audit/mapper/AuditMapper.java
  4. 1
      demo/commons/src/main/java/com/example/commons/domain/entity/Audit.java
  5. 5
      demo/commons/src/main/java/com/example/commons/domain/entity/Detail.java
  6. 1
      demo/commons/src/main/java/com/example/commons/domain/vo/ConsumeDetail.java
  7. 1
      demo/commons/src/main/java/com/example/commons/domain/vo/RechargeVo.java
  8. 6
      demo/commons/src/main/java/com/example/commons/sevice/ProductService.java
  9. 2
      demo/commons/src/main/java/com/example/commons/sevice/RechargeService.java
  10. 12
      demo/recharge/pom.xml
  11. 2
      demo/recharge/src/main/java/com/example/recharge/RechargeApplication.java
  12. 4
      demo/recharge/src/main/java/com/example/recharge/mapper/ActivityMapper.java
  13. 7
      demo/recharge/src/main/java/com/example/recharge/mapper/RechargeMapper.java
  14. 71
      demo/recharge/src/main/java/com/example/recharge/service/RechargeServiceImpl.java
  15. 2
      demo/statistics/src/main/java/com/example/statistics/StatisticsApplication.java
  16. 22
      demo/statistics/src/main/java/com/example/statistics/mapper/DetailMapper.java
  17. 2
      demo/statistics/src/main/java/com/example/statistics/service/DetailServiceImpl.java
  18. 25
      demo/user/src/main/java/com/example/user/controller/ProductController.java
  19. 15
      demo/user/src/main/java/com/example/user/mapper/ProductMapper.java
  20. 16
      demo/user/src/main/java/com/example/user/service/ProductServiceImpl.java

2
demo/audit/pom.xml

@ -5,7 +5,7 @@
<groupId>com.example</groupId> <groupId>com.example</groupId>
<artifactId>audit</artifactId> <artifactId>audit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name>audit</name> <name>audit</name>
<description>audit</description> <description>audit</description>

2
demo/audit/src/main/java/com/example/audit/AuditApplication.java

@ -1,9 +1,11 @@
package com.example.audit; package com.example.audit;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan("com.example.**.mapper")
public class AuditApplication { public class AuditApplication {
public static void main(String[] args) { public static void main(String[] args) {

9
demo/audit/src/main/java/com/example/audit/mapper/AuditMapper.java

@ -14,15 +14,18 @@ public interface AuditMapper {
@Insert({ @Insert({
"INSERT INTO audit", "INSERT INTO audit",
"(jwcode,recharge_id,refund_id,name,status,auditFlag)",
"(jwcode,recharge_id,refund_id,admin_id,reson,detail_id,status,audit_flag)",
"values", "values",
"(#{jwcode},#{rechargeId},#{refundId},#{name},0,1)"
"(#{jwcode},#{rechargeId},#{refundId},#{adminId},#{reson},#{detailId},0,1)"
}) })
int insert(Audit audit); int insert(Audit audit);
@Update({ @Update({
"<script>", "<script>",
"update audit", "update audit",
"<set>", "<set>",
"<if test='adminId!=null'>admin_id=#{adminId},</if>",
"<if test='rechargeId!=null'>recharge_id=#{rechargeId},</if>",
"<if test='status!=null'>status=#{status},</if>", "<if test='status!=null'>status=#{status},</if>",
"<if test='reson!=null and reson.length>0'>`reson`=#{reson}</if>", "<if test='reson!=null and reson.length>0'>`reson`=#{reson}</if>",
"</set>", "</set>",
@ -47,7 +50,7 @@ public interface AuditMapper {
List<Audit> select(Audit Audit); List<Audit> select(Audit Audit);
@Select({ @Select({
"<script>", "<script>",
"select detail.*,audit.status,audit.reson,admin.*,user.name as user from detail",
"select detail.*,audit.status,audit.reson,audit.audit_id,admin.*,user.name as user from detail",
"inner join audit on detail.detail_id = audit.refund_id", "inner join audit on detail.detail_id = audit.refund_id",
"inner join `admin` on detail.admin_id = `admin`.admin_id", "inner join `admin` on detail.admin_id = `admin`.admin_id",
"inner join `user` on detail.jwcode = user.jwcode", "inner join `user` on detail.jwcode = user.jwcode",

1
demo/commons/src/main/java/com/example/commons/domain/entity/Audit.java

@ -23,4 +23,5 @@ public class Audit {
private Date startDate; private Date startDate;
private Date endDate; private Date endDate;
private String reson; private String reson;
private Integer detailId;
} }

5
demo/commons/src/main/java/com/example/commons/domain/entity/Detail.java

@ -16,7 +16,7 @@ public class Detail {
private String area; private String area;
private Integer activityId; private Integer activityId;
private String rechargeWay; private String rechargeWay;
private String goods;
private Integer productId;
private String consumePlatform; private String consumePlatform;
private String consumeType; private String consumeType;
private String refundType; private String refundType;
@ -37,4 +37,7 @@ public class Detail {
private Date endDate; private Date endDate;
private Date startDate; private Date startDate;
private String uname;
} }

1
demo/commons/src/main/java/com/example/commons/domain/vo/ConsumeDetail.java

@ -37,5 +37,6 @@ public class ConsumeDetail {
private String user; private String user;
private Date startDate; private Date startDate;
private Date endDate; private Date endDate;
private Integer auditId;
} }

1
demo/commons/src/main/java/com/example/commons/domain/vo/RechargeVo.java

@ -36,4 +36,5 @@ public class RechargeVo {
private Integer status; private Integer status;
private String reson; private String reson;
private String name; private String name;
private Integer auditId;
} }

6
demo/commons/src/main/java/com/example/commons/sevice/ProductService.java

@ -1,5 +1,9 @@
package com.example.commons.sevice; package com.example.commons.sevice;
public interface ProductService {
import com.example.commons.domain.entity.Product;
import java.util.List;
public interface ProductService {
List<Product> findAll(Product product);
} }

2
demo/commons/src/main/java/com/example/commons/sevice/RechargeService.java

@ -3,10 +3,12 @@ package com.example.commons.sevice;
import com.example.commons.domain.entity.Recharge; import com.example.commons.domain.entity.Recharge;
import com.example.commons.domain.vo.RechargeVo; import com.example.commons.domain.vo.RechargeVo;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
public interface RechargeService { public interface RechargeService {
@Transactional
int add(Recharge recharge) throws Exception; int add(Recharge recharge) throws Exception;
int edit(Recharge recharge) throws Exception; int edit(Recharge recharge) throws Exception;

12
demo/recharge/pom.xml

@ -23,6 +23,18 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.example</groupId>
<artifactId>statistics</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>audit</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId> <groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version> <version>3.0.3</version>

2
demo/recharge/src/main/java/com/example/recharge/RechargeApplication.java

@ -1,9 +1,11 @@
package com.example.recharge; package com.example.recharge;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan("com.example.**.mapper")
public class RechargeApplication { public class RechargeApplication {
public static void main(String[] args) { public static void main(String[] args) {

4
demo/recharge/src/main/java/com/example/recharge/mapper/ActivityMapper.java

@ -11,9 +11,9 @@ public interface ActivityMapper {
//增加活动信息 //增加活动信息
@Insert({"insert into activity", @Insert({"insert into activity",
"(admin_id,dept,start_time,end_time,recharge_ratio,activity_name,activity_flag,create_time) " ,
"(admin_id,start_time,end_time,recharge_ratio,activity_name,activity_flag,create_time) " ,
"values", "values",
"(#{adminId},#{dept},#{startTime},#{endTime},#{rechargeRatio},#{activityName},1,now())"
"(#{adminId},#{startTime},#{endTime},#{rechargeRatio},#{activityName},1,now())"
}) })
@Options(useGeneratedKeys = true,keyColumn = "activity_id",keyProperty = "activityId") @Options(useGeneratedKeys = true,keyColumn = "activity_id",keyProperty = "activityId")
int add(Activity activity); int add(Activity activity);

7
demo/recharge/src/main/java/com/example/recharge/mapper/RechargeMapper.java

@ -11,10 +11,11 @@ public interface RechargeMapper {
@Insert({ @Insert({
"INSERT INTO recharge", "INSERT INTO recharge",
"(jwcode,activity_id,paid_gold,free_gold,recharge_gold,pay_way,recharge_way,recharge_time,recharge_voucher,admin_id,area,remark,flag)",
"(jwcode,activity_id,paid_gold,free_gold,recharge_gold,pay_way,recharge_way,recharge_time,recharge_voucher,admin_id,remark,flag)",
"values ", "values ",
"(#{jwcode},#{activityId},#{paidGold},#{freeGold},#{rechargeGold},#{payWay},#{rechargeWay},#{rechargeTime},#{rechargeVoucher},#{adminId},#{area},#{remark},1)"
"(#{jwcode},#{activityId},#{paidGold},#{freeGold},#{rechargeGold},#{payWay},#{rechargeWay},#{rechargeTime},#{rechargeVoucher},#{adminId},#{remark},1)"
}) })
@Options(useGeneratedKeys = true,keyColumn = "recharge_id",keyProperty = "rechargeId")
int insert(Recharge recharge); int insert(Recharge recharge);
@Update({ @Update({
@ -30,7 +31,7 @@ public interface RechargeMapper {
@Select({ @Select({
"<script>", "<script>",
"SELECT DISTINCT user.`name` as user_name , recharge.*,activity.activity_name,audit.`status`,audit.reson, admin.name,admin.area FROM recharge",
"SELECT DISTINCT user.`name` as user_name , recharge.*,activity.activity_name,audit.`status`,audit.audit_id,audit.reson, admin.name,admin.area FROM recharge",
"INNER JOIN audit ON recharge.recharge_id = audit.recharge_id", "INNER JOIN audit ON recharge.recharge_id = audit.recharge_id",
"INNER JOIN `user` ON recharge.jwcode = `user`.jwcode", "INNER JOIN `user` ON recharge.jwcode = `user`.jwcode",
"INNER JOIN activity on recharge.activity_id = activity.activity_id", "INNER JOIN activity on recharge.activity_id = activity.activity_id",

71
demo/recharge/src/main/java/com/example/recharge/service/RechargeServiceImpl.java

@ -1,25 +1,90 @@
package com.example.recharge.service; package com.example.recharge.service;
import com.example.audit.mapper.AuditMapper;
import com.example.commons.domain.entity.Audit;
import com.example.commons.domain.entity.Detail;
import com.example.commons.domain.entity.Recharge; import com.example.commons.domain.entity.Recharge;
import com.example.commons.domain.vo.RechargeVo; import com.example.commons.domain.vo.RechargeVo;
import com.example.commons.sevice.RechargeService; import com.example.commons.sevice.RechargeService;
import com.example.recharge.mapper.RechargeMapper; import com.example.recharge.mapper.RechargeMapper;
import com.example.statistics.mapper.DetailMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class RechargeServiceImpl implements RechargeService { public class RechargeServiceImpl implements RechargeService {
private final RechargeMapper rechargeMapper;
@Autowired
private RechargeMapper rechargeMapper;
@Autowired
private AuditMapper auditMapper;
@Autowired
private DetailMapper detailMapper;
@Override @Override
@Transactional
public int add(Recharge recharge) throws Exception { public int add(Recharge recharge) throws Exception {
return rechargeMapper.insert(recharge);
// return rechargeMapper.insert(recharge);
int result = rechargeMapper.insert(recharge);
if (result != 1) {
throw new Exception("Failed to insert recharge data");
}
System.out.println(recharge.getRechargeId());
int rechargeId = recharge.getRechargeId();
Integer jwCode= Integer.valueOf(recharge.getJwcode());
String JwCode = recharge.getJwcode();
int activityId = recharge.getActivityId();
double paidGold =recharge.getPaidGold();
double freeGold =recharge.getFreeGold();
double rechargeGold =recharge.getRechargeGold();
String rechargeWay =recharge.getRechargeWay();
String remark =recharge.getRemark();
int adminId =recharge.getAdminId();
Detail detail = new Detail();
detail.setJwcode(JwCode);
detail.setActivityId(activityId);
detail.setTaskCoin(paidGold);
detail.setRechargeCoin(rechargeGold);
detail.setFreeCoin(freeGold);
detail.setRechargeWay(rechargeWay);
detail.setRemark(remark);
detail.setAdminId(adminId);
System.out.println(detail);
result = detailMapper.add(detail);
if (result != 1) {
throw new Exception("Failed to insert another entity");
}
int detailId = detail.getDetailId();
System.out.println(detailId);
Audit audit = new Audit();
audit.setRechargeId(rechargeId);
audit.setJwcode(jwCode);
audit.setDetailId(detailId);
System.out.println(audit);
result = auditMapper.insert(audit);
if (result != 1) {
throw new Exception("Failed to insert another entity");
}
return result;
} }
@Override @Override

2
demo/statistics/src/main/java/com/example/statistics/StatisticsApplication.java

@ -1,9 +1,11 @@
package com.example.statistics; package com.example.statistics;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan("com.example.**.mapper")
public class StatisticsApplication { public class StatisticsApplication {
public static void main(String[] args) { public static void main(String[] args) {

22
demo/statistics/src/main/java/com/example/statistics/mapper/DetailMapper.java

@ -3,6 +3,7 @@ package com.example.statistics.mapper;
import com.example.commons.domain.entity.Detail; import com.example.commons.domain.entity.Detail;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -12,13 +13,14 @@ public interface DetailMapper {
@Insert({ @Insert({
"insert into detail", "insert into detail",
"(jwcode,area,activity_id,recharge_way,product_id,consume_platform,consume_type,refund_type,refund_goods," +
"cntact_id,remark,recharge_coin,free_coin,task_coin,admin_id,update_type,detail_flag,create_time)",
"(jwcode,activity_id,recharge_way,product_id,consume_platform,consume_type,refund_type,refund_goods," +
"contact_id,remark,recharge_coin,free_coin,task_coin,admin_id,update_type,detail_flag,create_time)",
"values ", "values ",
"(#{jwcode},#{area},#{activityId},#{rechargeId},#{productId},#{area},#{consumePlatform},#{consumeType},#{refundType}" +
",#{refundGoods},#{cntactId},#{remark},#{rechargeCoin}" +
",#{freeCoin},#{taskCoin},#{adminId},#{updateType},#{detailFlag},#{createTime}",
"(#{jwcode},#{activityId},#{rechargeWay},#{productId},#{consumePlatform},#{consumeType},#{refundType}" +
",#{refundGoods},#{contactId},#{remark},#{rechargeCoin}" +
",#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now())"
}) })
@Options(useGeneratedKeys = true,keyColumn = "detail_id",keyProperty = "detailId")
int add(Detail detail); int add(Detail detail);
@Select({ @Select({
"SELECT * from detail where detail =#{detail}" "SELECT * from detail where detail =#{detail}"
@ -26,13 +28,15 @@ public interface DetailMapper {
Detail selectById(Integer id); Detail selectById(Integer id);
@Select({ @Select({
"<script>", "<script>",
"select detail.*,admin.name,admin.area from detail",
"select detail.*,admin.name,admin.area,user.name as uname,audit.status from detail",
"inner join `admin` on detail.admin_id = `admin`.admin_id", "inner join `admin` on detail.admin_id = `admin`.admin_id",
"inner join `user` on detail.jwcode = `user`.jwcode", "inner join `user` on detail.jwcode = `user`.jwcode",
"left join audit on detail.detail_id=audit.detail_id",
"<where>", "<where>",
"<if test='jwcode!=null'>and jwcode like concat('%',#{jwcode},'%')</if>",
"<if test='updateType!=null and updateType>0'>and update_type=#{updateType}</if>",
"<if test='startDate != null and endDate != null'>AND recharge.create_time BETWEEN #{startDate} AND #{endDate}</if>",
"(status is null or status='1')",
"<if test='jwcode!=null and jwcode.length>0'>and detail.jwcode=#{jwcode}</if>",
"<if test='updateType!=null and updateType.length>0'>and update_type=#{updateType}</if>",
"<if test='startDate != null and endDate != null'>AND detail.create_time BETWEEN #{startDate} AND #{endDate}</if>",
"</where>", "</where>",
"</script>" "</script>"

2
demo/statistics/src/main/java/com/example/statistics/service/DetailServiceImpl.java

@ -37,7 +37,7 @@ public class DetailServiceImpl implements DetailService {
@Override @Override
public List<Detail> getAllDetail(Detail detail) { public List<Detail> getAllDetail(Detail detail) {
return List.of();
return detailMapper.select(detail);
} }

25
demo/user/src/main/java/com/example/user/controller/ProductController.java

@ -0,0 +1,25 @@
package com.example.user.controller;
import com.example.commons.domain.entity.Product;
import com.example.commons.domain.entity.User;
import com.example.commons.domain.vo.Result;
import com.example.commons.sevice.ProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@RestController
@RequestMapping("/product")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class ProductController {
private final ProductService productService;
@PostMapping
public Result Product(@RequestBody Product product){
return Result.success(productService.findAll(product));
}
}

15
demo/user/src/main/java/com/example/user/mapper/ProductMapper.java

@ -0,0 +1,15 @@
package com.example.user.mapper;
import com.example.commons.domain.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface ProductMapper {
@Select({
"select * from product"
})
public List<Product> findAll(Product product);
}

16
demo/user/src/main/java/com/example/user/service/ProductServiceImpl.java

@ -1,5 +1,19 @@
package com.example.user.service; package com.example.user.service;
public class ProductServiceImpl {
import com.example.commons.domain.entity.Product;
import com.example.commons.sevice.ProductService;
import com.example.user.mapper.ProductMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ProductServiceImpl implements ProductService {
private final ProductMapper productMapper;
@Override
public List<Product> findAll(Product product) {
return productMapper.findAll(product);
}
} }
Loading…
Cancel
Save