微信API 账单处理

This commit is contained in:
limqhz
2023-02-07 16:37:33 +08:00
parent 61697eb17d
commit 189a085f0b
11 changed files with 264 additions and 14 deletions

View File

@@ -0,0 +1,67 @@
package com.quinn.common.wx;
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.util.Date;
/**
* <p>
*
* </p>
*
* @author limqsh
* @since 2023-02-07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("qn_acc_bill")
@ApiModel(value="AccBill对象", description="")
public class AccBillDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "自增id")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
@ApiModelProperty(value = "金额")
private Double money;
@ApiModelProperty(value = "余额")
private Double balance;
@ApiModelProperty(value = "账单类型")
private AccBillType billType;
@ApiModelProperty(value = "转账&还款需要")
private Integer fromAccount;
private String fromAccountName;
@ApiModelProperty(value = "账户分类ID")
private Integer account;
private String accountName;
@ApiModelProperty(value = "-1 转账 -2 还款")
private Integer moneyType;
private String moneyName;
private String moneyIcon;
private Date date;
private String remark;
}

View File

@@ -0,0 +1,20 @@
package com.quinn.common.wx;
public enum AccBillType {
/**
* 收入
*/
INCOME,
/**
* 支出
*/
EXPEND,
/**
* 转账
*/
TRANSFER,
/**
* 还款
*/
REPAYMENT
}

View File

@@ -16,5 +16,9 @@ public enum AccSettingType {
/**
* 负债账户
*/
OWE_SETTING
OWE_SETTING,
/**
* 系统属性
*/
OTHER
}

View File

@@ -0,0 +1,95 @@
package com.quinn.controller.wx;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.dto.res.ResponseDTO;
import com.quinn.pojo.AccBill;
import com.quinn.service.AccBillService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author limqsh
* @since 2022-05-01
*/
@RestController
@RequestMapping("/wx")
public class WxBillController extends BaseWxController{
@Resource
AccBillService accBillService;
@PostMapping("user/bills")
public ResponseDTO getBills(HttpServletRequest request){
List<AccBill> accBills = accBillService.list(new QueryWrapper<AccBill>().eq("user_id", getLoginUserId(request)));
return ResponseDTO.ok().setData(accBills);
}
@PostMapping("user/bills/today")
public ResponseDTO getTodayBills(HttpServletRequest request){
List<AccBillDTO> accBills = accBillService.listAccToday(getLoginUserId(request));
return ResponseDTO.ok().setData(accBills);
}
/**
* 本年度支出统计
* @return
*/
@PostMapping("user/bill/{id}")
public ResponseDTO getBill(@PathVariable("id") Integer id){
AccBillDTO accBill = accBillService.getAccBill(id);
return ResponseDTO.ok().setData(accBill);
}
/**
* 本年度支出统计
* @return
*/
@PostMapping("user/bill/del/{id}")
public ResponseDTO deleteBill(@PathVariable("id") Integer id){
accBillService.removeById(id);
return ResponseDTO.ok();
}
/**
* 本年度支出统计
* @param request
* @return
*/
@PostMapping("user/bill/edit")
public ResponseDTO editBill(HttpServletRequest request,AccBill accBill){
if (accBill.getId() != -1){
AccBill byId = accBillService.getById(accBill.getId());
if (byId != null){
byId.setId(accBill.getId());
byId.setName(accBill.getName());
byId.setBillType(accBill.getBillType());
byId.setMoneyType(accBill.getMoneyType());
byId.setFromAccount(accBill.getFromAccount());
byId.setAccount(accBill.getAccount());
byId.setDate(accBill.getDate());
byId.setMoney(accBill.getMoney());
byId.setRemark(accBill.getRemark());
}
accBillService.updateById(byId);
}else {
accBill.setGmtCreate(new Date());
accBill.setUserId(getLoginUserId(request));
accBillService.save(accBill);
}
return ResponseDTO.ok();
}
}

View File

