package com.java110.fee.api;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.java110.po.meter.PhoneBillFlow;
|
import com.java110.utils.util.Assert;
|
import com.java110.utils.util.BeanConvertUtil;
|
import org.mybatis.spring.SqlSessionTemplate;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 话费流水信息接口
|
* 适配 phone_bill_flow 表
|
* @author dev
|
* @date 2025-12-24
|
*/
|
@RestController
|
@RequestMapping(value = "/phoneBillFlowInfo")
|
public class PhoneBillFlowInfoApi {
|
|
@Autowired
|
protected SqlSessionTemplate sqlSessionTemplate;
|
|
/**
|
* 保存话费流水信息
|
*
|
* @param reqJson 请求参数
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/savePhoneBillFlowInfo
|
* @path /app/phoneBillFlowInfo/savePhoneBillFlowInfo
|
*/
|
@RequestMapping(value = "/savePhoneBillFlowInfo", method = RequestMethod.POST)
|
public ResponseEntity<String> savePhoneBillFlowInfo(@RequestBody JSONObject reqJson) {
|
// 核心参数校验
|
Assert.hasKeyAndValue(reqJson, "id", "请求报文中未包含主键ID");
|
Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区ID");
|
|
// 转换为DTO
|
PhoneBillFlow dto = BeanConvertUtil.covertBean(reqJson, PhoneBillFlow.class);
|
|
// 调用Mapper保存方法
|
int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.savePhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(dto));
|
|
// 构造响应结果
|
JSONObject resJson = new JSONObject();
|
if (insert > 0) {
|
resJson.put("code", "0000");
|
resJson.put("msg", "保存话费流水信息成功");
|
} else {
|
resJson.put("code", "0001");
|
resJson.put("msg", "保存话费流水信息失败");
|
}
|
resJson.put("count", insert);
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 重载方法-保存话费流水信息
|
*
|
* @param dto 话费流水DTO
|
* @return 响应结果
|
*/
|
public ResponseEntity<String> savePhoneBillFlowInfo(PhoneBillFlow dto) {
|
int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.savePhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(dto));
|
|
// 构造响应结果
|
JSONObject resJson = new JSONObject();
|
if (insert > 0) {
|
resJson.put("code", "0000");
|
resJson.put("msg", "保存话费流水信息成功");
|
} else {
|
resJson.put("code", "0001");
|
resJson.put("msg", "保存话费流水信息失败");
|
}
|
resJson.put("count", insert);
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 批量插入话费流水信息
|
*
|
* @param reqJson 请求参数(包含phoneBillFlowList列表)
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/insertPhoneBillFlows
|
* @path /app/phoneBillFlowInfo/insertPhoneBillFlows
|
*/
|
@RequestMapping(value = "/insertPhoneBillFlows", method = RequestMethod.POST)
|
public ResponseEntity<String> insertPhoneBillFlows(@RequestBody JSONObject reqJson) {
|
// 校验列表参数
|
Assert.hasKey(reqJson, "phoneBillFlowList", "请求报文中未包含话费流水列表");
|
Assert.notEmpty(reqJson.getJSONArray("phoneBillFlowList"), "话费流水列表不能为空");
|
|
// 转换为Map(适配批量插入的参数格式)
|
Map<String, Object> paramMap = new HashMap<>();
|
paramMap.put("phoneBillFlowList", reqJson.getJSONArray("phoneBillFlowList"));
|
|
// 调用Mapper批量插入方法
|
int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.insertPhoneBillFlows", paramMap);
|
|
// 构造响应结果
|
JSONObject resJson = new JSONObject();
|
if (insert > 0) {
|
resJson.put("code", "0000");
|
resJson.put("msg", "批量插入话费流水信息成功");
|
} else {
|
resJson.put("code", "0001");
|
resJson.put("msg", "批量插入话费流水信息失败");
|
}
|
resJson.put("count", insert);
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 修改话费流水信息
|
*
|
* @param reqJson 请求参数
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/updatePhoneBillFlowInfo
|
* @path /app/phoneBillFlowInfo/updatePhoneBillFlowInfo
|
*/
|
@RequestMapping(value = "/updatePhoneBillFlowInfo", method = RequestMethod.POST)
|
public ResponseEntity<String> updatePhoneBillFlowInfo(@RequestBody JSONObject reqJson) {
|
// 主键校验
|
Assert.hasKey(reqJson, "id", "请求报文中未包含主键ID");
|
|
PhoneBillFlow dto = BeanConvertUtil.covertBean(reqJson, PhoneBillFlow.class);
|
|
// 调用Mapper修改方法
|
int update = sqlSessionTemplate.update("phoneBillFlowServiceDaoImpl.updatePhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(dto));
|
|
JSONObject resJson = new JSONObject();
|
if (update > 0) {
|
resJson.put("code", "0000");
|
resJson.put("msg", "修改话费流水信息成功");
|
} else {
|
resJson.put("code", "0001");
|
resJson.put("msg", "修改话费流水信息失败,未找到对应记录");
|
}
|
resJson.put("count", update);
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 分页查询话费流水信息列表
|
*
|
* @param id 主键ID(可选)
|
* @param communityId 小区ID(可选)
|
* @param roomId 房间ID(可选)
|
* @param deviceNumber 设备号(可选)
|
* @param year 年份(可选)
|
* @param month 月份(可选)
|
* @param page 页码(默认1)
|
* @param row 每页条数(默认10)
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/queryPhoneBillFlowInfo
|
* @path /app/phoneBillFlowInfo/queryPhoneBillFlowInfo
|
*/
|
@RequestMapping(value = "/queryPhoneBillFlowInfo", method = RequestMethod.GET)
|
public ResponseEntity<String> queryPhoneBillFlowInfo(
|
@RequestParam(value = "id", required = false) String id,
|
@RequestParam(value = "communityId", required = false) String communityId,
|
@RequestParam(value = "roomId", required = false) String roomId,
|
@RequestParam(value = "deviceNumber", required = false) String deviceNumber,
|
@RequestParam(value = "year", required = false) String year,
|
@RequestParam(value = "month", required = false) String month,
|
@RequestParam(value = "page", defaultValue = "1") int page,
|
@RequestParam(value = "row", defaultValue = "10") int row) {
|
|
// 封装查询参数
|
PhoneBillFlow queryDto = new PhoneBillFlow();
|
queryDto.setId(id);
|
queryDto.setCommunityId(communityId);
|
queryDto.setRoomId(roomId);
|
queryDto.setDeviceNumber(deviceNumber);
|
queryDto.setYear(year);
|
queryDto.setMonth(month);
|
queryDto.setPage((page - 1) * row); // 计算分页起始位置
|
queryDto.setRow(row);
|
|
// 查询列表数据
|
List<Map<String, Object>> list = sqlSessionTemplate.selectList(
|
"phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(queryDto));
|
|
List<PhoneBillFlow> phoneBillFlows = BeanConvertUtil.covertBeanList(list, PhoneBillFlow.class);
|
|
// 查询总数
|
Object total = ((HashMap) sqlSessionTemplate.selectOne(
|
"phoneBillFlowServiceDaoImpl.queryPhoneBillFlowsCount",
|
BeanConvertUtil.beanCovertMap(queryDto))).get("count");
|
|
// 构造分页响应
|
JSONObject resJson = new JSONObject();
|
resJson.put("code", "0000");
|
resJson.put("msg", "查询话费流水信息成功");
|
resJson.put("page", page);
|
resJson.put("row", row);
|
resJson.put("total", total);
|
resJson.put("data", phoneBillFlows);
|
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 根据ID查询单条话费流水信息
|
*
|
* @param id 主键ID
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/getPhoneBillFlowInfoById
|
* @path /app/phoneBillFlowInfo/getPhoneBillFlowInfoById
|
*/
|
@RequestMapping(value = "/getPhoneBillFlowInfoById", method = RequestMethod.GET)
|
public ResponseEntity<String> getPhoneBillFlowInfoById(@RequestParam(value = "id") String id) {
|
// 主键校验
|
Assert.hasLength(id, "主键ID不能为空");
|
|
PhoneBillFlow queryDto = new PhoneBillFlow();
|
queryDto.setId(id);
|
|
// 查询单条数据
|
Map<String, Object> result = sqlSessionTemplate.selectOne(
|
"phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(queryDto));
|
|
|
JSONObject resJson = new JSONObject();
|
if (result != null) {
|
PhoneBillFlow phoneBillFlow = BeanConvertUtil.covertBean(result, PhoneBillFlow.class);
|
resJson.put("code", "0000");
|
resJson.put("msg", "查询话费流水信息成功");
|
resJson.put("data", phoneBillFlow);
|
} else {
|
resJson.put("code", "0001");
|
resJson.put("msg", "未找到对应话费流水记录");
|
}
|
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
|
/**
|
* 根据设备号查询话费流水信息
|
*
|
* @param deviceNumber 设备号
|
* @return 响应结果
|
* @serviceCode /phoneBillFlowInfo/getPhoneBillFlowInfoByDeviceNumber
|
* @path /app/phoneBillFlowInfo/getPhoneBillFlowInfoByDeviceNumber
|
*/
|
@RequestMapping(value = "/getPhoneBillFlowInfoByDeviceNumber", method = RequestMethod.GET)
|
public ResponseEntity<String> getPhoneBillFlowInfoByDeviceNumber(@RequestParam(value = "deviceNumber") String deviceNumber) {
|
Assert.hasLength(deviceNumber, "设备号不能为空");
|
|
PhoneBillFlow queryDto = new PhoneBillFlow();
|
queryDto.setDeviceNumber(deviceNumber);
|
|
List<Map<String, Object>> result = sqlSessionTemplate.selectList(
|
"phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
|
BeanConvertUtil.beanCovertMap(queryDto));
|
|
JSONObject resJson = new JSONObject();
|
resJson.put("code", "0000");
|
resJson.put("msg", "查询话费流水信息成功");
|
resJson.put("data", result);
|
|
return ResponseEntity.ok(resJson.toJSONString());
|
}
|
}
|