package cn.mulanbay.pms.web.controller;
import cn.mulanbay.ai.nlp.processor.NLPProcessor;
import cn.mulanbay.common.exception.ApplicationException;
import cn.mulanbay.common.util.*;
import cn.mulanbay.persistent.query.NullType;
import cn.mulanbay.persistent.query.PageRequest;
import cn.mulanbay.persistent.query.PageResult;
import cn.mulanbay.persistent.query.Sort;
import cn.mulanbay.pms.common.ConfigKey;
import cn.mulanbay.pms.common.PmsErrorCode;
import cn.mulanbay.pms.handler.BudgetHandler;
import cn.mulanbay.pms.handler.ConsumeHandler;
import cn.mulanbay.pms.handler.SystemConfigHandler;
import cn.mulanbay.pms.handler.bean.BuyRecordMatchBean;
import cn.mulanbay.pms.persistent.domain.*;
import cn.mulanbay.pms.persistent.dto.*;
import cn.mulanbay.pms.persistent.enums.*;
import cn.mulanbay.pms.persistent.service.*;
import cn.mulanbay.pms.util.ChartUtil;
import cn.mulanbay.pms.util.TreeBeanUtil;
import cn.mulanbay.pms.web.bean.request.CommonBeanDeleteRequest;
import cn.mulanbay.pms.web.bean.request.CommonBeanGetRequest;
import cn.mulanbay.pms.web.bean.request.GroupType;
import cn.mulanbay.pms.web.bean.request.buy.*;
import cn.mulanbay.pms.web.bean.response.TreeBean;
import cn.mulanbay.pms.web.bean.response.buy.BuyRecordCostStatVo;
import cn.mulanbay.pms.web.bean.response.buy.ChartRadarGroupVo;
import cn.mulanbay.pms.web.bean.response.chart.*;
import cn.mulanbay.web.bean.response.ResultBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.*;
/**
* 购买记录
*
* @author fenghong
* @create 2017-07-10 21:44
*/
@RestController
@RequestMapping("/buyRecord")
public class BuyRecordController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(BuyRecordController.class);
private static Class<BuyRecord> beanClass = BuyRecord.class;
@Autowired
BuyRecordService buyRecordService;
@Autowired
LifeExperienceService lifeExperienceService;
@Autowired
AuthService authService;
@Autowired
BudgetHandler budgetHandler;
@Autowired
IncomeService incomeService;
@Autowired
NLPProcessor nlpProcessor;
@Autowired
ConsumeHandler consumeHandler;
@Autowired
SystemConfigHandler systemConfigHandler;
@Autowired
DataService dataService;
// # 购买记录统计中是否启用商品类型里的可统计字段
@Value("${system.buyRecord.stat.useStatable}")
boolean useStatable;
/**
* 关键字列表
*
* @return
*/
@RequestMapping(value = "/getKeywordsTree")
public ResultBean getKeywordsTree(BuyRecordKeywordsSearch sf) {
List<TreeBean> list = new ArrayList<TreeBean>();
if(sf.getStartDate()==null&&sf.getEndDate()==null){
Date[] range = this.getTagsDateRange();
sf.setStartDate(range[0]);
sf.setEndDate(range[1]);
}
List<String> keywordsList = buyRecordService.getKeywordsList(sf);
//去重
Set<String> keywordsSet = TreeBeanUtil.deleteDuplicate(keywordsList);
for (String s : keywordsSet) {
TreeBean tb = new TreeBean();
tb.setId(s);
tb.setText(s);
list.add(tb);
}
return callback(TreeBeanUtil.addRoot(list, sf.getNeedRoot()));
}
/**
* 获取标签的时间段
* @return
*/
private Date[] getTagsDateRange(){
Date[] ds = systemConfigHandler.getDateRange(null,"buyRecord.tags.days");
return ds;
}
/**
* 获取列表数据
*
* @return
*/
@RequestMapping(value = "/getData", method = RequestMethod.GET)
public ResultBean getData(BuyRecordSearch sf) {
PageRequest pr = sf.buildQuery();
if (StringUtil.isEmpty(sf.getSortField())) {
Sort s = new Sort("buyDate", Sort.DESC);
pr.addSort(s);
} else {
Sort s = new Sort(sf.getSortField(), sf.getSortType());
pr.addSort(s);
}
pr.setBeanClass(beanClass);
PageResult<BuyRecord> qr = baseService.getBeanResult(pr);
return callbackDataGrid(qr);
}
/**
* 总的概要统计
* 这里的出售已经不准了,因为售出的时间应该用deleteDate查询了
*
* @return
*/
@RequestMapping(value = "/stat", method = RequestMethod.GET)
public ResultBean stat(BuyRecordSearch sf) {
sf.setMoneyFlow(MoneyFlow.BUY);
BuyRecordStat buyData = buyRecordService.getBuyRecordStat(sf);
sf.setMoneyFlow(MoneyFlow.SALE);
BuyRecordStat saleData = buyRecordService.getBuyRecordStat(sf);
List<BuyRecordStat> list = new ArrayList<>();
list.add(buyData);
list.add(saleData);
return callback(list);
}
/**
* 统计消费金额,包含看病费用
*
* @return
*/
@RequestMapping(value = "/statWithTreat", method = RequestMethod.GET)
public ResultBean statWithTreat(BuyRecordAnalyseStatSearch sf) {
sf.setType(GroupType.TOTALPRICE);
sf.setGroupField("goods_type_id");
List<BuyRecordRealTimeStat> list = buyRecordService.getAnalyseStat(sf);
return callback(this.createAnalyseStatPieData(list, sf));
}
/**
* 创建
*
* @return
*/
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResultBean create(@RequestBody @Valid BuyRecordFormRequest formRequest) {
BuyRecord buyRecord = new BuyRecord();
changeFormToBean(formRequest, buyRecord);
buyRecord.setCreatedTime(new Date());
buyRecordService.saveBuyRecord(buyRecord);
updateIncome(buyRecord);
consumeHandler.addToCache(buyRecord);
return callback(buyRecord);
}
/**
* 转换
* @param formRequest
* @param buyRecord
*/
private void changeFormToBean(BuyRecordFormRequest formRequest, BuyRecord buyRecord) {
BeanCopy.copyProperties(formRequest, buyRecord, true);
buyRecord.setTotalPrice(buyRecord.getPrice() * buyRecord.getAmount()
+ buyRecord.getShipment());
//不判断会导致保存异常。当不选择商品子类型时,spring mvc会初始化一个空的GoodsType对象(id=null)
if (formRequest.getSubGoodsTypeId() != null) {
GoodsType subGoodsType = this.getUserEntity(GoodsType.class, formRequest.getSubGoodsTypeId(), formRequest.getUserId());
buyRecord.setSubGoodsType(subGoodsType);
} else {
buyRecord.setSubGoodsType(null);
}
BuyType buyType = this.getUserEntity(BuyType.class, formRequest.getBuyTypeId(), formRequest.getUserId());
buyRecord.setBuyType(buyType);
GoodsType goodsType = this.getUserEntity(GoodsType.class, formRequest.getGoodsTypeId(), formRequest.getUserId());
buyRecord.setGoodsType(goodsType);
//消费日期默认为购买日期
if (buyRecord.getConsumeDate() == null) {
buyRecord.setConsumeDate(buyRecord.getBuyDate());
}
//设置总价
BigDecimal totalPrice = new BigDecimal(0);
totalPrice = totalPrice.add(new BigDecimal(formRequest.getPrice()).multiply(new BigDecimal(formRequest.getAmount())));
totalPrice = totalPrice.add(new BigDecimal(formRequest.getShipment()));
buyRecord.setTotalPrice(totalPrice.doubleValue());
//设置使用时长
if(buyRecord.getDeleteDate()!=null){
long usedTime = buyRecord.getDeleteDate().getTime()-buyRecord.getBuyDate().getTime();
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
木兰湾是用于管理个人消费、锻炼、音乐、阅读、健康、饮食、人生经历等各个衣食住行信息的个人信息管理系统,通过提醒、计划模块利用调度系统来统计分析执行情况,并通过积分和评分体系来综合评估个人的总体状态。系统基于SpringBoot前后端分离,技术栈:Spring、Hibernate、Quartz、Vue
资源推荐
资源详情
资源评论
收起资源包目录
木兰湾是用于管理个人消费、锻炼、音乐、阅读、健康、饮食、人生经历等各个衣食住行信息的系统 (1288个子文件)
git 0B
.gitignore 99B
ahanlp-1.3.jar 2.47MB
ahanlp-1.3.jar 2.47MB
BuyRecordController.java 44KB
TreatService.java 39KB
FileUtil.java 35KB
BuyRecordService.java 33KB
LifeExperienceController.java 32KB
DataService.java 31KB
DietController.java 30KB
PlanService.java 29KB
TreatRecordController.java 29KB
LifeExperienceService.java 28KB
AuthService.java 26KB
PlanReportController.java 25KB
SportExerciseService.java 25KB
MusicPracticeController.java 25KB
UserRewardPointRecordController.java 24KB
BudgetController.java 24KB
SportExerciseController.java 24KB
BaseHibernateDao.java 23KB
UserBehaviorController.java 23KB
UserController.java 23KB
MainController.java 21KB
ReadingRecordController.java 21KB
AbstractBaseJob.java 20KB
DietService.java 19KB
UserPlanRemindJob.java 19KB
HTMLFilter.java 19KB
ReadingRecordService.java 18KB
BudgetSnapShotController.java 17KB
WxpayHandler.java 17KB
MusicPracticeService.java 17KB
BudgetService.java 16KB
OperationLogController.java 16KB
ScheduleHandler.java 16KB
TaskTriggerController.java 15KB
BudgetHandler.java 15KB
CommonRecordController.java 15KB
DateUtil.java 15KB
AccountController.java 14KB
UserCalendarHandler.java 14KB
UserNotifyRemindJob.java 14KB
UserCalendarController.java 14KB
LogService.java 14KB
BodyAbnormalRecordController.java 13KB
BudgetLogController.java 13KB
DreamController.java 12KB
UserBehaviorService.java 12KB
NotifyService.java 12KB
SystemFunction.java 12KB
LifeExperienceSumController.java 12KB
SleepController.java 11KB
BaseService.java 11KB
TreatDrugDetailController.java 11KB
UserPlanController.java 11KB
UserNotifyController.java 11KB
SystemFunctionController.java 11KB
UserScoreController.java 11KB
QuartzServer.java 10KB
PmsNotifyHandler.java 10KB
TaskTrigger.java 10KB
Site.java 10KB
PlanConfigController.java 10KB
QaHandler.java 10KB
UserOperationConfigController.java 10KB
TreatTestController.java 10KB
AccountService.java 10KB
TokenHandler.java 10KB
SystemConfigHandler.java 10KB
BaseController.java 10KB
QaConfigController.java 9KB
UserChartController.java 9KB
BodyBasicInfoController.java 9KB
BuyRecord.java 9KB
UserCalendarService.java 9KB
IncomeController.java 9KB
UserScoreService.java 9KB
PmsMessageSendHandler.java 9KB
WorkOvertimeController.java 9KB
ChartUtil.java 9KB
UserScoreHandler.java 9KB
BudgetCheckJob.java 9KB
ConsumeHandler.java 9KB
AbstractQaMessageHandler.java 9KB
Base64Util.java 9KB
ControllerHandler.java 9KB
SportMilestoneController.java 8KB
DreamRemindJob.java 8KB
WechatController.java 8KB
NotifyConfigController.java 8KB
TreatDrugController.java 8KB
SystemFunctionFormRequest.java 8KB
UserPlanService.java 8KB
BuyRecordMatchLogController.java 8KB
RoleController.java 8KB
ModelConfigController.java 8KB
HibernatePersistentProcessor.java 8KB
LevelConfigController.java 8KB
共 1288 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7364
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
- 基于Java的财务报销管理系统后端开发源码
- 基于Python核心技术的cola项目设计源码介绍
- 基于Python及多语言集成的TSDT软件过程改进设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功