package cn.timer.api.controller.qyzx;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;

import javax.servlet.http.HttpSession;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.additional.update.impl.LambdaUpdateChainWrapper;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.timer.api.bean.qyzx.QyzxAttaFwjsb;
import cn.timer.api.bean.qyzx.QyzxEmpEntAsso;
import cn.timer.api.bean.qyzx.QyzxEmpLogin;
import cn.timer.api.bean.qyzx.QyzxEntInfoM;
import cn.timer.api.bean.qyzx.QyzxFeebackAccessory;
import cn.timer.api.bean.qyzx.QyzxInvoiceUsual;
import cn.timer.api.bean.qyzx.QyzxLogBuy;
import cn.timer.api.bean.qyzx.QyzxOperLog;
import cn.timer.api.bean.qyzx.QyzxPayServe;
import cn.timer.api.bean.qyzx.QyzxSuggestionFeeback;
import cn.timer.api.bean.spmk.SpmkApproveSummary;
import cn.timer.api.bean.zzgl.ZzglAuth;
import cn.timer.api.bean.zzgl.ZzglBmgwM;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enums.CommonEnum;
import cn.timer.api.dao.qyzx.QyzxEmpEntAssoMapper;
import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper;
import cn.timer.api.dao.qyzx.QyzxEntAuthMapper;
import cn.timer.api.dao.qyzx.QyzxEntInfoMMapper;
import cn.timer.api.dao.qyzx.QyzxFeebackAccessoryMapper;
import cn.timer.api.dao.qyzx.QyzxInvoiceUsualMapper;
import cn.timer.api.dao.qyzx.QyzxLogBuyMapper;
import cn.timer.api.dao.qyzx.QyzxOperLogMapper;
import cn.timer.api.dao.qyzx.QyzxPayServeMapper;
import cn.timer.api.dao.qyzx.QyzxSuggestionFeebackMapper;
import cn.timer.api.dao.zzgl.ZzglBmgwMMapper;
import cn.timer.api.dto.login.QysDto;
import cn.timer.api.dto.qyzx.AdminListDto;
import cn.timer.api.dto.qyzx.AttaFpglQueryDto;
import cn.timer.api.dto.qyzx.EntauthDto;
import cn.timer.api.dto.qyzx.FeebackDto;
import cn.timer.api.dto.qyzx.LogBuyDto;
import cn.timer.api.dto.qyzx.QyzxOperLogQuaryDto;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.aliyun.OSSUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@Api(tags = "4.0企业中心")
@RequestMapping(value = "/qyzx", produces = { "application/json" })
public class QyzxController {
	@Autowired
	private HttpSession session;

	@Autowired
	private QyzxEmpEntAssoMapper qyzxEmpEntAssoMapper;

	@Autowired
	private QyzxEntInfoMMapper qyzxEntInfoMMapper;

	@Autowired
	private QyzxEmpLoginMapper qyzxEmpLoginMapper;

	@Autowired
	private QyzxLogBuyMapper qyzxLogBuyMapper;

	@Autowired
	private QyzxEntAuthMapper qyzxEntAuthMapper;

	@Autowired
	private ZzglBmgwMMapper zzglBmgwMMapper;

	@Autowired
	private QyzxPayServeMapper qyzxPayServeMapper;

	@Autowired
	private QyzxSuggestionFeebackMapper qyzxSuggestionFeebackMapper;

	@Autowired
	private QyzxFeebackAccessoryMapper qyzxFeebackAccessoryMapper;

	@Autowired
	private QyzxInvoiceUsualMapper qyzxInvoiceUsualMapper;