@@ -51,7 +51,7 @@ public class CodeGenerator {
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("qn_acc_setting");//设置要映射的表名
strategy.setInclude("qn_acc_bill");//设置要映射的表名
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix("qn_");//设置表前缀不生成

View File

@@ -1,16 +1,22 @@
package com.quinn.mapper;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.pojo.AccBill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Date;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author limqsh
* @since 2023-02-02
* @since 2023-02-07
*/
public interface AccBillMapper extends BaseMapper<AccBill> {
List<AccBillDTO> listAccToday(String userId, Date date);
AccBillDTO getAccBill(Integer sid);
}

View File

@@ -2,4 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.quinn.mapper.AccBillMapper">
<select id="listAccToday" resultType="com.quinn.common.wx.AccBillDTO">
select id,name,bill_type "billType",money,balance,
from_account "fromAccount",(select name from qn_acc_setting b where b.id = a.from_account) "fromAccountName",
account "account",(select name from qn_acc_setting b where b.id = a.account) "accountName",
a.money_type "moneyType",
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
a.date
from qn_acc_bill a where a.user_id = #{userId} and a.date = #{date}
</select>
<select id="getAccBill" resultType="com.quinn.common.wx.AccBillDTO">
select id,name,bill_type "billType",money,balance,
from_account "fromAccount",(select name from qn_acc_setting b where b.id = a.from_account) "fromAccountName",
account "account",(select name from qn_acc_setting b where b.id = a.account) "accountName",
a.money_type "moneyType",
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
a.date,a.remark
from qn_acc_bill a where a.id = #{sid}
</select>
</mapper>

View File

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import com.quinn.common.wx.AccBillType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -13,11 +15,11 @@ import lombok.experimental.Accessors;
/**
* <p>
*
*
* </p>
*
* @author limqsh
* @since 2023-02-02
* @since 2023-02-07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -32,16 +34,24 @@ public class AccBill implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
private String userId;
@ApiModelProperty(value = "金额")
private Double money;
@ApiModelProperty(value = "账单分类ID")
private Integer billType;
@ApiModelProperty(value = "账单类型")
private AccBillType billType;
@ApiModelProperty(value = "转账&还款需要")
private Integer fromAccount;
@ApiModelProperty(value = "账户分类ID")
private Integer accountType;
private Integer account;
@ApiModelProperty(value = "-1 转账 -2 还款")
private Integer moneyType;
private Date date;

View File

@@ -1,16 +1,21 @@
package com.quinn.service;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.pojo.AccBill;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Date;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author limqsh
* @since 2023-02-02
* @since 2023-02-07
*/
public interface AccBillService extends IService<AccBill> {
List<AccBillDTO> listAccToday(String userId);
AccBillDTO getAccBill(Integer sid);
}

View File

@@ -1,20 +1,37 @@
package com.quinn.service.impl;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.pojo.AccBill;
import com.quinn.mapper.AccBillMapper;
import com.quinn.service.AccBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author limqsh
* @since 2023-02-02
* @since 2023-02-07
*/
@Service
public class AccBillServiceImpl extends ServiceImpl<AccBillMapper, AccBill> implements AccBillService {
@Resource
AccBillMapper accBillMapper;
@Override
public List<AccBillDTO> listAccToday(String userId) {
return accBillMapper.listAccToday(userId,new Date());
}
@Override
public AccBillDTO getAccBill(Integer sid) {
return accBillMapper.getAccBill(sid);
}
}

View File

@@ -14,12 +14,16 @@ CREATE TABLE `qn_acc_setting` (
DROP TABLE IF EXISTS `qn_acc_bill`;
CREATE TABLE `qn_acc_bill` (
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`name` varchar(255) NOT NULL,
`user_id` varchar(200) NOT NULL,
`money` double(9,2) NOT NULL COMMENT '金额',
`bill_type` int(10) DEFAULT NULL COMMENT '账单分类ID',
`account_type` int(10) NOT NULL COMMENT '账户分类ID',
`bill_type` varchar(20) DEFAULT NULL COMMENT '账单类型',
`from_account` int(10) DEFAULT NULL COMMENT '转账&还款需要',
`account` int(10) DEFAULT NULL COMMENT '账户分类ID',
`money_type` int(10) DEFAULT NULL COMMENT '-1 转账 -2 还款',
`money_type_icon` varchar(255) DEFAULT NULL,
`date` datetime DEFAULT NULL,
`remark` varchar(500) DEFAULT NULL,
`user_id` varchar(200) DEFAULT NULL,
`gmt_create` datetime NOT NULL COMMENT '收藏创建时间',
PRIMARY KEY (`id`)
);