【WX】 账户调整,账单查询

This commit is contained in:
limqhz
2023-02-08 16:56:45 +08:00
parent 34149bfba4
commit db4d3f4b71
13 changed files with 168 additions and 11 deletions

View File

@@ -33,8 +33,6 @@ public class AccBillDTO implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
@ApiModelProperty(value = "金额")
private Double money;

View File

@@ -0,0 +1,11 @@
package com.quinn.common.wx;
import lombok.Data;
import java.io.Serializable;
@Data
public class EditBill implements Serializable {
private Integer sid;
private Double balance;
}

View File

@@ -0,0 +1,11 @@
package com.quinn.common.wx;
import lombok.Data;
import java.io.Serializable;
@Data
public class ListBillByAccount implements Serializable {
private Integer sid;
private String dateRange;
}

View File

@@ -2,6 +2,7 @@ package com.quinn.controller.wx;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.common.wx.ListBillByAccount;
import com.quinn.dto.res.ResponseDTO;
import com.quinn.pojo.AccBill;
import com.quinn.service.AccBillService;
@@ -42,6 +43,12 @@ public class WxBillController extends BaseWxController{
return ResponseDTO.ok().setData(accBills);
}
@PostMapping("user/bills/account")
public ResponseDTO getBillsByBills(HttpServletRequest request, ListBillByAccount listBillByAccount){
List<AccBillDTO> accBills = accBillService.listBillByAccount(getLoginUserId(request),listBillByAccount.getSid(),listBillByAccount.getDateRange());
return ResponseDTO.ok().setData(accBills);
}
/**
* 本年度支出统计
* @return

View File

@@ -2,6 +2,7 @@ package com.quinn.controller.wx;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quinn.common.wx.AccSettingType;
import com.quinn.common.wx.EditBill;
import com.quinn.common.wx.YearAmnt;
import com.quinn.dto.req.SearchPage;
import com.quinn.dto.res.ResponseDTO;
@@ -37,8 +38,8 @@ public class WxSettingsController extends BaseWxController{
private AccSettingService accSettingService;
@PostMapping("user/login")
public ResponseDTO userIndexBlog(String openId){
return ResponseDTO.ok().setData(accountCheckService.getUserId(openId));
public ResponseDTO userIndexBlog(String wxCode){
return ResponseDTO.ok().setData(accountCheckService.getUserId(wxCode));
}
@PostMapping("user/settings")
@@ -71,6 +72,18 @@ public class WxSettingsController extends BaseWxController{
accSettingService.removeById(id);
return ResponseDTO.ok();
}
/**
* 本年度支出统计
* @return
*/
@PostMapping("/user/settings/edit/bill")
public ResponseDTO editBill(EditBill editBill){
AccSetting accSetting = new AccSetting();
accSetting.setId(editBill.getSid());
accSetting.setBalance(editBill.getBalance());
accSettingService.updateById(accSetting);
return ResponseDTO.ok();
}
/**
* 本年度支出统计

View File

@@ -19,4 +19,12 @@ public interface AccBillMapper extends BaseMapper<AccBill> {
List<AccBillDTO> listAccToday(String userId, String date);
AccBillDTO getAccBill(Integer sid);
List<AccBillDTO> listBillByAccount(String userId, Integer accountId, String startDate, String endDate);
List<AccBillDTO> listBillByDate(String userId, String startDate, String endDate);
List<AccBillDTO> listIncomeBillOrder(String userId, String startDate, String endDate);
List<AccBillDTO> listExpendBillOrder(String userId, String startDate, String endDate);
}

View File

@@ -3,24 +3,72 @@
<mapper namespace="com.quinn.mapper.AccBillMapper">
<select id="listAccToday" resultType="com.quinn.common.wx.AccBillDTO">
select id,name,bill_type "billType",money,balance,
select id,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
DATE_FORMAT(a.date,'%Y-%m-%d') 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,
<select id="listBillByAccount" resultType="com.quinn.common.wx.AccBillDTO">
select id,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
DATE_FORMAT(a.date,'%Y-%m-%d') date
from qn_acc_bill a where a.user_id = #{userId} and a.account = #{accountId} and a.date <![CDATA[ >= ]]> #{startDate} a.date <![CDATA[ <= ]]> #{startDate}
order by a.date desc
</select>
<select id="listBillByDate" resultType="com.quinn.common.wx.AccBillDTO">
select id,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",
DATE_FORMAT(a.date,'%Y-%m-%d') date
from qn_acc_bill a where a.user_id = #{userId} and a.date <![CDATA[ >= ]]> #{startDate} a.date <![CDATA[ <= ]]> #{startDate}
order by a.date desc
</select>
<select id="listIncomeBillOrder" resultType="com.quinn.common.wx.AccBillDTO">
select id,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",
DATE_FORMAT(a.date,'%Y-%m-%d') date
from qn_acc_bill a where a.user_id = #{userId} and a.bill_type='INCOME' and a.date <![CDATA[ >= ]]> #{startDate} a.date <![CDATA[ <= ]]> #{startDate}
order by a.money desc
</select>
<select id="listExpendBillOrder" resultType="com.quinn.common.wx.AccBillDTO">
select id,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",
DATE_FORMAT(a.date,'%Y-%m-%d') date
from qn_acc_bill a where a.user_id = #{userId} and a.bill_type='EXPEND' and a.date <![CDATA[ >= ]]> #{startDate} a.date <![CDATA[ <= ]]> #{startDate}
order by a.money desc
</select>
<select id="getAccBill" resultType="com.quinn.common.wx.AccBillDTO">
select id,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",
DATE_FORMAT(a.date,'%Y-%m-%d') date,a.remark
from qn_acc_bill a where a.id = #{sid}
</select>

View File

@@ -41,6 +41,9 @@ public class AccBill implements Serializable {
@ApiModelProperty(value = "金额")
private Double money;
@ApiModelProperty(value = "余额")
private Double balance;
@ApiModelProperty(value = "账单类型")
private AccBillType billType;

View File

@@ -43,6 +43,9 @@ public class AccSetting implements Serializable {
@ApiModelProperty(value = "收藏者id")
private String icon;
@ApiModelProperty(value = "余额")
private Double balance;
private String userId;
@ApiModelProperty(value = "收藏创建时间")

View File

@@ -17,5 +17,9 @@ import java.util.List;
*/
public interface AccBillService extends IService<AccBill> {
List<AccBillDTO> listAccToday(String userId);
List<AccBillDTO> listBillByAccount(String userId,Integer accountId,String rangeDate);
List<AccBillDTO> listBillByDate(String userId,String rangeDate);
List<AccBillDTO> listIncomeBillOrder(String userId,String rangeDate);
List<AccBillDTO> listExpendBillOrder(String userId,String rangeDate);
AccBillDTO getAccBill(Integer sid);
}

