package com.newfiber.api.pc.controller.EventsManage; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.plugins.Page; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.core.support.HttpCode; import com.newfiber.api.core.utils.UUIDPK; import com.newfiber.api.pc.dao.EventsManage.BoundaryTabletDao; import com.newfiber.api.pc.dao.EventsManage.SystemFileDao; import com.newfiber.api.pc.model.EventsManage.BoundaryTablet; import com.newfiber.api.pc.model.EventsManage.BoundaryTabletQuery; import com.newfiber.api.pc.model.EventsManage.SystemFile; import com.newfiber.api.pc.model.EventsManage.SystemFileQuery; import com.newfiber.api.pc.service.RestTemplateService; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by XuChengChao on 2017/12/20. */ @Controller public class BoundaryTabletController { @Autowired private SystemFileDao systemFileDao; @Autowired private BoundaryTabletDao boundaryTabletDao; @Resource private RestTemplateService restTemplateService; /** * 添加界碑/界桩 * @param * @param * @return */ @PostMapping(value = "boundary/addBoundaryTablet",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj addBoundaryTablet(@RequestBody ReqBodyObj<BoundaryTablet> param,HttpServletRequest request){ if (param.getData() == null){ return RespBodyObj.error(HttpCode.BAD_REQUEST); } BoundaryTablet boundaryTablet = param.getData(); String userNo = request.getHeader("userNo"); String userName = restTemplateService.getUserInfo(userNo).getUserName(); boundaryTablet.setCreateUserNo(userNo); boundaryTablet.setCreateUserName(userName); int type = boundaryTablet.getTabletType(); if (type==1){ boundaryTablet.setTabletTypeName("界碑"); } if (type==2){ boundaryTablet.setTabletTypeName("界桩"); } boundaryTablet.setTabletNo(UUIDPK.UUIDGenerator.getUUID()); List<String> pics = boundaryTablet.getPics(); if (pics != null){ String picNo = UUIDPK.UUIDGenerator.getUUID(); for (int i=0;i<pics.size();i++){ if (!(pics.get(i)).isEmpty()){ SystemFile file = new SystemFile(); file.setFileNo(picNo); file.setFileAddress(pics.get(i)); file.setFileName(pics.get(i).substring(pics.get(i).lastIndexOf("/")+1,pics.get(i).length())); file.setCreateUserNo(userNo); int addFile = systemFileDao.insertSelective(file); } } boundaryTablet.setPicNo(picNo); } try { int add = boundaryTabletDao.insertSelective(boundaryTablet); return RespBodyObj.ok(); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } /** * 查询界碑/界桩信息 * @return */ @PostMapping(value = "boundary/selectBoundaryTablet",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj selectBoundaryInfo(@RequestBody ReqBodyObj<Map<String,Object>>param) throws UnsupportedEncodingException { Map<String,Object> map = param.getData(); String str = (String) map.get("str"); Integer page = param.getCurrent(); Integer rows = param.getSize(); String divisionNo = (String) map.get("divisionNo"); Integer tabletType = (Integer) map.get("tabletType"); String tabletNo = (String) map.get("tabletNo"); BoundaryTabletQuery query = new BoundaryTabletQuery(); BoundaryTabletQuery.Criteria criteria = query.createCriteria(); if (page != null && rows != null){ query.setStartRow((page-1)*rows); query.setPageSize(rows); } if (divisionNo != null){ criteria.andDivisionnoEqualTo(divisionNo); } if (str != null && !("".equals(str))){ String str1 = URLDecoder.decode(str,"UTF-8"); criteria.andManageDepartmentLike(str1); } if (tabletType != null){ criteria.andTabletTypeEqualTo(tabletType); } if (tabletNo != null){ criteria.andTabletNoEqualTo(tabletNo); } try { List<BoundaryTablet> list = boundaryTabletDao.selectByExample(query); if (list.size()>0){ for (BoundaryTablet b : list){ String picNo = b.getPicNo(); if (picNo != null && !("".equals(picNo))){ SystemFileQuery query1 = new SystemFileQuery(); query1.createCriteria().andFileNoEqualTo(picNo); List<SystemFile> files = systemFileDao.selectByExample(query1); b.setPicList(files); }else { List<SystemFile> list1 = new ArrayList<>(); list1.add(new SystemFile()); b.setPicList(list1); } } } int count = boundaryTabletDao.countByExample(query); Page page1 = new Page(); page1.setTotal(count); page1.setRecords(list); return RespBodyObj.ok(page1); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } /** * 更新界碑/界桩 * @ * @return */ @PostMapping(value = "boundary/updateBoundaryInfo",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj updateBoundaryTablet(HttpServletRequest request,@RequestBody ReqBodyObj<BoundaryTablet> param){ BoundaryTablet boundaryTablet = param.getData(); String userNo = request.getHeader("userNo"); String userName = restTemplateService.getUserInfo(userNo).getUserName(); boundaryTablet.setUpdateTime(new Date()); boundaryTablet.setUpdateUserName(userName); boundaryTablet.setUpdateUserNo(userNo); Integer type = boundaryTablet.getTabletType(); if (type==1){ boundaryTablet.setTabletTypeName("界碑"); }else { boundaryTablet.setTabletTypeName("界桩"); } String tabletNo = boundaryTablet.getTabletNo(); BoundaryTabletQuery query = new BoundaryTabletQuery(); query.createCriteria().andTabletNoEqualTo(tabletNo); try { int update = boundaryTabletDao.updateByExampleSelective(boundaryTablet,query); if (update > 0){ return RespBodyObj.ok("修改成功"); }else { return RespBodyObj.error("修改失败"); } }catch ( Exception e){ e.printStackTrace(); return RespBodyObj.error("修改失败"); } } /** * 删除界碑/界桩 * @param * @return */ @PostMapping(value = "boundary/deleteBoundaryTablet",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj deleteTablet(@RequestBody ReqBodyObj<String[]> param ){ String [] tabletNo = param.getData(); JSONObject json = new JSONObject(); try { if (tabletNo.length>0){ BoundaryTabletQuery query = new BoundaryTabletQuery(); for (int i=0;i<tabletNo.length;i++){ String No = tabletNo[i]; query.createCriteria().andTabletNoEqualTo(No); int delete = boundaryTabletDao.deleteByExample(query); } } return RespBodyObj.ok("删除成功"); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error("删除失败"); } } }