Bläddra i källkod

添加编辑删除井盖设备信息

zhj 2 år sedan
förälder
incheckning
8e53a20f0f

+ 5 - 0
src/main/java/com/welampiot/common/InterfaceResultEnum.java

@@ -33,6 +33,11 @@ public enum InterfaceResultEnum {
     TRASH_CAN_ADDRESS_UNIQUE_ERROR("0226","垃圾桶设备地址重复","",""),
     LACK_TRASH_CAN_NAME_ERROR("0227","请填写垃圾桶设备名称","",""),
     TRASH_CAN_NAME_UNIQUE_ERROR("0228","垃圾桶设备名称重复","",""),
+    LACK_MANHOLE_NAME_ERROR("0229","请填写井盖设备名称","",""),
+    MANHOLE_NAME_UNIQUE_ERROR("0230","井盖设备名称重复","",""),
+    LACK_MANHOLE_ADDRESS_ERROR("0231","请填写井盖设备地址","",""),
+    MANHOLE_ADDRESS_UNIQUE_ERROR("0232","井盖设备地址重复","",""),
+    LACK_MANHOLE_MODEL_ERROR("0233","请选择井盖设备型号","",""),
     ;
     private String code;
     private String msgCn;

+ 95 - 0
src/main/java/com/welampiot/controller/ManholeController.java

@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 
 /**
  * ClassName: ManholeController
@@ -88,4 +90,97 @@ public class ManholeController {
         ManholeVO vo = manholeService.getHistoryListByDTO(dto);
         return BaseResult.success(vo);
     }
+
+    /**
+     * 添加编辑井盖设备信息
+     * @param request 要添加编辑的井盖属性
+     * @return 更新数据
+     */
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    public BaseResult save(HttpServletRequest request){
+        int version = (int) toolUtils.getRequestContent(request,"version",1);
+        int id = (int) toolUtils.getRequestContent(request,"id",1);
+        int areaId = (int) toolUtils.getRequestContent(request,"areaId",1);
+        int sectionId = (int) toolUtils.getRequestContent(request,"sectionId",1);
+        int model = (int) toolUtils.getRequestContent(request,"model",1);
+        double longitude = request.getParameter("longitude") == null || request.getParameter("longitude").length() == 0 ? 0 : Double.parseDouble(request.getParameter("longitude"));
+        double latitude = request.getParameter("latitude") == null || request.getParameter("latitude").length() == 0 ? 0 : Double.parseDouble(request.getParameter("latitude"));
+        String address = request.getParameter("address");
+        String name = request.getParameter("name");
+        String installDate = request.getParameter("installDate");
+        String expirationDate = request.getParameter("expirationDate");
+
+        ManholeDTO dto = new ManholeDTO();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        dto.setAreaId(areaId);
+        dto.setSectionId(sectionId);
+        dto.setModel(model);
+        dto.setLongitude(longitude);
+        dto.setLatitude(latitude);
+        dto.setAddress(address);
+        dto.setName(name);
+        if (installDate != null && !installDate.equals("")) {
+            try {
+                dto.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(installDate)));
+            } catch (ParseException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        if (expirationDate != null && !expirationDate.equals("")) {
+            try {
+                dto.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(expirationDate)));
+            } catch (ParseException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        if (id == 0) { // 添加
+            if (name == null || name.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_MANHOLE_NAME_ERROR,version);
+            if (address == null || address.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_MANHOLE_ADDRESS_ERROR,version);
+            if (String.valueOf(model).length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_MANHOLE_MODEL_ERROR,version);
+            if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
+            if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
+
+            ManholeDTO manholeDTO = new ManholeDTO();
+            manholeDTO.setName(name);
+            manholeDTO.setSectionId(sectionId);
+            if (manholeService.findByManholeDTO(manholeDTO) > 0) return toolUtils.response(InterfaceResultEnum.MANHOLE_NAME_UNIQUE_ERROR,version);
+            manholeDTO = new ManholeDTO();
+            manholeDTO.setAddress(address);
+            manholeDTO.setSectionId(sectionId);
+            if (manholeService.findByManholeDTO(manholeDTO) > 0) return toolUtils.response(InterfaceResultEnum.MANHOLE_ADDRESS_UNIQUE_ERROR,version);
+            manholeService.addManholeDataByDTO(dto);
+        } else { // 编辑
+            dto.setId(id);
+            ManholeDTO manholeDTO = new ManholeDTO();
+            manholeDTO.setId(id);
+            manholeDTO.setName(name);
+            manholeDTO.setSectionId(sectionId);
+            if (manholeService.findByManholeDTO(manholeDTO) > 0) return toolUtils.response(InterfaceResultEnum.MANHOLE_NAME_UNIQUE_ERROR,version);
+            manholeDTO = new ManholeDTO();
+            manholeDTO.setId(id);
+            manholeDTO.setAddress(address);
+            manholeDTO.setSectionId(sectionId);
+            if (manholeService.findByManholeDTO(manholeDTO) > 0) return toolUtils.response(InterfaceResultEnum.MANHOLE_ADDRESS_UNIQUE_ERROR,version);
+            manholeService.updateManholeDataByDTO(dto);
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
+
+    /**
+     * 删除井盖设备以及相关的日志
+     * @param request 删除设备的id
+     * @return 操作成功
+     */
+    @RequestMapping(value = "/del", method = RequestMethod.POST)
+    public BaseResult del(HttpServletRequest request){
+        int version = (int) toolUtils.getRequestContent(request,"version",1);
+        String id = request.getParameter("id");
+        if (id == null || id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        String[] split = id.split(",");
+        for (String manHoleId : split) {
+            int l = Integer.parseInt(manHoleId);
+            manholeService.deleteManholeDataById(l);
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
 }

+ 10 - 0
src/main/java/com/welampiot/dao/ManholeDao.java

@@ -28,4 +28,14 @@ public interface ManholeDao {
     List<ManholeDTO> getListByDTO(ManholeDTO dto);
 
     List<ManholeDTO> getHistoryListByDTO(ManholeDTO dto);
+
+    void addManholeDataByDTO(ManholeDTO dto);
+
+    void updateManholeDataByDTO(ManholeDTO dto);
+
+    Integer findByManholeDTO(ManholeDTO dto);
+
+    void deleteManholeDataById(@Param("id") Integer id);
+
+    void deleteManholeLogDataById(@Param("id") Integer id);
 }

+ 2 - 0
src/main/java/com/welampiot/dao/TranshInfoDao.java

@@ -38,4 +38,6 @@ public interface TranshInfoDao {
     Integer checkDataByDTO(TranshInfoDTO dto);
 
     void deleteTrashDevById(@Param("id") Integer id);
+
+    void deleteTrashDevLogById(@Param("id") Integer id);
 }

+ 2 - 0
src/main/java/com/welampiot/dto/ManholeDTO.java

@@ -22,6 +22,8 @@ public class ManholeDTO implements Serializable {
     /** 路段、街道id **/
     private Integer sectionId;
 
+    private Integer areaId;
+
     /** 设备地址 **/
     private String address;
 

+ 11 - 0
src/main/java/com/welampiot/service/ManholeService.java

@@ -2,6 +2,7 @@ package com.welampiot.service;
 
 import com.welampiot.dto.ManholeDTO;
 import com.welampiot.vo.ManholeVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -20,4 +21,14 @@ public interface ManholeService {
     ManholeVO getListByDTO(ManholeDTO dto, Integer version);
 
     ManholeVO getHistoryListByDTO(ManholeDTO dto);
+
+    void addManholeDataByDTO(ManholeDTO dto);
+
+    void updateManholeDataByDTO(ManholeDTO dto);
+
+    Integer findByManholeDTO(ManholeDTO dto);
+
+    void deleteManholeDataById(@Param("id") Integer id);
+
+    void deleteManholeLogDataById(@Param("id") Integer id);
 }

+ 2 - 0
src/main/java/com/welampiot/service/TranshInfoService.java

@@ -27,4 +27,6 @@ public interface TranshInfoService {
     BaseResult updateTranshDataByTranshId(TranshInfoDTO dto);
 
     void deleteTrashDevById(Integer id);
+
+    void deleteTrashDevLogById(Integer id);
 }

+ 26 - 0
src/main/java/com/welampiot/service/impl/ManholeServiceImpl.java

@@ -224,4 +224,30 @@ public class ManholeServiceImpl implements ManholeService {
         vo.setList(list);
         return vo;
     }
+
+    @Override
+    public void addManholeDataByDTO(ManholeDTO dto) {
+        manholeDao.addManholeDataByDTO(dto);
+    }
+
+    @Override
+    public void updateManholeDataByDTO(ManholeDTO dto) {
+        manholeDao.updateManholeDataByDTO(dto);
+    }
+
+    @Override
+    public Integer findByManholeDTO(ManholeDTO dto) {
+        return manholeDao.findByManholeDTO(dto);
+    }
+
+    @Override
+    public void deleteManholeDataById(Integer id) {
+        this.deleteManholeLogDataById(id);
+        manholeDao.deleteManholeDataById(id);
+    }
+
+    @Override
+    public void deleteManholeLogDataById(Integer id) {
+        manholeDao.deleteManholeLogDataById(id);
+    }
 }

+ 6 - 0
src/main/java/com/welampiot/service/impl/TranshInfoServiceImpl.java

@@ -288,6 +288,12 @@ public class TranshInfoServiceImpl implements TranshInfoService {
 
     @Override
     public void deleteTrashDevById(Integer id) {
+        this.deleteTrashDevLogById(id);
         transhInfoDao.deleteTrashDevById(id);
     }
+
+    @Override
+    public void deleteTrashDevLogById(Integer id) {
+        transhInfoDao.deleteTrashDevLogById(id);
+    }
 }

+ 68 - 0
src/main/resources/mapper/ManholeMapper.xml

@@ -96,5 +96,73 @@
             limit #{page},#{count}
         </if>
     </select>
+    
+    <insert id="addManholeDataByDTO" parameterType="com.welampiot.dto.ManholeDTO" keyProperty="id" useGeneratedKeys="true">
+        insert into manhole(areaid, sectionid, address, name, longitude, latitude, model
+                            <if test="installDate != null and installDate != ''">
+                                ,install_date
+                            </if>
+                            <if test="expirationDate != null and expirationDate != ''">
+                                ,expiration_date
+                            </if>)
+        values
+            (#{areaId}, #{sectionId}, #{address}, #{name}, #{longitude}, #{latitude},
+            <if test="installDate != null and installDate != ''">
+                #{installDate},
+            </if>
+            <if test="expirationDate != null and expirationDate != ''">
+                #{expirationDate},
+            </if>
+            #{model})
+    </insert>
+
+    <update id="updateManholeDataByDTO" parameterType="com.welampiot.dto.ManholeDTO">
+        update manhole
+        set
+            areaid = #{areaId},
+            sectionid = #{sectionId},
+            address = #{address},
+            name = #{name},
+            longitude = #{longitude},
+            latitude = #{latitude},
+            model = #{model}
+            <if test="installDate != null and installDate != ''">
+                ,install_date = #{installDate}
+            </if>
+            <if test="expirationDate != null and expirationDate != ''">
+                ,expiration_date = #{expirationDate}
+            </if>
+        where id = #{id}
+    </update>
+
+    <select id="findByManholeDTO" resultType="Integer">
+        select count(*)
+        from manhole m
+        where 1=1
+        <if test="sectionId != null">
+            and m.sectionid = #{sectionId}
+        </if>
+        <if test="name != null">
+            and m.name = #{name}
+        </if>
+        <if test="address != null">
+            and m.address = #{address}
+        </if>
+        <if test="id != null">
+            and m.id != #{id}
+        </if>
+    </select>
+
+    <delete id="deleteManholeDataById">
+        delete
+        from manhole
+        where id = #{id}
+    </delete>
+
+    <delete id="deleteManholeLogDataById">
+        delete
+        from manhole_info_log
+        where manhole_id = #{id}
+    </delete>
 
 </mapper>

+ 4 - 0
src/main/resources/mapper/TranshInfoMapper.xml

@@ -141,4 +141,8 @@
         delete from transh_info where id = #{id}
     </delete>
 
+    <delete id="deleteTrashDevLogById">
+        delete from transh_info_log where transh_id = #{id}
+    </delete>
+
 </mapper>