package com.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;

import com.entity.GuapaishenqingEntity;
import com.entity.view.GuapaishenqingView;

import com.service.GuapaishenqingService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MPUtil;
import com.utils.MapUtils;
import com.utils.CommonUtil;
import java.io.IOException;

/**
 * 挂牌申请
 * 后端接口
 * @author 
 * @email 
 * @date 2030-03-20 23:07:14
 */
@RestController
@RequestMapping("/guapaishenqing")
public class GuapaishenqingController {
    @Autowired
    private GuapaishenqingService guapaishenqingService;




    



    /**
     * 后端列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,GuapaishenqingEntity guapaishenqing,
		HttpServletRequest request){
		String tableName = request.getSession().getAttribute("tableName").toString();
		if(tableName.equals("jiashiyuan")) {
			guapaishenqing.setZhanghao((String)request.getSession().getAttribute("username"));
		}
		if(tableName.equals("gongzuorenyuan")) {
			guapaishenqing.setYuangongzhanghao((String)request.getSession().getAttribute("username"));
		}
        EntityWrapper<GuapaishenqingEntity> ew = new EntityWrapper<GuapaishenqingEntity>();

		PageUtils page = guapaishenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, guapaishenqing), params), params));

        return R.ok().put("data", page);
    }
    
    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,GuapaishenqingEntity guapaishenqing, 
		HttpServletRequest request){
        EntityWrapper<GuapaishenqingEntity> ew = new EntityWrapper<GuapaishenqingEntity>();

		PageUtils page = guapaishenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, guapaishenqing), params), params));
        return R.ok().put("data", page);
    }



	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( GuapaishenqingEntity guapaishenqing){
       	EntityWrapper<GuapaishenqingEntity> ew = new EntityWrapper<GuapaishenqingEntity>();
      	ew.allEq(MPUtil.allEQMapPre( guapaishenqing, "guapaishenqing")); 
        return R.ok().put("data", guapaishenqingService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(GuapaishenqingEntity guapaishenqing){
        EntityWrapper< GuapaishenqingEntity> ew = new EntityWrapper< GuapaishenqingEntity>();
 		ew.allEq(MPUtil.allEQMapPre( guapaishenqing, "guapaishenqing")); 
		GuapaishenqingView guapaishenqingView =  guapaishenqingService.selectView(ew);
		return R.ok("查询挂牌申请成功").put("data", guapaishenqingView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        GuapaishenqingEntity guapaishenqing = guapaishenqingService.selectById(id);
        return R.ok().put("data", guapaishenqing);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        GuapaishenqingEntity guapaishenqing = guapaishenqingService.selectById(id);
        return R.ok().put("data", guapaishenqing);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GuapaishenqingEntity guapaishenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(guapaishenqing);
        guapaishenqingService.insert(guapaishenqing);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody GuapaishenqingEntity guapaishenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(guapaishenqing);
        guapaishenqingService.insert(guapaishenqing);
        return R.ok();
    }





    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    public R update(@RequestBody GuapaishenqingEntity guapaishenqing, HttpServletRequest request){
        //ValidatorUtils.validateEntity(guapaishenqing);
        guapaishenqingService.updateById(guapaishenqing);//全部更新
        return R.ok();
    }

    /**
     * 审核
     */
    @RequestMapping("/shBatch")
    @Transactional
    public R update(@RequestBody Long[] ids, @RequestParam String sfsh, @RequestParam String shhf){
        List<GuapaishenqingEntity> list = new ArrayList<GuapaishenqingEntity>();
        for(Long id : ids) {
            GuapaishenqingEntity guapaishenqing = guapaishenqingService.selectById(id);
            guapaishenqing.setSfsh(sfsh);
            guapaishenqing.setShhf(shhf);
            list.add(guapaishenqing);
        }
        guapaishenqingService.updateBatchById(list);
        return R.ok();
    }


    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        guapaishenqingService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
    
	










}
