package cn.com.lzt.clearingpoint.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.daju.mix.dao.entity.TBArchivesPlace; import com.daju.mix.dao.service.ITBArchivesPlaceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.tag.core.easyui.TagUtil; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Objects; import java.util.Optional; /** * 清运点 管理 */ @Slf4j @Controller @RequestMapping("/ClearingPointController") public class ClearingPointController { private static final String BASE_PATH = "cn/com/lzt/clearingpoint/"; private static final int CLEAN_TYPE = 33; private static final String ARCHIVESPLACE = "archivesPlace"; @Resource private ITBArchivesPlaceService archivesPlaceService; @RequestMapping(params = "view") public ModelAndView index() { System.out.println("--------------"); return new ModelAndView(BASE_PATH.concat("clearingpoint")); } /** * 分页查询 清运点 * * @param tbArchivesPlace * @param response * @param dataGrid */ @RequestMapping(params = "datagrid") public void datagrid(TBArchivesPlace tbArchivesPlace, HttpServletResponse response, DataGrid dataGrid) throws Exception { //空对象判断 Optional.ofNullable(tbArchivesPlace).orElseThrow(() -> new Exception("场所档案对象不能为null")); //条件 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(TBArchivesPlace::getType, CLEAN_TYPE) .isNotNull(TBArchivesPlace::getTimeStatus) .eq(StringUtils.isNotBlank(tbArchivesPlace.getCode()), TBArchivesPlace::getCode, tbArchivesPlace.getCode()) .like(StringUtils.isNotBlank(tbArchivesPlace.getName()), TBArchivesPlace::getName, StringUtils.isNotBlank(tbArchivesPlace.getName()) ? tbArchivesPlace.getName().trim():tbArchivesPlace.getName()) .eq(StringUtils.isNotBlank(tbArchivesPlace.getPrepTime()), TBArchivesPlace::getPrepTime, tbArchivesPlace.getPrepTime()) .eq(StringUtils.isNotBlank(tbArchivesPlace.getLateTime()), TBArchivesPlace::getLateTime, tbArchivesPlace.getLateTime()) .eq(StringUtils.isNotBlank(tbArchivesPlace.getTimeStatus()), TBArchivesPlace::getTimeStatus, tbArchivesPlace.getTimeStatus()); Page list = archivesPlaceService.page(new Page<>(dataGrid.getPage(), dataGrid.getRows()), queryWrapper); TagUtil.datagrid(response, dataGrid, list); } /** * 新建页面 * * @param archivesPlace * @param req * @return */ @RequestMapping(params = "goAdd") public ModelAndView goAdd(TBArchivesPlace archivesPlace, HttpServletRequest req) throws Exception { //空对象判断 Optional.ofNullable(archivesPlace).orElseThrow(() -> new Exception("场所档案对象不能为null")); if (StringUtil.isNotEmpty(archivesPlace.getId())) { TBArchivesPlace byId = archivesPlaceService.getById(archivesPlace.getId()); req.setAttribute(ARCHIVESPLACE, byId); } return new ModelAndView(BASE_PATH.concat("clearingpoint-add")); } /** * 录入数据 or 更新 * * @param archivesPlace * @param request * @return */ @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(TBArchivesPlace archivesPlace, HttpServletRequest request) { AjaxJson j = new AjaxJson(); String message; if (Objects.isNull(archivesPlace) || Objects.isNull(archivesPlace.getId()) || StringUtils.isBlank(archivesPlace.getPrepTime()) || StringUtils.isBlank(archivesPlace.getLateTime()) || StringUtils.isBlank(archivesPlace.getTimeStatus())) { message = "清运点`0档案信息有误"; j.setMsg(message); j.setSuccess(false); return j; } boolean saveOrUpdate; LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.set(TBArchivesPlace::getPrepTime, archivesPlace.getPrepTime()) .set(TBArchivesPlace::getLateTime, archivesPlace.getLateTime()) .set(TBArchivesPlace::getTimeStatus, archivesPlace.getTimeStatus()) .eq(TBArchivesPlace::getId, archivesPlace.getId()); saveOrUpdate = archivesPlaceService.update(updateWrapper); if (saveOrUpdate) { message = "清运点档案保存成功"; j.setSuccess(true); } else { message = "清运点档案保存失败"; j.setSuccess(false); } j.setMsg(message); return j; } /** * 更新操作 * * @param archivesPlace * @param req * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(TBArchivesPlace archivesPlace, HttpServletRequest req) throws Exception { TBArchivesPlace one = archivesPlaceService.getById(archivesPlace.getId()); // 空对象判断 Optional.ofNullable(one).orElseThrow(() -> new Exception("不存在当前清运点档案")); req.setAttribute(ARCHIVESPLACE, one); return new ModelAndView(BASE_PATH.concat("clearingpoint-update")); } /** * 删除清运点的 信息 * * @param archivesPlace * @return */ @RequestMapping(params = "logicDel") @ResponseBody public AjaxJson logicDel(@RequestBody TBArchivesPlace archivesPlace) { AjaxJson j = new AjaxJson(); String message; //空对象判断 if (Objects.isNull(archivesPlace) || Objects.isNull(archivesPlace.getId())) { message = "清运点信息删除有误"; j.setMsg(message); j.setSuccess(false); return j; } LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper .set(TBArchivesPlace::getTimeStatus, null) .set(TBArchivesPlace::getType, CLEAN_TYPE) .eq(TBArchivesPlace::getId, archivesPlace.getId()); boolean b = archivesPlaceService.update(updateWrapper); if (b) { message = "清运点删除成功"; j.setSuccess(Boolean.TRUE); } else { message = "清运点删除失败"; j.setSuccess(Boolean.FALSE); } j.setMsg(message); return j; } /** * 清运点选择 * * @return */ @RequestMapping(params = "CleanSelect") public ModelAndView userSelect() { return new ModelAndView(BASE_PATH.concat("clearingpoint-select")); } /** * 清运点选择 分页 * * @param tbArchivesPlace * @param response * @param dataGrid */ @RequestMapping(params = "datagrid2") public void datagrid2(TBArchivesPlace tbArchivesPlace, HttpServletResponse response, DataGrid dataGrid) throws Exception { //空对象判断 Optional.ofNullable(tbArchivesPlace).orElseThrow(() -> new Exception("场所档案对象不能为null")); //条件 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(TBArchivesPlace::getType, CLEAN_TYPE).isNull(TBArchivesPlace::getTimeStatus); if (StringUtils.isNotBlank(tbArchivesPlace.getCode())) { queryWrapper.eq(TBArchivesPlace::getCode, tbArchivesPlace.getCode()); } if (StringUtils.isNotBlank(tbArchivesPlace.getName())) { queryWrapper.like(TBArchivesPlace::getName, tbArchivesPlace.getName().trim()); } Page list = archivesPlaceService.page(new Page<>(dataGrid.getPage(), dataGrid.getRows()), queryWrapper); TagUtil.datagrid(response, dataGrid, list); } }