package com.matrix.system.hive.action; 
 | 
  
 | 
import com.matrix.core.anotations.RemoveRequestToken; 
 | 
import com.matrix.core.anotations.SaveRequestToken; 
 | 
import com.matrix.core.pojo.AjaxResult; 
 | 
import com.matrix.core.pojo.PaginationVO; 
 | 
import com.matrix.core.tools.DateUtil; 
 | 
import com.matrix.core.tools.WebUtil; 
 | 
import com.matrix.core.tools.excl.ExcelSheetPO; 
 | 
import com.matrix.core.tools.excl.ExcelVersion; 
 | 
import com.matrix.system.common.tools.ResponseHeadUtil; 
 | 
import com.matrix.system.hive.action.util.QueryUtil; 
 | 
import com.matrix.system.hive.bean.SysCheckInfo; 
 | 
import com.matrix.core.tools.DateUtil; 
 | 
import com.matrix.system.hive.service.CodeService; 
 | 
import com.matrix.system.hive.service.SysCheckDetailService; 
 | 
import com.matrix.system.hive.service.SysCheckInfoService; 
 | 
import com.matrix.system.hive.service.SysStoreInfoService; 
 | 
import org.springframework.beans.propertyeditors.CustomDateEditor; 
 | 
import org.springframework.stereotype.Controller; 
 | 
import org.springframework.ui.ModelMap; 
 | 
import org.springframework.web.bind.ServletRequestDataBinder; 
 | 
import org.springframework.web.bind.annotation.InitBinder; 
 | 
import org.springframework.web.bind.annotation.RequestMapping; 
 | 
import org.springframework.web.bind.annotation.ResponseBody; 
 | 
  
 | 
import javax.annotation.Resource; 
 | 
import javax.servlet.http.HttpServletRequest; 
 | 
import javax.servlet.http.HttpServletResponse; 
 | 
import java.io.IOException; 
 | 
import java.io.OutputStream; 
 | 
import java.net.URLDecoder; 
 | 
import java.net.URLEncoder; 
 | 
import java.text.SimpleDateFormat; 
 | 
import java.util.ArrayList; 
 | 
import java.util.Date; 
 | 
import java.util.List; 
 | 
  
 | 
  
 | 
/** 
 | 
 * 盘点 
 | 
 * 
 | 
 * @author jiangyouyao 
 | 
 * @date 2016-07-20 
 | 
 */ 
 | 
@Controller 
 | 
@RequestMapping(value = "admin/check") 
 | 
public class CheckInfoController extends BaseController { 
 | 
  
 | 
  
 | 
    @Resource 
 | 
    private SysCheckInfoService currentService; 
 | 
    @Resource 
 | 
    private SysCheckDetailService checkDetailService; 
 | 
    @Resource 
 | 
    private SysStoreInfoService sysStoreInfoService; 
 | 
    @Resource 
 | 
    private CodeService codeService; 
 | 
  