View File

@@ -31,6 +31,34 @@ public class AccBillServiceImpl extends ServiceImpl<AccBillMapper, AccBill> impl
return accBillMapper.listAccToday(userId, QuinnUtils.getViewStrFromDate(new Date()));
}
@Override
public List<AccBillDTO> listBillByAccount(String userId,Integer accountId,String rangeDate) {
String startDate = rangeDate.substring(0,rangeDate.indexOf(""));
String endDate = rangeDate.substring(rangeDate.indexOf("")+1);
return accBillMapper.listBillByAccount(userId, accountId,startDate,endDate);
}
@Override
public List<AccBillDTO> listBillByDate(String userId, String rangeDate) {
String startDate = rangeDate + "-01";
String endDate = rangeDate + "-31";
return accBillMapper.listBillByDate(userId,startDate,endDate);
}
@Override
public List<AccBillDTO> listIncomeBillOrder(String userId, String rangeDate) {
String startDate = rangeDate + "-01";
String endDate = rangeDate + "-31";
return accBillMapper.listIncomeBillOrder(userId,startDate,endDate);
}
@Override
public List<AccBillDTO> listExpendBillOrder(String userId, String rangeDate) {
String startDate = rangeDate + "-01";
String endDate = rangeDate + "-31";
return accBillMapper.listExpendBillOrder(userId,startDate,endDate);
}
@Override
public AccBillDTO getAccBill(Integer sid) {
return accBillMapper.getAccBill(sid);

View File

@@ -5,20 +5,43 @@ import com.quinn.intergration.AttrIcon;
import com.quinn.mapper.UserMapper;
import com.quinn.pojo.User;
import com.quinn.service.AccountCheckService;
import com.quinn.utils.HttpUtils;
import com.quinn.utils.JsonUtils;
import com.quinn.utils.QuinnUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Component
public class AccountCheckServiceImpl implements AccountCheckService {
@Resource
UserMapper userMapper;
private final String WX_OPENID_URL = "https://api.weixin.qq.com/sns/jscode2session";
private final String WX_APP_ID = "wxb1f499f0a173865b";
private final String WX_APP_SECRET = "833eefaf9206337d6c2d643f94baef7b";
private final String GRANT_TYPE = "authorization_code";
@Override
public String getUserId(String openid) {
public String getUserId(String code) {
// let param = {
// appid:'wxb1f499f0a173865b',
// secret:'833eefaf9206337d6c2d643f94baef7b',
// js_code: res.code,
// grant_type: 'authorization_code'
// };
Map param = new HashMap<>();
param.put("appid",WX_APP_ID);
param.put("secret",WX_APP_SECRET);
param.put("js_code",code);
param.put("GRANT_TYPE",GRANT_TYPE);
String result = HttpUtils.doPost(WX_OPENID_URL, param);
String openid = (String) JsonUtils.decode(result,Map.class).get("openid");
String uid = userMapper.getUserByOpenid(openid);
if (StringUtils.isEmpty(uid)){
// 没有这个用户,需要构建用户对象

View File

@@ -7,6 +7,7 @@ CREATE TABLE `qn_acc_setting` (
`name` varchar(200) NOT NULL COMMENT '名称',
`setting_type` varchar(20) DEFAULT NULL COMMENT '设置类型',
`icon` varchar(200) NOT NULL COMMENT '收藏者id',
`balance` double(9,2) NOT NULL DEFAULT 0 COMMENT '余额',
`user_id` varchar(200) DEFAULT NULL,
`gmt_create` datetime NOT NULL COMMENT '收藏创建时间',
PRIMARY KEY (`id`)
@@ -14,7 +15,6 @@ 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 DEFAULT 0 COMMENT '金额',
`balance` double(9,2) NOT NULL DEFAULT 0 COMMENT '余额',