package com.matrix.system.hive.action; 
 | 
  
 | 
import com.matrix.core.anotations.RemoveRequestToken; 
 | 
import com.matrix.core.anotations.SaveRequestToken; 
 | 
import com.matrix.core.constance.MatrixConstance; 
 | 
import com.matrix.core.exception.GlobleException; 
 | 
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.bean.SysUsers; 
 | 
import com.matrix.system.common.tools.ResponseHeadUtil; 
 | 
import com.matrix.system.constance.Dictionary; 
 | 
import com.matrix.system.hive.action.util.QueryUtil; 
 | 
import com.matrix.system.hive.bean.SysAllotDetail; 
 | 
import com.matrix.system.hive.bean.SysAllottedInfo; 
 | 
import com.matrix.system.hive.dao.SysAllotDetailDao; 
 | 
import com.matrix.core.tools.DateUtil; 
 | 
import com.matrix.system.hive.service.SysAllottedInfoService; 
 | 
import org.springframework.stereotype.Controller; 
 | 
import org.springframework.ui.ModelMap; 
 | 
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.OutputStream; 
 | 
import java.net.URLDecoder; 
 | 
import java.net.URLEncoder; 
 | 
import java.util.ArrayList; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * 调拨 
 | 
 * 
 | 
 * @author jiangyouyao 
 | 
 * @date 2016-07-20 
 | 
 */ 
 | 
@Controller 
 | 
@RequestMapping(value = "admin/allotted") 
 | 
public class AllottedInfoController extends BaseController { 
 | 
  
 | 
  
 | 
    @Resource 
 | 
    private SysAllottedInfoService currentService; 
 | 
  
 | 
    @Resource 
 | 
    private SysAllotDetailDao sysAllotDetailDao; 
 | 
  
