package com.pj.project.tb_fee_statistics;

import java.util.List;

import com.pj.utils.so.SoMap;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.project4sp.SP;

import com.pj.current.satoken.StpUserUtil;
import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: tb_fee_statistics -- 收费统计表
 * @author lzm 
 */
@RestController
@RequestMapping("/TbFeeStatistics/")
public class TbFeeStatisticsController {

	/** 底层 Service 对象 */
	@Autowired
	TbFeeStatisticsService tbFeeStatisticsService;

	/** 增 */  
	@RequestMapping("add")
	@SaCheckPermission(TbFeeStatistics.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson add(TbFeeStatistics t){
		tbFeeStatisticsService.add(t);
		t = tbFeeStatisticsService.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(t);
	}

	/** 删 */  
	@RequestMapping("delete")
	@SaCheckPermission(TbFeeStatistics.PERMISSION_CODE)
	public AjaxJson delete(Long id){
		int line = tbFeeStatisticsService.delete(id);
		return AjaxJson.getByLine(line);
	}
	
	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
	@SaCheckPermission(TbFeeStatistics.PERMISSION_CODE)
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
		int line = SP.publicMapper.deleteByIds(TbFeeStatistics.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 */  
	@RequestMapping("update")
	@SaCheckPermission(TbFeeStatistics.PERMISSION_CODE)
	public AjaxJson update(TbFeeStatistics t){
		int line = tbFeeStatisticsService.update(t);
		return AjaxJson.getByLine(line);
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbFeeStatistics t = tbFeeStatisticsService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
	public AjaxJson getList() { 
		SoMap so = SoMap.getRequestSoMap();
		List<TbFeeStatistics> list = tbFeeStatisticsService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}

    @RequestMapping("getMonth")
    public AjaxJson getMonth() {
        SoMap so = SoMap.getRequestSoMap();
        List<TbFeeStatistics> list = tbFeeStatisticsService.getMonth(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }

    @RequestMapping("getYear")
    public AjaxJson getYear() {
        SoMap so = SoMap.getRequestSoMap();
        List<TbFeeStatistics> list = tbFeeStatisticsService.getYear(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }

    @RequestMapping("updateParkNum")
    public AjaxJson updateParkNum(){
        SoMap so = SoMap.getRequestSoMap();
        String day = so.getString("day");
        TbFeeStatistics feeStatistics = tbFeeStatisticsService.updateParkNum(day);
        return AjaxJson.getSuccessData(feeStatistics);
    }

    @RequestMapping("export/monthStatistics")
    public AjaxJson exportMonthStatistics() throws Exception{
        SoMap so = SoMap.getRequestSoMap();
        return AjaxJson.getSuccessData(tbFeeStatisticsService.exportMonthStatistics(so));
    }


    @RequestMapping("calcuAgain")
    public AjaxJson calcuAgain() {
        tbFeeStatisticsService.calcuAgain();
        return AjaxJson.getSuccess();
    }
	
	
	
	// ------------------------- 前端接口 -------------------------
	
	
	/** 改 - 不传不改 [G] */
	@RequestMapping("updateByNotNull")
	public AjaxJson updateByNotNull(Long id){
		AjaxError.throwBy(true, "如需正常调用此接口，请删除此行代码");
		// 鉴别身份，是否为数据创建者 
		long userId = SP.publicMapper.getColumnByIdToLong(TbFeeStatistics.TABLE_NAME, "user_id", id);
		AjaxError.throwBy(userId != StpUserUtil.getLoginIdAsLong(), "此数据您无权限修改");
		// 开始修改 (请只保留需要修改的字段)
		SoMap so = SoMap.getRequestSoMap();
		so.clearNotIn("id", "feeType", "feeTypeId", "feeTypeName", "itemTypeId", "itemTypeName", "year", "month", "dayTime", "num", "taxMoney", "taxRate", "noTaxMoney", "payType").clearNull().humpToLineCase();	
		int line = SP.publicMapper.updateBySoMapById(TbFeeStatistics.TABLE_NAME, so, id);
		return AjaxJson.getByLine(line);
	}
	

	@RequestMapping(value = "getFeeType")
	public AjaxJson getFeeType(){
		return AjaxJson.getSuccessData(TbFeeStatistics.getList());
	}
	
	
	
	

}
