微信API 账单查询
This commit is contained in:
@@ -2,10 +2,13 @@ package com.quinn.controller.wx;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.quinn.common.wx.AccBillDTO;
|
import com.quinn.common.wx.AccBillDTO;
|
||||||
|
import com.quinn.common.wx.AccBillType;
|
||||||
import com.quinn.common.wx.ListBillByAccount;
|
import com.quinn.common.wx.ListBillByAccount;
|
||||||
import com.quinn.dto.res.ResponseDTO;
|
import com.quinn.dto.res.ResponseDTO;
|
||||||
import com.quinn.pojo.AccBill;
|
import com.quinn.pojo.AccBill;
|
||||||
|
import com.quinn.pojo.AccSetting;
|
||||||
import com.quinn.service.AccBillService;
|
import com.quinn.service.AccBillService;
|
||||||
|
import com.quinn.service.AccSettingService;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -14,7 +17,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -30,6 +36,8 @@ public class WxBillController extends BaseWxController{
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AccBillService accBillService;
|
AccBillService accBillService;
|
||||||
|
@Resource
|
||||||
|
AccSettingService accSettingService;
|
||||||
|
|
||||||
@PostMapping("user/bills")
|
@PostMapping("user/bills")
|
||||||
public ResponseDTO getBills(HttpServletRequest request){
|
public ResponseDTO getBills(HttpServletRequest request){
|
||||||
@@ -46,7 +54,32 @@ public class WxBillController extends BaseWxController{
|
|||||||
@PostMapping("user/bills/account")
|
@PostMapping("user/bills/account")
|
||||||
public ResponseDTO getBillsByBills(HttpServletRequest request, ListBillByAccount listBillByAccount){
|
public ResponseDTO getBillsByBills(HttpServletRequest request, ListBillByAccount listBillByAccount){
|
||||||
List<AccBillDTO> accBills = accBillService.listBillByAccount(getLoginUserId(request),listBillByAccount.getSid(),listBillByAccount.getDateRange());
|
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){
|
if (accBill.getId() != -1){
|
||||||
AccBill byId = accBillService.getById(accBill.getId());
|
AccBill byId = accBillService.getById(accBill.getId());
|
||||||
if (byId != null){
|
if (byId != null){
|
||||||
|
modifyBalance(true,byId);
|
||||||
|
double balance = modifyBalance(false, accBill);
|
||||||
|
byId.setBalance(balance);
|
||||||
byId.setId(accBill.getId());
|
byId.setId(accBill.getId());
|
||||||
byId.setName(accBill.getName());
|
byId.setName(accBill.getName());
|
||||||
byId.setBillType(accBill.getBillType());
|
byId.setBillType(accBill.getBillType());
|
||||||
@@ -93,10 +129,26 @@ public class WxBillController extends BaseWxController{
|
|||||||
}else {
|
}else {
|
||||||
accBill.setGmtCreate(new Date());
|
accBill.setGmtCreate(new Date());
|
||||||
accBill.setUserId(getLoginUserId(request));
|
accBill.setUserId(getLoginUserId(request));
|
||||||
|
double balance = modifyBalance(false, accBill);
|
||||||
|
accBill.setBalance(balance);
|
||||||
accBillService.save(accBill);
|
accBillService.save(accBill);
|
||||||
}
|
}
|
||||||
return ResponseDTO.ok();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ import java.util.List;
|
|||||||
public interface AccSettingMapper extends BaseMapper<AccSetting> {
|
public interface AccSettingMapper extends BaseMapper<AccSetting> {
|
||||||
|
|
||||||
List<YearAmnt> getBillByType(String userId, AccSettingType settingType);
|
List<YearAmnt> getBillByType(String userId, AccSettingType settingType);
|
||||||
|
|
||||||
|
void updateBalance(int accId, double money);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
|
(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",
|
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
|
||||||
DATE_FORMAT(a.date,'%Y-%m-%d') date
|
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
|
order by a.date desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@
|
|||||||
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
|
(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",
|
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
|
||||||
DATE_FORMAT(a.date,'%Y-%m-%d') date
|
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
|
order by a.date desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@
|
|||||||
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
|
(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",
|
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
|
||||||
DATE_FORMAT(a.date,'%Y-%m-%d') date
|
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
|
order by a.money desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@
|
|||||||
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
|
(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",
|
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
|
||||||
DATE_FORMAT(a.date,'%Y-%m-%d') date
|
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
|
order by a.money desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,8 @@
|
|||||||
group by a.bill_type
|
group by a.bill_type
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="updateBalance">
|
||||||
|
update qn_acc_setting set balance = balance + #{money} where id = #{accId}
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<mapper namespace="com.quinn.mapper.UserMapper">
|
<mapper namespace="com.quinn.mapper.UserMapper">
|
||||||
|
|
||||||
<select id="getUserByOpenid" resultType="string">
|
<select id="getUserByOpenid" resultType="string">
|
||||||
SELECT UID FROM QN_USER WHERE OPENID = #{openid}
|
SELECT uid FROM qn_user WHERE openid = #{openid}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ public interface AccSettingService extends IService<AccSetting> {
|
|||||||
|
|
||||||
List<YearAmnt> getBillByType(String userId, AccSettingType accSetting);
|
List<YearAmnt> getBillByType(String userId, AccSettingType accSetting);
|
||||||
|
|
||||||
|
void updateBalance(int accId,double money);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,9 @@ public class AccSettingServiceImpl extends ServiceImpl<AccSettingMapper, AccSett
|
|||||||
public List<YearAmnt> getBillByType(String userId, AccSettingType settingType) {
|
public List<YearAmnt> getBillByType(String userId, AccSettingType settingType) {
|
||||||
return accSettingMapper.getBillByType(userId,settingType);
|
return accSettingMapper.getBillByType(userId,settingType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBalance(int accId, double money) {
|
||||||
|
accSettingMapper.updateBalance(accId,money);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user