| package com.matrix.system.shopXcx.action; | 
|   | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.constance.SystemMessageCode; | 
| import com.matrix.core.pojo.PaginationVO; | 
| import com.matrix.core.tools.ModelUtils; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.core.constance.SystemErrorCode; | 
| import com.matrix.core.anotations.RemoveRequestToken; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.common.constance.AppConstance; | 
| import com.matrix.system.hive.action.util.QueryUtil; | 
| import com.matrix.system.shopXcx.dao.ShopInvoiceDao; | 
| import org.springframework.beans.propertyeditors.CustomDateEditor; | 
| import org.springframework.stereotype.Controller; | 
| import com.matrix.core.exception.GlobleException; | 
| import org.springframework.web.bind.WebDataBinder; | 
| import org.springframework.web.bind.annotation.InitBinder; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
| import com.matrix.core.anotations.SaveRequestToken; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.tools.WebUtil; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
|   | 
| import java.text.SimpleDateFormat; | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Map; | 
| import com.matrix.system.shopXcx.bean.ShopInvoice; | 
| import org.springframework.web.servlet.ModelAndView; | 
|   | 
| /** | 
|  * @description 发票 | 
|  * @author jiangyouyao | 
|  * @date 2019-06-15 11:47 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/shopInvoice") | 
| public class ShopInvoiceAction { | 
|   | 
|     @Autowired | 
|     private ShopInvoiceDao shopInvoiceDao; | 
|      | 
|     //记录编辑前的值Before_Edit_Value | 
|     public static final String BEV="ShopInvoice_BEV"; | 
|      | 
|      | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value =  "/showList") | 
|     public @ResponseBody AjaxResult showList(ShopInvoice shopInvoice, PaginationVO pageVo) { | 
|         QueryUtil.setQueryLimitCom(shopInvoice); | 
|         List<ShopInvoice> dataList = shopInvoiceDao.selectInPage(shopInvoice, pageVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, | 
|                 shopInvoiceDao.selectTotalRecord(shopInvoice)); | 
|         return result; | 
|     } | 
|         | 
|     /** | 
|      * 新增 | 
|      */    | 
|     @RemoveRequestToken     | 
|        @RequestMapping(value =  "/addShopInvoice") | 
|     public @ResponseBody AjaxResult addShopInvoice(ShopInvoice shopInvoice) { | 
|         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         shopInvoice.setCreateBy(user.getSuName()); | 
|         shopInvoice.setUpdateBy(user.getSuName()); | 
|         shopInvoice.setCompanyId(user.getCompanyId()); | 
|          int i=shopInvoiceDao.insert(shopInvoice); | 
|          if(i > 0){ | 
|              return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "发票"); | 
|          }else { | 
|             throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * | 
|      * @Description (TODO 自定义数据绑定, 解决此问题) | 
|      * @param binder | 
|      */ | 
|     @InitBinder | 
|     public void initBinder(WebDataBinder binder) { | 
|         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | 
|         dateFormat.setLenient(false); | 
|         binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); | 
|     } | 
|      | 
|      | 
|     /** | 
|      * 修改 | 
|      */    | 
|     @RemoveRequestToken     | 
|        @RequestMapping(value =  "/modifyShopInvoice") | 
|     public @ResponseBody AjaxResult modifyShopInvoice(ShopInvoice newShopInvoice) { | 
|            ShopInvoice oldShopInvoice = WebUtil.getSessionAttribute(BEV); | 
|         int i = 0; | 
|         Map<String, Object> modifyMap = null; | 
|         try { | 
|             if (!ModelUtils.isModified(oldShopInvoice, newShopInvoice)) { | 
|                 i = MatrixConstance.DML_SUCCESSS; | 
|             } | 
|             modifyMap = ModelUtils.comparePojo2Map(oldShopInvoice, newShopInvoice); | 
|         } catch (Exception e) { | 
|             throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopInvoice); | 
|         } | 
|         if (modifyMap.size() > 0) { | 
|             if(null != newShopInvoice.getInvoExpressCode() && !"".equals(newShopInvoice.getInvoExpressCode())){ | 
|                 modifyMap.put("invoState", AppConstance.SENDBYPOST); | 
|             } | 
|             modifyMap.put("invoId", oldShopInvoice.getInvoId()); | 
|             shopInvoiceDao.updateByMap(modifyMap); | 
|         } | 
|         i = MatrixConstance.DML_SUCCESSS; | 
|         WebUtil.removeSessionAttribute(BEV); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "发票"); | 
|         } else { | 
|             throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); | 
|         } | 
|     } | 
|      | 
|      | 
|      | 
|      | 
|        /** | 
|      * 进入修改界面 | 
|      */    | 
|     @SaveRequestToken | 
|        @RequestMapping(value =  "/editForm") | 
|     public ModelAndView editForm(Integer id) { | 
|         ShopInvoice shopInvoice = new ShopInvoice(); | 
|         ModelAndView modelAndView = new ModelAndView("admin/shop/shopInvoice-form"); | 
|         if (id != null) { | 
|             shopInvoice = shopInvoiceDao.selectById(id); | 
|             WebUtil.setSessionAttribute(BEV, shopInvoice); | 
|         } | 
|         modelAndView.addObject("obj",shopInvoice); | 
|         return modelAndView; | 
|     } | 
|         | 
|         | 
|        /** | 
|      * 删除 | 
|      */   | 
|      @RequestMapping(value = "/del") | 
|     public @ResponseBody AjaxResult del(String keys) { | 
|         List<String> ids = StringUtils.strToCollToString(keys, ","); | 
|         int i =  shopInvoiceDao.deleteByIds(ids); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); | 
|         } else { | 
|             throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); | 
|         } | 
|     } | 
|    | 
| } |