package com.zcloud.controller.study;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.study.TempStudyService;
import com.zcloud.service.study.TempStudyUsersService;
import com.zcloud.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：临时学习任务
 * 作者：luoxiaobao
 * 时间：2022-05-18
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/tempstudy")
public class AppTempStudyController extends BaseController {

	@Autowired
	private TempStudyService tempstudyService;
	@Autowired
	private TempStudyUsersService tempStudyUsersService;

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	@ResponseBody
	@Transactional
	@LogAnno(menuType= "手机",menuServer= "临时学习任务",instructionsOperate = "临时学习任务",instructionsType = "修改")
	public Object edit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = tempStudyUsersService.findById(pd);
		pd.put("STATUS",1);
		pd.put("STUDY_TIME", DateUtil.date2Str(new Date()));
		tempStudyUsersService.edit(pd);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	@LogAnno(menuType= "手机",menuServer= "临时学习任务",instructionsOperate = "临时学习任务",instructionsType = "列表")
	public Object list(Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		page.setPd(pd);
		List<PageData>	varList = tempStudyUsersService.list(page);	//列出TempStudy列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}
}