	/**
	 * 获取企业信息
	 * 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/ent")
	@ApiOperation(value = "获取企业信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<QyzxEntInfoM> selectent(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		QyzxEntInfoM qyzxEntInfoM = new LambdaQueryChainWrapper<QyzxEntInfoM>(qyzxEntInfoMMapper)
				.eq(orgCode != null, QyzxEntInfoM::getId, orgCode).one();
		return ResultUtil.data(qyzxEntInfoM, "获取企业信息成功");
	}

	/**
	 * 添加/修改企业信息
	 * 
	 * @param
	 * @return
	 */
	@PostMapping(value = "/ent")
	@ApiOperation(value = "添加/修改企业信息", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxEntInfoM> addent(@CurrentUser UserBean userBean, @RequestBody QyzxEntInfoM qyzxEntInfoM) {
		qyzxEntInfoM.setId(userBean.getOrgCode());
		
		QyzxEntInfoM q = new LambdaQueryChainWrapper<QyzxEntInfoM>(qyzxEntInfoMMapper)
				.eq(QyzxEntInfoM::getId, userBean.getOrgCode()).one();
		
		
		qyzxEntInfoM.setRegisterTime(q.getRegisterTime());
		qyzxEntInfoM.insertOrUpdate();

		return ResultUtil.data(qyzxEntInfoM, "添加/修改企业");
	}

	/**
	 * 企业认证-申请
	 * 
	 * @param qyzxEntAuth
	 * @return
	 */
	@PostMapping(value = "/entauth")
	@ApiOperation(value = "企业认证", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxEntInfoM> entauth(@CurrentUser UserBean userBean, @RequestBody QyzxEntInfoM qyzxEntInfoM) {
		// 设置审核状态
		qyzxEntInfoM.setAttestStatus(CommonEnum.AUTH_TYPE_UNDEREVIEW.getType());
		qyzxEntInfoM.setId(userBean.getOrgCode());
		qyzxEntInfoM.updateById();
		// }
		return ResultUtil.data(qyzxEntInfoM, "申请企业认证中");
	}

	/**
	 * 企业认证-审核-通过/未通过
	 * 
	 * @param qyzxEntAuth
	 * @return
	 */
	/*
	 * @PostMapping(value = "/entauthcheck")
	 * 
	 * @ApiOperation(value = "企业认证-审核-通过/未通过", httpMethod = "POST", notes =
	 * "接口发布说明") public Result<QyzxEntAuth> entauthcheck1(@CurrentUser UserBean
	 * userBean, @RequestBody QyzxEntAuth qyzxEntAuth) { Integer id =
	 * qyzxEntAuth.getId(); Integer authType = qyzxEntAuth.getAuthType(); if (id ==
	 * null || authType == null) { return ResultUtil.error("参数缺少/异常"); } QyzxEntAuth
	 * entAuth = QyzxEntAuth.builder().id(id).authType(authType).build(); boolean b
	 * = entAuth.updateById(); if (b) { return ResultUtil.data(qyzxEntAuth,
	 * "企业认证-审批成功"); } else { return ResultUtil.error("企业认证-审批失败"); } }
	 */

	/**
	 * 运营管理 企业认证-审核-通过/不通过(weng)
	 * 
	 * @param qyzxEntAuth
	 * @return
	 */
	@PostMapping(value = "/entauthpass")
	@ApiOperation(value = "企业认证-审核-通过", httpMethod = "POST", notes = "接口发布说明")
	public Result<String> entauthpass(@RequestBody EntauthDto entauthDto) {// 2未通过,3通过
		String msg = "企业未认证";
		Integer type = entauthDto.getAuthType();
		if (type == CommonEnum.AUTH_TYPE_SUCCESS.getType()) {
			msg = "企业认证成功";
		}
		if (type == CommonEnum.AUTH_TYPE_FAILURE.getType()) {
			msg = "企业认证失败";
		}
		boolean b = new LambdaUpdateChainWrapper<QyzxEntInfoM>(qyzxEntInfoMMapper)
				.eq(QyzxEntInfoM::getId, entauthDto.getOrgCode()).set(QyzxEntInfoM::getAttestStatus, type).update();
		if (b) {
			return ResultUtil.data(msg);
		}
		return ResultUtil.data("企业认证流程有误");
	}

	/**
	 * 新增/编辑常用企业开票资料
	 * 
	 * @param QyzxInvoiceUsual
	 * @return
	 */
	@PostMapping(value = "/invoiceusual")
	@ApiOperation(value = "新增/编辑常用企业开票资料", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxInvoiceUsual> invoiceusual(@CurrentUser UserBean userBean,
			@RequestBody QyzxInvoiceUsual qyzxInvoiceUsual) {
		qyzxInvoiceUsual.setOrgCode(userBean.getOrgCode());
		qyzxInvoiceUsual.setModifyUser(userBean.getEmpNum());
		boolean tof = qyzxInvoiceUsual.insertOrUpdate();
		if (tof) {
			return ResultUtil.data(qyzxInvoiceUsual, "常用企业开票资料已修改");
		}
		return ResultUtil.error("开票资料修改无效");
	}

	/**
	 * 显示常用的企业开票资料
	 * 
	 * @param QyzxInvoiceUsual
	 * @return
	 */
	@SuppressWarnings("deprecation")
	@GetMapping(value = "/invoiceusual")
	@ApiOperation(value = "显示常用的企业开票资料", httpMethod = "GET", notes = "接口发布说明")
	public Result<QyzxInvoiceUsual> invoiceusual(@CurrentUser UserBean userBean) {
		QyzxInvoiceUsual one = qyzxInvoiceUsualMapper.selectOne(new QueryWrapper<QyzxInvoiceUsual>().lambda()
				.eq(QyzxInvoiceUsual::getOrgCode, userBean.getOrgCode()));
		if (one != null) {
			if (one.getShippingArea() == null) {
				one.setShippingArea("");
			}
			if (one.getShippingAddress() == null) {
				one.setShippingAddress("");
			}
		}
		return ResultUtil.data(one, "显示常用的企业开票资料");
	}

	/**
	 * 显示企业的超级管理员
	 * 
	 * @param qyzxEntAuth
	 * @return
	 */
	@GetMapping(value = "/smanagerphone")
	@ApiOperation(value = "显示超管头像和电话号码", httpMethod = "GET", notes = "接口发布说明")
	public Result<QyzxEmpLogin> smanagerphone(@CurrentUser UserBean userBean) {
		QyzxEmpEntAsso smanagerid = new LambdaQueryChainWrapper<QyzxEmpEntAsso>(qyzxEmpEntAssoMapper)
				.select(QyzxEmpEntAsso::getEmpNum).eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode())
				.eq(QyzxEmpEntAsso::getStatus, 0).one();
		QyzxEmpLogin smanagerphone = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
				.select(QyzxEmpLogin::getPhone, QyzxEmpLogin::getHeadUrl)
				.eq(QyzxEmpLogin::getId, smanagerid.getEmpNum()).one();
		return ResultUtil.data(smanagerphone, "企业超管头像和电话号码");
	}

	/*	*//**
			 * 获取企业的到期时间和版本号
			 *//*
				 * @GetMapping(value = "/endtimeversion")
				 * 
				 * @ApiOperation(value = "获取企业的到期时间和版本号", httpMethod = "GET", notes = "接口发布说明")
				 * public Result<QyzxEntInfoM> endtimeversion(@CurrentUser UserBean userBean) {
				 * QyzxEntInfoM qyzxEntInfoM = new
				 * LambdaQueryChainWrapper<QyzxEntInfoM>(qyzxEntInfoMMapper)
				 * .select(QyzxEntInfoM::getEndTime,QyzxEntInfoM::getLevel).eq(QyzxEntInfoM::
				 * getId, userBean.getOrgCode()).one(); return ResultUtil.data(qyzxEntInfoM,
				 * "获取企业的到期时间和版本号成功"); }
				 */

	/**
	 * 企业列表
	 * 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/entlist")
	@ApiOperation(value = "企业列表", httpMethod = "GET", notes = "接口发布说明", position = 98)
	public Result<List<QyzxEntInfoM>> entlist1(@CurrentUser UserBean userBean) {
		Integer empNum = userBean.getEmpNum();
		QueryWrapper<QyzxEmpEntAsso> queryWrapper = new QueryWrapper<>();
		queryWrapper.select("org_code").eq("emp_num", empNum);
		List<Object> orgCodes = qyzxEmpEntAssoMapper.selectObjs(queryWrapper);
		List<QyzxEntInfoM> qyzxEntInfoMs = new LambdaQueryChainWrapper<QyzxEntInfoM>(qyzxEntInfoMMapper)
				.in(CollUtil.isNotEmpty(orgCodes), QyzxEntInfoM::getId, orgCodes).list();
		return ResultUtil.data(qyzxEntInfoMs, "获取企业信息成功");
	}

	/**
	 * 切换企业
	 * 
	 * @param org_num
	 * @return
	 */
	@GetMapping(value = "/changeent/{orgCode}")
	@ApiOperation(value = "切换企业", httpMethod = "GET", notes = "接口发布说明", position = 97)
	public Result<List<String>> changeent(@CurrentUser UserBean userBean, @PathVariable Integer orgCode) {
		// 查询该员工加入的企业id列表
		QyzxEmpLogin emp = userBean.getQyzxEmpLogin();
		Stream<QysDto> s = emp.getQys().stream().filter(o -> orgCode.equals(o.getId()));
		// 判断 切换目标企业id 是否包含在 企业id列表 内
		if (s != null) {
			List<String> menus = new ArrayList<>();
			QysDto ctrl = s.findFirst().get();
			if (CommonEnum.U_TYPE_ADMIN.getType().equals(ctrl.getUserType())
					|| CommonEnum.U_TYPE_C_ADMIN.getType().equals(ctrl.getUserType())) {
			} else {
				// 获取权限
				ArrayList<Integer> list = new ArrayList<Integer>();
//				List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
//						.eq(ZzglBmgwM::getOrgCode, ctrl.getId()).list();
				
				List<ZzglBmgwM> zzglBmgwMs = zzglBmgwMMapper.selectList(new QueryWrapper<ZzglBmgwM>().lambda().eq(ZzglBmgwM::getOrgCode, ctrl.getId()));
				
				// 传入的部门岗位是登录者的岗位id.获取的list中只有一个元素,不必要
				ZzglBmgwM.getupDepts(list, ctrl.getBmgwId(), zzglBmgwMs);
				if (list != null && list.size() > 0) {
					LambdaQueryWrapper<ZzglAuth> wp = new LambdaQueryWrapper<>();
					wp.select(ZzglAuth::getMenuId).eq(ZzglAuth::getOrgCode, ctrl.getId())
							.and(i -> i.in(ZzglAuth::getBmgwId, list.toArray()));
					List<ZzglAuth> zas = ZzglAuth.builder().build().selectList(wp);
					if (zas != null && zas.size() != 0)
						zas.stream().forEach(o -> menus.add(o.getMenuId()));
				}
			}
			emp.setOrgId(orgCode);
			session.setAttribute("ui", emp);
			qyzxEmpLoginMapper.updateById(emp);
			return ResultUtil.data(menus, "切换企业成功");
		} else {
			return ResultUtil.error();
		}
	}

	@Autowired
	private OSSUtil oss;

	// 下载系统使用手册 直接提供(OSS公共读权限文件)url地址到前端按钮
	/**
	 * 意见反馈
	 */

	/*
	 * @PostMapping(value = "/feedback")
	 * 
	 * @ApiOperation(value = "意见反馈", httpMethod = "POST", notes = "接口发布说明") public
	 * Result<QyzxSuggestionFeeback> feedback(@CurrentUser UserBean userBean,
	 * 
	 * @RequestParam(required = false) String opinionText, @RequestParam(required =
	 * false) String moudle,
	 * 
	 * @Param("files") List<MultipartFile> files) { String url = null; List<String>
	 * list = new ArrayList<String>(); if (files != null) { for (MultipartFile file
	 * : files) { String path = "8timer2.0/" + userBean.getOrgCode() + "/" + moudle
	 * + "/" + file.getOriginalFilename(); if (file == null || file.getSize() <= 0)
	 * { return ResultUtil.error("上传的文件为空,请重新选择!"); } else { try { url =
	 * oss.uploadFile(path, file.getInputStream()); list.add(url); } catch
	 * (IOException e) { e.printStackTrace(); } } } } QyzxSuggestionFeeback feeback
	 * = new QyzxSuggestionFeeback(); feeback.setEmpNum(userBean.getEmpNum());
	 * feeback.setOpinionText(opinionText); feeback.setCreateTime(new Date());
	 * feeback.setOrgCode(userBean.getOrgCode()); boolean a = feeback.insert(); if
	 * (a && list.size() > 0) { for (String opinionUrl : list) {
	 * QyzxFeebackAccessory.builder().feebackId(feeback.getId()).opinionUrl(
	 * opinionUrl).build().insert(); } } return ResultUtil.success("意见反馈成功!"); }
	 */
	/**
	 * 意见反馈2
	 */
	@PostMapping(value = "/feedback")
	@ApiOperation(value = "意见反馈", httpMethod = "POST", notes = "接口发布说明")
	public Result<String> feedback(@CurrentUser UserBean userBean, @RequestBody FeebackDto feebackDto) {
		String opinionText = feebackDto.getOpinionText();
		List<String> urlList = feebackDto.getUrlList();
		QyzxSuggestionFeeback qs = QyzxSuggestionFeeback.builder().orgCode(userBean.getOrgCode()).empNum(userBean.getEmpNum()).opinionText(opinionText).bugType(1).createTime(new Date()).build();
		
		boolean tof = qs.insert();
		Integer feebackId = qs.getId();
		if (tof) {
			for (String str : urlList) {
				QyzxFeebackAccessory.builder().feebackId(feebackId).opinionUrl(str).build().insert();
			}
			return ResultUtil.data("意见反馈成功!");
		}

		return ResultUtil.data("意见反馈失败!");
	}

	/**
	 * 查看服务列表
	 */
	@GetMapping(value = "/servelist")
	@ApiOperation(value = "查看服务列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<QyzxPayServe>> servelist() {
		List<QyzxPayServe> list = new LambdaQueryChainWrapper<QyzxPayServe>(qyzxPayServeMapper)
				.select(QyzxPayServe::getName, QyzxPayServe::getNum, QyzxPayServe::getSpecialPrice,
						QyzxPayServe::getOriginalPrice, QyzxPayServe::getSort, QyzxPayServe::getUnit,
						QyzxPayServe::getRemark)
				.orderByAsc(QyzxPayServe::getId).list();
		return ResultUtil.data(list, "查看服务列表成功");
	}

	/**
	 * 购买服务(添加服务计算,添加购买记录)
	 * 
	 * @param
	 * @return
	 */
	@PostMapping(value = "/buyserve")
	@ApiOperation(value = "购买服务(添加服务计算,添加购买记录)", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxLogBuy> buyserve(@CurrentUser UserBean userBean, @RequestBody QyzxLogBuy qyzxLogBuy) {
		Integer payServeId = qyzxLogBuy.getPayServeId();// 套餐的付费服务的id
		Integer num = qyzxLogBuy.getNum();// 套餐的购买次数
		QyzxPayServe qyzxPayServe = QyzxPayServe.builder().id(payServeId).build().selectById();
		Integer code = qyzxPayServe.getCode();// 获取套餐的付费服务代码

		Double o = qyzxPayServe.getOriginalPrice();
		Double s = qyzxPayServe.getSpecialPrice();
		Double price = (s != null && s > 0d ? s : o);
		Double money = NumberUtil.round(NumberUtil.mul(price, num), 4).doubleValue();
		log.info("money:" + money);
		Date date = new Date();
		log.info("date:" + date);
		// 添加购买记录表
		QyzxLogBuy.builder().empNum(userBean.getEmpNum()).payServeId(payServeId).money(money).num(num).createTime(date)
				.build().insertOrUpdate();
		// 添加或修改服务计算表
		Integer number = qyzxPayServe.getNum();
		QueryWrapper<QyzxAttaFwjsb> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("emp_num", userBean.getEmpNum()).eq("code", code);
		Integer result = QyzxAttaFwjsb.builder().build().selectCount(queryWrapper);
		if (result != null && result > 0) {
			QyzxAttaFwjsb fwjb = QyzxAttaFwjsb.builder().build().selectOne(queryWrapper);
			// 续费
			QyzxAttaFwjsb.builder().id(fwjb.getId()).empNum(userBean.getEmpNum()).code(code)
					.hasNum(fwjb.getHasNum() + num * number).createTime(date).build().insertOrUpdate();
		} else {
			// 新增
			QyzxAttaFwjsb.builder().empNum(userBean.getEmpNum()).code(code).hasNum(num * number).createTime(date)
					.build().insertOrUpdate();
		}
		return ResultUtil.data(qyzxLogBuy, "添加/修改发票资料成功");
	}

	// 使用系统购买服务
	/**
	 * 获取服务计算
	 * 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/fwjs")
	@ApiOperation(value = "查看服务计算", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<QyzxAttaFwjsb>> fwjs(@CurrentUser UserBean userBean) {
		List<QyzxAttaFwjsb> qyzxAttaFpgl = QyzxAttaFwjsb.builder().build()
				.selectList(new QueryWrapper<QyzxAttaFwjsb>().eq("emp_num", userBean.getEmpNum()));
		return ResultUtil.data(qyzxAttaFpgl, "获取服务计算成功");
	}

	/**
	 * 获取购买记录
	 * 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/gmjl")
	@ApiOperation(value = "获取购买记录", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<QyzxLogBuy>> selectgmjl(@CurrentUser UserBean userBean) {
		List<QyzxLogBuy> qyzxLogBuy = QyzxLogBuy.builder().build()
				.selectList(new QueryWrapper<QyzxLogBuy>().eq("emp_num", userBean.getEmpNum()));
		return ResultUtil.data(qyzxLogBuy, "获取购买记录成功");
	}

	/**
	 * 查询购买记录
	 * 
	 * @param
	 * @return
	 */
	@PostMapping(value = "/gmjlquery")
	@ApiOperation(value = "查询购买记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> querygmjl(@CurrentUser UserBean userBean, @RequestBody AttaFpglQueryDto attaFpglQueryDto) {

		Integer empNum = userBean.getEmpNum();
		attaFpglQueryDto.setEmpNum(empNum);

		IPage<LogBuyDto> page = new Page<LogBuyDto>(
				attaFpglQueryDto.getCurrentPage() == null ? 1 : attaFpglQueryDto.getCurrentPage(),
				attaFpglQueryDto.getTotalPage() == null ? 10 : attaFpglQueryDto.getTotalPage());

		List<LogBuyDto> logBuyDto = qyzxLogBuyMapper.selectByName(page, attaFpglQueryDto);

		return ResultUtil.data(page, logBuyDto, "查询成功");
	}

	/**
	 * 账号管理 获取账号
	 * 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/adminlist/{page}/{limit}")
	@ApiOperation(value = "获取账号", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> adminlist(@CurrentUser UserBean userBean, @PathVariable("page") Integer page,
			@PathVariable("limit") Integer limit) {
		IPage<AdminListDto> page1 = new Page<AdminListDto>(page, limit);
		return ResultUtil.data(page1, qyzxEmpEntAssoMapper.adminlist(page1, userBean.getOrgCode()), "获取账号");
	}
	
	@Autowired
	private QyzxOperLogMapper qyzxOperLogMapper;
	
	/**
	 * 查询-操作日志
	 * 
	 * @param
	 * @return
	 */
	@PostMapping(value = "/select_oper_log")
	@ApiOperation(value = "查询-操作日志", httpMethod = "POST", notes = "查询-操作日志")
	public Result<Object> selectOperLog(@CurrentUser UserBean userBean,@RequestBody QyzxOperLogQuaryDto qyzxOperLogQuaryDto) {
		IPage<QyzxOperLog> page = new Page<QyzxOperLog>(
				qyzxOperLogQuaryDto.getCurrentPage() == null ? 1 : qyzxOperLogQuaryDto.getCurrentPage(),
						qyzxOperLogQuaryDto.getTotalPage() == null ? 10 : qyzxOperLogQuaryDto.getTotalPage());
		
		qyzxOperLogQuaryDto.setOrgCode(userBean.getOrgCode());
		IPage<QyzxOperLog> pages = qyzxOperLogMapper.selectPageByQuery(page, qyzxOperLogQuaryDto);
		List<QyzxOperLog> listOl = pages.getRecords();
		
		return ResultUtil.data(pages, listOl, "操作成功!");
	}
	
	/**
	 * 删除-操作日志
	 * 
	 * @param
	 * @return
	 */
	@DeleteMapping(value = "/delete_oper_log")
	@ApiOperation(value = "删除-操作日志", httpMethod = "DELETE", notes = "查询-操作日志")
	public Result<Object> deleteOperLog(@CurrentUser UserBean userBean,@RequestBody Integer[] ids) {
		
		ArrayList<Integer> list = CollUtil.toList(ids);
		int delCount = qyzxOperLogMapper.deleteBatchIds(list);
		
		return ResultUtil.data(delCount, "操作成功!");
	}

}