 | 
    /** 
 | 
     * 列表显示 
 | 
     */ 
 | 
    @RequestMapping(value = "/showList") 
 | 
    public @ResponseBody 
 | 
    AjaxResult showList(SysAllottedInfo sysAllottedInfo, PaginationVO pageVo) { 
 | 
        QueryUtil.setQueryLimitCom(sysAllottedInfo); 
 | 
        List<SysAllottedInfo> dataList = currentService.findInPage(sysAllottedInfo, pageVo); 
 | 
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,  dataList, currentService.findTotal(sysAllottedInfo)); 
 | 
        return result; 
 | 
  
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增或修改页面 
 | 
     */ 
 | 
    @RequestMapping(value = "/addOrModify") 
 | 
    @RemoveRequestToken 
 | 
    public @ResponseBody 
 | 
    AjaxResult addOrModify(SysAllottedInfo sysAllottedInfo) { 
 | 
        //调入仓库和调出仓库不能是同一个仓库 
 | 
        if (sysAllottedInfo.getAllottedOutstoreId() == sysAllottedInfo.getAllottedInstoreId()) { 
 | 
            throw new GlobleException("调入仓库和调出仓库不能相同"); 
 | 
        } 
 | 
        if (sysAllottedInfo.getId() != null) { 
 | 
  
 | 
            return modify(currentService, sysAllottedInfo, "调拨"); 
 | 
        } else { 
 | 
            QueryUtil.setQueryLimitCom(sysAllottedInfo); 
 | 
            return add(currentService, sysAllottedInfo, "调拨"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入门店调拨修改界面 
 | 
     */ 
 | 
    @RequestMapping(value = "/editForm") 
 | 
    @SaveRequestToken 
 | 
    public String editForm(Long id) { 
 | 
        SysAllottedInfo sysAllottedInfo; 
 | 
        if (id != null) { 
 | 
            sysAllottedInfo = currentService.findById(id); 
 | 
            List<SysAllotDetail> sysAllotDetails = sysAllotDetailDao.selectAllottedDetailByOrderId(id); 
 | 
            sysAllottedInfo.setSysAllotDetails(sysAllotDetails); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysAllottedInfo); 
 | 
        } 
 | 
        return "admin/hive/store/allottedinfo-form"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入库存调拨修改界面 
 | 
     */ 
 | 
    @RequestMapping(value = "/editFormAll") 
 | 
    @SaveRequestToken 
 | 
    public String editFormAll(Long id) { 
 | 
        SysAllottedInfo sysAllottedInfo; 
 | 
        if (id != null) { 
 | 
            sysAllottedInfo = currentService.findById(id); 
 | 
            List<SysAllotDetail> sysAllotDetails = sysAllotDetailDao.selectAllottedDetailByOrderId(id); 
 | 
            sysAllottedInfo.setSysAllotDetails(sysAllotDetails); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysAllottedInfo); 
 | 
        } 
 | 
        return "admin/hive/instore/allottedinfo-form"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 删除 
 | 
     */ 
 | 
    @RequestMapping(value = "/del") 
 | 
    public @ResponseBody 
 | 
    AjaxResult del(String keys) { 
 | 
  
 | 
        return remove(currentService, keys); 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 进入查看页面 
 | 
     */ 
 | 
    @RequestMapping(value = "/lookInfo") 
 | 
    public String lookInfo(Long id) { 
 | 
        SysAllottedInfo sysAllottedInfo; 
 | 
        if (id != null) { 
 | 
            sysAllottedInfo = currentService.findById(id); 
 | 
            List<SysAllotDetail> sysAllotDetails = sysAllotDetailDao.selectAllottedDetailByOrderId(id); 
 | 
            sysAllottedInfo.setSysAllotDetails(sysAllotDetails); 
 | 
            int count = 0; 
 | 
            for (SysAllotDetail allDetail : sysAllottedInfo.getSysAllotDetails()) { 
 | 
                count += allDetail.getReceiveTotal(); 
 | 
            } 
 | 
            WebUtil.getRequest().setAttribute("count", count); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysAllottedInfo); 
 | 
        } 
 | 
        return "admin/hive/instore/allottedinfo-look"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 进入审核页面 
 | 
     */ 
 | 
    @RequestMapping(value = "/checkInfo") 
 | 
    public String checkInfo(Long id) { 
 | 
        SysAllottedInfo sysAllottedInfo; 
 | 
        if (id != null) { 
 | 
            sysAllottedInfo = currentService.findById(id); 
 | 
            List<SysAllotDetail> sysAllotDetails = sysAllotDetailDao.selectAllottedDetailByOrderId(id); 
 | 
            sysAllottedInfo.setSysAllotDetails(sysAllotDetails); 
 | 
            WebUtil.getRequest().setAttribute("obj", sysAllottedInfo); 
 | 
        } 
 | 
        return "admin/hive/instore/allottedinfo-check"; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 审核 
 | 
     */ 
 | 
  
 | 
    @RequestMapping(value = "/check") 
 | 
    public @ResponseBody 
 | 
    AjaxResult check(SysAllottedInfo sysAllottedInfo) { 
 | 
  
 | 
        int i = currentService.check(sysAllottedInfo); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核成功"); 
 | 
        } else { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 撤销审核 
 | 
     * 
 | 
     * @param sysAllottedInfo 
 | 
     * @return AjaxResult    返回类型 
 | 
     * @throws 
 | 
     * @Title: unCheck 
 | 
     * @author:jyy 
 | 
     * @date 2016年8月22日 下午7:56:05 
 | 
     */ 
 | 
  
 | 
    @RequestMapping(value = "/unCheck") 
 | 
    public @ResponseBody 
 | 
    AjaxResult unCheck(SysAllottedInfo sysAllottedInfo) { 
 | 
  
 | 
        int i = currentService.unCheck(sysAllottedInfo); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销成功"); 
 | 
        } else { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 确认发货 
 | 
     * 
 | 
     * @param sysAllottedInfo 
 | 
     * @return AjaxResult    返回类型 
 | 
     * @throws 
 | 
     * @Title: sendGoods 
 | 
     * @author:jyy 
 | 
     * @date 2016年8月23日 上午9:22:18 
 | 
     */ 
 | 
    @RequestMapping(value = "/sendGoods") 
 | 
    public @ResponseBody 
 | 
    AjaxResult sendGoods(SysAllottedInfo sysAllottedInfo) { 
 | 
  
 | 
        int i = currentService.sendGoods(sysAllottedInfo); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); 
 | 
        } else { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 确认收货 
 | 
     * 
 | 
     * @param sysAllottedInfo 
 | 
     * @return AjaxResult    返回类型 
 | 
     * @throws 
 | 
     * @Title: rejectGoods 
 | 
     * @author:jyy 
 | 
     * @date 2016年8月23日 上午9:22:18 
 | 
     */ 
 | 
    @RequestMapping(value = "/rejectGoods") 
 | 
    public @ResponseBody 
 | 
    AjaxResult rejectGoods(SysAllottedInfo sysAllottedInfo) { 
 | 
  
 | 
        int i = currentService.rejectGoods(sysAllottedInfo); 
 | 
        if (i > 0) { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "收货成功"); 
 | 
        } else { 
 | 
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销失败"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 不予审核方法,做权限控制 
 | 
     */ 
 | 
    @RequestMapping(value = "/addcheckremark") 
 | 
    public @ResponseBody 
 | 
    AjaxResult addcheckremark(SysAllottedInfo sysAllottedInfo) { 
 | 
  
 | 
        //1.判断是否有修改的权限 
 | 
        SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        if (user.getRoleName().contains(Dictionary.USER_ROLE_PLZG) || user.getRoleName().contains(Dictionary.USER_ROLE_CCZG)) { 
 | 
            //2.去数据库判断该单的状态,如果审核通过不能修改 
 | 
            SysAllottedInfo checkAllottedInfo = currentService.findById(sysAllottedInfo.getId()); 
 | 
            if (checkAllottedInfo != null && !(checkAllottedInfo.getCheckStatus().equals(Dictionary.CHECK_STATUS_DSH))) { 
 | 
                throw new GlobleException("该单据状态为" + checkAllottedInfo.getCheckStatus() + ",不可再审核!"); 
 | 
            } 
 | 
            //3、满足条件则更改 
 | 
            sysAllottedInfo.setCheckStatus(Dictionary.CHECK_STATUS_SHWTG); 
 | 
            int count = currentService.update(sysAllottedInfo); 
 | 
            if (count > 0) { 
 | 
                return new AjaxResult(AjaxResult.STATUS_SUCCESS, null); 
 | 
            } else { 
 | 
                return new AjaxResult(AjaxResult.STATUS_SUCCESS, null); 
 | 
            } 
 | 
        } else { 
 | 
            throw new GlobleException("审核人必须为配料主管或者仓库主管!"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * @param @param  model 
 | 
     * @param @param  request 
 | 
     * @param @param  response 
 | 
     * @param @param  vipInfo 
 | 
     * @param @return 设定文件 
 | 
     * @return ModelAndView    返回类型 
 | 
     * @throws 
 | 
     * @author jiangyouyao 
 | 
     * @Title: report 
 | 
     *  调拨单导出 
 | 
     */ 
 | 
    @RequestMapping(value = "/exportExcel") 
 | 
    public void report(ModelMap model, HttpServletRequest request, HttpServletResponse response, SysAllottedInfo sysAllottedInfo, String gridName) throws Exception { 
 | 
  
 | 
  
 | 
  
 | 
        if (sysAllottedInfo.getCheckStatus() != null && !"".equals(sysAllottedInfo.getCheckStatus())) { 
 | 
            sysAllottedInfo.setCheckStatus(URLDecoder.decode(sysAllottedInfo.getCheckStatus(), "UTF-8")); 
 | 
        } 
 | 
        if (sysAllottedInfo.getAllottedType() != null && !"".equals(sysAllottedInfo.getAllottedType())) { 
 | 
            sysAllottedInfo.setAllottedType(URLDecoder.decode(sysAllottedInfo.getAllottedType(), "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.setQueryLimitCom(sysAllottedInfo); 
 | 
        List<SysAllottedInfo> dataList = currentService.findInPage(sysAllottedInfo, null); 
 | 
        List<List<Object>> list = new ArrayList<>(); 
 | 
        if (dataList.size() > 0) { 
 | 
            for (SysAllottedInfo item : dataList) { 
 | 
                List<Object> temp = new ArrayList<>(); 
 | 
                temp.add(item.getAllottedId()); 
 | 
                temp.add(item.getAllottedType()); 
 | 
                temp.add(item.getAllottedOutstoreName()); 
 | 
                temp.add(item.getAllottedInstoreName()); 
 | 
                temp.add(item.getCheckStatus()); 
 | 
                temp.add(DateUtil.dateToString(item.getAllottedDate(), DateUtil.DATE_FORMAT_MM)); 
 | 
                temp.add(item.getMakingManName()); 
 | 
                temp.add(item.getAppManName()); 
 | 
                temp.add(item.getAllottedRemark()); 
 | 
                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); 
 | 
  
 | 
    } 
 | 
} 
 |