 | 
    /** 
 | 
     * 列表显示 
 | 
     */ 
 | 
    @RequestMapping(value = "/showList") 
 | 
    public @ResponseBody 
 | 
    AjaxResult showList(SysCheckInfo sysCheckInfo, PaginationVO pageVo) { 
 | 
        QueryUtil.setQueryLimit(sysCheckInfo); 
 | 
        return showList(currentService, sysCheckInfo, pageVo); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增或修改页面 
 | 
     */ 
 | 
    @RequestMapping(value = "/addOrModify") 
 | 
    @RemoveRequestToken 
 | 
    public @ResponseBody 
 | 
    AjaxResult addOrModify(SysCheckInfo sysCheckInfo) { 
 | 
        QueryUtil.setQueryLimit(sysCheckInfo); 
 | 
        if (sysCheckInfo.getId() != null) { 
 | 
            return modify(currentService, sysCheckInfo, "盘点"); 
 | 
        } else { 
 | 
            QueryUtil.setQueryLimit(sysCheckInfo); 
 | 
            return add(currentService, sysCheckInfo, "盘点"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入修改界面 
 | 
     */ 
 | 
    @RequestMapping(value = "/editForm") 
 | 
    @SaveRequestToken 
 | 
    public String editForm(Long id) { 
 | 
        SysCheckInfo sysCheckInfo; 
 | 
        if (id != null) { 
 | 
            sysCheckInfo = currentService.findById(id); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysCheckInfo); 
 | 
        } 
 | 
        return "admin/hive/instore/checkinfo-form"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 删除 
 | 
     */ 
 | 
    @RequestMapping(value = "/del") 
 | 
    public @ResponseBody 
 | 
    AjaxResult del(Long keys) { 
 | 
  
 | 
        int i = currentService.removeById(keys); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功"); 
 | 
        } else { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 进入查看页面 
 | 
     */ 
 | 
    @RequestMapping(value = "/lookInfo") 
 | 
    public String lookInfo(Long id) { 
 | 
        SysCheckInfo sysCheckInfo; 
 | 
        if (id != null) { 
 | 
            sysCheckInfo = currentService.findById(id); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysCheckInfo); 
 | 
        } 
 | 
        return "admin/hive/instore/checkinfo-look"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入盘点单明细 
 | 
     */ 
 | 
    @RequestMapping(value = "/toCheckDetail") 
 | 
    public String toCheckDetail(Long checkId) { 
 | 
        SysCheckInfo checkInfo = currentService.findById(checkId); 
 | 
        WebUtil.getRequest().setAttribute("obj", checkInfo); 
 | 
        return "admin/hive/instore/checkDetail-list"; 
 | 
    } 
 | 
  
 | 
    @RequestMapping(value = "/toMobileCheckDetail") 
 | 
    public String toMobileCheckDetail(Long checkId) { 
 | 
        SysCheckInfo checkInfo = currentService.findById(checkId); 
 | 
        WebUtil.getRequest().setAttribute("obj", checkInfo); 
 | 
        return "admin/hive/mobile/store-check-detail"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 审核 
 | 
     */ 
 | 
    @RequestMapping(value = "/check") 
 | 
    public @ResponseBody 
 | 
    AjaxResult check(SysCheckInfo sysCheckInfo) { 
 | 
        int i = currentService.check(sysCheckInfo); 
 | 
        if (i > 0) { 
 | 
  
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核成功"); 
 | 
        } else { 
 | 
  
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核失败"); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    /** 
 | 
     * @param bin 
 | 
     */ 
 | 
    @InitBinder 
 | 
    public void initBinder(ServletRequestDataBinder bin) { 
 | 
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 
 | 
        CustomDateEditor dateEditor = new CustomDateEditor(format, true); 
 | 
        bin.registerCustomEditor(Date.class, dateEditor); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * @param @param  model 
 | 
     * @param @param  request 
 | 
     * @param @param  response 
 | 
     * @param @param  vipInfo 
 | 
     * @param @return 设定文件 
 | 
     * @return ModelAndView    返回类型 
 | 
     * @throws IOException 
 | 
     * @throws 
 | 
     * @author jiangyouyao 
 | 
     * @Title: report 
 | 
     *  盘点单导出 
 | 
     */ 
 | 
    @RequestMapping(value = "/exportExcel") 
 | 
    public void report(ModelMap model, HttpServletRequest request, HttpServletResponse response, SysCheckInfo sysCheckInfo) throws IOException { 
 | 
  
 | 
        if (sysCheckInfo.getCheckType() != null && !"".equals(sysCheckInfo.getCheckType())) { 
 | 
            sysCheckInfo.setCheckType(URLDecoder.decode(sysCheckInfo.getCheckType(), "UTF-8")); 
 | 
        } 
 | 
        if (sysCheckInfo.getCheckStatus() != null && !"".equals(sysCheckInfo.getCheckStatus())) { 
 | 
            sysCheckInfo.setCheckStatus(URLDecoder.decode(sysCheckInfo.getCheckStatus(), "UTF-8")); 
 | 
        } 
 | 
  
 | 
        List<ExcelSheetPO> res = new ArrayList<>(); 
 | 
        ExcelSheetPO orderSheet = new ExcelSheetPO(); 
 | 
        String title = "盘点信息"; 
 | 
        orderSheet.setSheetName(title); 
 | 
        orderSheet.setTitle(title); 
 | 
        String[] header = {"盘点单类型", "盘点单编号", "盘点时间", "制单人", "审核人", "盘点状态", "备注", "审核意见"}; 
 | 
        orderSheet.setHeaders(header); 
 | 
        QueryUtil.setQueryLimit(sysCheckInfo); 
 | 
        List<SysCheckInfo> dataList = currentService.findByModel(sysCheckInfo); 
 | 
        List<List<Object>> list = new ArrayList<>(); 
 | 
        if (dataList.size() > 0) { 
 | 
            for (SysCheckInfo item : dataList) { 
 | 
                List<Object> temp = new ArrayList<>(); 
 | 
                temp.add(item.getCheckType()); 
 | 
                temp.add(item.getCheckNo()); 
 | 
                //时间转为字符串 
 | 
                String strDate = DateUtil.dateToString(item.getCheckDate(), DateUtil.DATE_FORMAT_DD); 
 | 
                temp.add(strDate); 
 | 
                temp.add(item.getMakingManName()); 
 | 
                temp.add(item.getAppManName()); 
 | 
                temp.add(item.getCheckStatus()); 
 | 
                temp.add(item.getRemark()); 
 | 
                temp.add(item.getAppRemark()); 
 | 
                list.add(temp); 
 | 
            } 
 | 
        } 
 | 
        orderSheet.setDataList(list); 
 | 
        res.add(orderSheet); 
 | 
        response = ResponseHeadUtil.setExcelHead(response); 
 | 
        response.setHeader("Content-Disposition", 
 | 
                "attachment;filename=" + URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8")); 
 | 
        OutputStream os = response.getOutputStream(); 
 | 
        com.matrix.core.tools.excl.ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true); 
 | 
  
 | 
    } 
 | 
} 
 |