微信API 账单查询

This commit is contained in:
2023-02-08 21:24:06 +08:00
parent db4d3f4b71
commit 56c9766034
7 changed files with 73 additions and 6 deletions

View File

@@ -2,10 +2,13 @@ package com.quinn.controller.wx;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quinn.common.wx.AccBillDTO;
import com.quinn.common.wx.AccBillType;
import com.quinn.common.wx.ListBillByAccount;
import com.quinn.dto.res.ResponseDTO;
import com.quinn.pojo.AccBill;
import com.quinn.pojo.AccSetting;
import com.quinn.service.AccBillService;
import com.quinn.service.AccSettingService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -14,7 +17,10 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
@@ -30,6 +36,8 @@ public class WxBillController extends BaseWxController{
@Resource
AccBillService accBillService;
@Resource
AccSettingService accSettingService;
@PostMapping("user/bills")
public ResponseDTO getBills(HttpServletRequest request){
@@ -46,7 +54,32 @@ public class WxBillController extends BaseWxController{
@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);
double expendBalance = 0;
double incomeBalance = 0;
List<AccBillDTO> payList = accBills.stream().filter(x -> {
AccBillType billType = x.getBillType();
return AccBillType.EXPEND.equals(billType) ||
((AccBillType.REPAYMENT.equals(billType) || AccBillType.TRANSFER.equals(billType))
&& listBillByAccount.getSid() == x.getFromAccount());
}).collect(Collectors.toList());
List<AccBillDTO> incomeList = accBills.stream().filter(x -> {
AccBillType billType = x.getBillType();
return AccBillType.INCOME.equals(billType) ||
((AccBillType.REPAYMENT.equals(billType) || AccBillType.TRANSFER.equals(billType))
&& listBillByAccount.getSid() == x.getAccount());
}).collect(Collectors.toList());
for (AccBillDTO accBillDTO : payList) {
expendBalance = expendBalance + accBillDTO.getMoney();
}
for (AccBillDTO accBillDTO : incomeList) {
incomeBalance = incomeBalance + accBillDTO.getMoney();
}
Map<String,Object> result = new HashMap<>();
result.put("incomeList",incomeList);
result.put("payList",payList);
result.put("expendBalance",expendBalance);
result.put("incomeBalance",incomeBalance);
return ResponseDTO.ok().setData(result);
}
/**
@@ -79,6 +112,9 @@ public class WxBillController extends BaseWxController{
if (accBill.getId() != -1){
AccBill byId = accBillService.getById(accBill.getId());
if (byId != null){
modifyBalance(true,byId);
double balance = modifyBalance(false, accBill);
byId.setBalance(balance);
byId.setId(accBill.getId());
byId.setName(accBill.getName());
byId.setBillType(accBill.getBillType());
@@ -93,10 +129,26 @@ public class WxBillController extends BaseWxController{
}else {
accBill.setGmtCreate(new Date());
accBill.setUserId(getLoginUserId(request));
double balance = modifyBalance(false, accBill);
accBill.setBalance(balance);
accBillService.save(accBill);
}
return ResponseDTO.ok();
}
private double modifyBalance(boolean isBack,AccBill accBill){
AccBillType billType = accBill.getBillType();
double money = isBack ? - accBill.getMoney() : accBill.getMoney();
accSettingService.updateBalance(accBill.getAccount(),AccBillType.EXPEND.equals(billType) ? -money : money);
if (AccBillType.REPAYMENT.equals(billType) || AccBillType.TRANSFER.equals(billType)){
accSettingService.updateBalance(accBill.getFromAccount(),-money);
}
if (AccBillType.INCOME.equals(billType) || AccBillType.EXPEND.equals(billType)){
AccSetting byId = accSettingService.getById(accBill.getAccount());
return byId.getBalance();
}
return 0;
}
}

View File

@@ -18,4 +18,6 @@ import java.util.List;
public interface AccSettingMapper extends BaseMapper<AccSetting> {
List<YearAmnt> getBillByType(String userId, AccSettingType settingType);
void updateBalance(int accId, double money);
}

View File

@@ -21,7 +21,9 @@
(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.account = #{accountId} and a.date <![CDATA[ >= ]]> #{startDate} a.date <![CDATA[ <= ]]> #{startDate}
from qn_acc_bill a where a.user_id = #{userId}
and (a.account = #{accountId} or a.from_account = #{accountId})
and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
order by a.date desc
</select>
@@ -33,7 +35,7 @@
(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}
from qn_acc_bill a where a.user_id = #{userId} and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
order by a.date desc
</select>
@@ -45,7 +47,7 @@
(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}
from qn_acc_bill a where a.user_id = #{userId} and a.bill_type='INCOME' and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
order by a.money desc
</select>
@@ -57,7 +59,7 @@
(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}
from qn_acc_bill a where a.user_id = #{userId} and a.bill_type='EXPEND' and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
order by a.money desc
</select>

View File

@@ -8,4 +8,8 @@
group by a.bill_type
</select>
<update id="updateBalance">
update qn_acc_setting set balance = balance + #{money} where id = #{accId}
</update>
</mapper>

View File

@@ -3,7 +3,7 @@
<mapper namespace="com.quinn.mapper.UserMapper">
<select id="getUserByOpenid" resultType="string">
SELECT UID FROM QN_USER WHERE OPENID = #{openid}
SELECT uid FROM qn_user WHERE openid = #{openid}
</select>
</mapper>

View File

@@ -19,4 +19,6 @@ public interface AccSettingService extends IService<AccSetting> {
List<YearAmnt> getBillByType(String userId, AccSettingType accSetting);
void updateBalance(int accId,double money);
}

View File

@@ -29,4 +29,9 @@ public class AccSettingServiceImpl extends ServiceImpl<AccSettingMapper, AccSett
public List<YearAmnt> getBillByType(String userId, AccSettingType settingType) {
return accSettingMapper.getBillByType(userId,settingType);
}
@Override
public void updateBalance(int accId, double money) {
accSettingMapper.updateBalance(accId,money);
}
}