|  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoIr.IrIrrigateUnit; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoIr.IrProject; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoProject; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoProjectOne; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoIr.IrUnitClient; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoUnit; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoUnitOne; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoActiveCard; | 
|---|
|  |  |  | import com.dy.pipIrrIrrigate.irrigateUnit.QueryVo; | 
|---|
|  |  |  | import com.dy.pipIrrIrrigate.irrigateUnit.dto.UnitClient; | 
|---|
|  |  |  | import com.dy.pipIrrIrrigate.result.IrrigateResultCode; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Content; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.Optional; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author :WuZeYu | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(irrigateUnitSv.addIrrigateUnit(po)).orElse(0); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_UNIT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("创建灌溉单元异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@RequestBody Map map) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); | 
|---|
|  |  |  | BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_UNIT_ID.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long unitId = Long.parseLong(map.get("id").toString()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer rows = irrigateUnitSv.deleteUnit(unitId); | 
|---|
|  |  |  | if (rows == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_UNIT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("删除灌溉单元异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer rows = irrigateUnitSv.deleteUnit(unitId); | 
|---|
|  |  |  | if (rows == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_UNIT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("删除灌溉单元异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(irrigateUnitSv.updateUnit(po)).orElse(0); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_PROJECT_FAIL.getMessage()); | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_UNIT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("修改灌溉单元异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 灌溉单元分配(农户租地) | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "add_unit_client", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> addUnitClient(@RequestBody @Valid UnitClient po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IrUnitClient irUnitClient = new IrUnitClient(); | 
|---|
|  |  |  | irUnitClient.setUnitId(po.getUnitId()); | 
|---|
|  |  |  | irUnitClient.setClientId(po.getClientId()); | 
|---|
|  |  |  | irUnitClient.setOperator(po.getOperator()); | 
|---|
|  |  |  | irUnitClient.setOperateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Long rec = Optional.ofNullable(irrigateUnitSv.addUnitClient(irUnitClient)).orElse(0L); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(IrrigateResultCode.UNIT_ASSOCIATE_CLIENT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(path = "delete_unit_client", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> deleteUnitClient(@RequestBody @Valid UnitClient po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IrUnitClient irUnitClient = new IrUnitClient(); | 
|---|
|  |  |  | irUnitClient.setUnitId(po.getUnitId()); | 
|---|
|  |  |  | irUnitClient.setClientId(po.getClientId()); | 
|---|
|  |  |  | irUnitClient.setOperator(po.getOperator()); | 
|---|
|  |  |  | irUnitClient.setOperateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Long rec = Optional.ofNullable(irrigateUnitSv.addUnitClient(irUnitClient)).orElse(0L); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(IrrigateResultCode.UNIT_ASSOCIATE_CLIENT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|